<commit_before>#!/usr/bin/env python3

from datetime import datetime
from pkg_resources import resource_filename

import argparse
import json

from flask import Flask, request, render_template, jsonify, Markup
from multiprocessing.managers import BaseManager, RemoteError

from monocle import config
from monocle import db
from monocle import utils
from monocle.names import POKEMON_NAMES


# Check whether config has all necessary attributes
if not hasattr(config, 'AREA_NAME'):
    raise RuntimeError('Please set AREA_NAME in config'.format(setting_name))
# Set defaults for missing config options
_optional = {
    'GOOGLE_MAPS_KEY': None,
    'RARE_IDS': (),
    'TRASH_IDS': (),
    'MAP_PROVIDER_URL': '//{s}.tile.osm.org/{z}/{x}/{y}.png',
    'MAP_PROVIDER_ATTRIBUTION': '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
    'MAP_WORKERS': True,
    'AUTHKEY': b'm3wtw0',
    'REPORT_MAPS': True,

    'LOAD_CUSTOM_HTML_FILE': False,
    'LOAD_CUSTOM_CSS_FILE': False,
    'LOAD_CUSTOM_JS_FILE': False,

    'FB_PAGE_ID': None,
    'TWITTER_SCREEN_NAME': None,
    'DISCORD_INVITE_ID': None,
    'TELEGRAM_USERNAME': None
}

for setting_name, default in _optional.items():
    if not hasattr(config, setting_name):
        setattr(config, setting_name, default)
del _optional

if not config.REPORT_MAPS:
    config.GOOGLE_MAPS_KEY = None


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-H',
        '--host',
        help='Set web server listening host',
        default='127.0.0.1'
    )
    parser.add_argument(
        '-P',
        '--port',
        type=int,
        help='Set web server listening port',
        default=5000
    )
    parser.add_argument(
        '-d', '--debug', help='Debug Mode', action='store_true'
    )
    parser.set_defaults(debug=False)
    return parser.parse_args()


app = Flask(__name__, template_folder=resource_filename('monocle', 'templates'), static_folder=resource_filename('monocle', 'static'))


@app.route('/')
def fullmap():
    map_center = utils.MAP_CENTER
    mapfile = 'newmap.html'
    extra_css_js = ''
    social_links = ''

    if config.LOAD_CUSTOM_HTML_FILE:
        mapfile = 'custom.html'

    if config.LOAD_CUSTOM_CSS_FILE:
        extra_css_js += '<link rel="stylesheet" href="static/css/custom.css">'

    if config.LOAD_CUSTOM_JS_FILE:
        extra_css_js += '<script type="text/javascript" src="static/js/custom.js"></script>'

    if config.FB_PAGE_ID:
        social_links += '<a class="map_btn facebook-icon" href="https://www.facebook.com/' + config.FB_PAGE_ID + '"></a>'

    if config.TWITTER_SCREEN_NAME:
        social_links += '<a class="map_btn twitter-icon" href="https://www.twitter.com/' + config.TWITTER_SCREEN_NAME + '"></a>'

    if config.DISCORD_INVITE_ID:
        social_links += '<a class="map_btn discord-icon" href="https://discord.gg/' + config.DISCORD_INVITE_ID + '"></a>'

    if config.TELEGRAM_USERNAME:
        social_links += '<a class="map_btn telegram-icon" href="https://www.telegram.me/' + config.TELEGRAM_USERNAME + '"></a>'


    return render_template(
        mapfile,
        area_name=config.AREA_NAME,
        map_center=map_center,
        map_provider_url=config.MAP_PROVIDER_URL,
        map_provider_attribution=config.MAP_PROVIDER_ATTRIBUTION,
        social_links=Markup(social_links),
        extra_css_js=Markup(extra_css_js),
    )

@app.route('/data')
def pokemon_data():
    return jsonify(get_pokemarkers())

@app.route('/spawnpoints')
def get_spawn_points():
    return jsonify(get_spawnpointsmarkers())

@app.route('/pokestops')
def get_pokestops():
    return jsonify(get_pokestopsmarkers())

@app.route('/scan_coords')
def get_scan_coords():
    return jsonify(get_scan_coords())
<commit_msg>Open social links in new tab/window<commit_after>#!/usr/bin/env python3

from datetime import datetime
from pkg_resources import resource_filename

import argparse
import json

from flask import Flask, request, render_template, jsonify, Markup
from multiprocessing.managers import BaseManager, RemoteError

from monocle import config
from monocle import db
from monocle import utils
from monocle.names import POKEMON_NAMES


# Check whether config has all necessary attributes
if not hasattr(config, 'AREA_NAME'):
    raise RuntimeError('Please set AREA_NAME in config'.format(setting_name))
# Set defaults for missing config options
_optional = {
    'GOOGLE_MAPS_KEY': None,
    'RARE_IDS': (),
    'TRASH_IDS': (),
    'MAP_PROVIDER_URL': '//{s}.tile.osm.org/{z}/{x}/{y}.png',
    'MAP_PROVIDER_ATTRIBUTION': '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
    'MAP_WORKERS': True,
    'AUTHKEY': b'm3wtw0',
    'REPORT_MAPS': True,

    'LOAD_CUSTOM_HTML_FILE': False,
    'LOAD_CUSTOM_CSS_FILE': False,
    'LOAD_CUSTOM_JS_FILE': False,

    'FB_PAGE_ID': None,
    'TWITTER_SCREEN_NAME': None,
    'DISCORD_INVITE_ID': None,
    'TELEGRAM_USERNAME': None
}

for setting_name, default in _optional.items():
    if not hasattr(config, setting_name):
        setattr(config, setting_name, default)
del _optional

if not config.REPORT_MAPS:
    config.GOOGLE_MAPS_KEY = None


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-H',
        '--host',
        help='Set web server listening host',
        default='127.0.0.1'
    )
    parser.add_argument(
        '-P',
        '--port',
        type=int,
        help='Set web server listening port',
        default=5000
    )
    parser.add_argument(
        '-d', '--debug', help='Debug Mode', action='store_true'
    )
    parser.set_defaults(debug=False)
    return parser.parse_args()


app = Flask(__name__, template_folder=resource_filename('monocle', 'templates'), static_folder=resource_filename('monocle', 'static'))


@app.route('/')
def fullmap():
    map_center = utils.MAP_CENTER
    mapfile = 'newmap.html'
    extra_css_js = ''
    social_links = ''

    if config.LOAD_CUSTOM_HTML_FILE:
        mapfile = 'custom.html'

    if config.LOAD_CUSTOM_CSS_FILE:
        extra_css_js += '<link rel="stylesheet" href="static/css/custom.css">'

    if config.LOAD_CUSTOM_JS_FILE:
        extra_css_js += '<script type="text/javascript" src="static/js/custom.js"></script>'

    if config.FB_PAGE_ID:
        social_links += '<a class="map_btn facebook-icon" target="_blank" href="https://www.facebook.com/' + config.FB_PAGE_ID + '"></a>'

    if config.TWITTER_SCREEN_NAME:
        social_links += '<a class="map_btn twitter-icon" target="_blank" href="https://www.twitter.com/' + config.TWITTER_SCREEN_NAME + '"></a>'

    if config.DISCORD_INVITE_ID:
        social_links += '<a class="map_btn discord-icon" target="_blank" href="https://discord.gg/' + config.DISCORD_INVITE_ID + '"></a>'

    if config.TELEGRAM_USERNAME:
        social_links += '<a class="map_btn telegram-icon" target="_blank" href="https://www.telegram.me/' + config.TELEGRAM_USERNAME + '"></a>'


    return render_template(
        mapfile,
        area_name=config.AREA_NAME,
        map_center=map_center,
        map_provider_url=config.MAP_PROVIDER_URL,
        map_provider_attribution=config.MAP_PROVIDER_ATTRIBUTION,
        social_links=Markup(social_links),
        extra_css_js=Markup(extra_css_js),
    )

@app.route('/data')
def pokemon_data():
    return jsonify(get_pokemarkers())

@app.route('/spawnpoints')
def get_spawn_points():
    return jsonify(get_spawnpointsmarkers())

@app.route('/pokestops')
def get_pokestops():
    return jsonify(get_pokestopsmarkers())

@app.route('/scan_coords')
def get_scan_coords():
    return jsonify(get_scan_coords())

{'fraction_non_alphanumeric': 0.13351605324980423, 'fraction_numerical': 0.0033933698773166276, 'mean_word_length': 3.8286074354127284, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 8, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4947090', 'n_tokens_mistral': 2682, 'n_tokens_neox': 2615, 'n_words': 499}