예제 #1
0
 def draftable_sets(self):
     result = {}
     for set_path in (LORE_SEEKER_REPO / 'data' / 'sets').iterdir():
         set_info = gefolge_web.util.cached_json(lazyjson.File(set_path))
         set_code = set_info['code'].value()
         if set_info.get('custom', False):
             set_config = config()['customSets'].get(set_code, {})
             if set_config.get('boosters',
                               True) and set_config.get('drafted') is None:
                 result[set_code] = set_info, set_config
     return sorted(result.items(),
                   key=lambda kv: (kv[1][0]['releaseDate'].value(), kv[0]))
예제 #2
0
 def prepare_reboot_notice():
     reboot_info = cached_json(
         lazyjson.File('/opt/dev/reboot.json')).value()
     if 'schedule' in reboot_info:
         flask.g.reboot_timestamp = parse_iso_datetime(
             reboot_info['schedule'], tz=pytz.utc)
         flask.g.reboot_upgrade = reboot_info.get('upgrade', False)
         flask.g.reboot_end_time = None if flask.g.reboot_upgrade else flask.g.reboot_timestamp + datetime.timedelta(
             minutes=15)
     else:
         flask.g.reboot_timestamp = None
         flask.g.reboot_upgrade = None
         flask.g.reboot_end_time = None
예제 #3
0
 def subtitle(self):
     if self.data.get('ibSubtitle'):
         return self.data['ibSubtitle'].value()
     set_code = self.card_set
     if set_code is not None:
         set_info_path = LORE_SEEKER_REPO / 'data' / 'sets' / f'{set_code}.json'
         if set_info_path.exists():
             set_info = gefolge_web.util.cached_json(
                 lazyjson.File(set_info_path))
         else:
             set_info = lazyjson.PythonFile({})
         set_config = config()['customSets'].get(set_code, {})
         return set_info.get('name', set_config.get('name', set_code))
예제 #4
0
 def description(self):
     set_code = self.card_set
     if set_code is None:
         result = 'Wir [draften](https://mtg.fandom.com/wiki/Booster_Draft) ein Custom Magic Set. Um zu bestimmen, welches, kannst du unten abstimmen.'
     else:
         set_info_path = LORE_SEEKER_REPO / 'data' / 'sets' / f'{set_code}.json'
         if set_info_path.exists():
             set_info = gefolge_web.util.cached_json(
                 lazyjson.File(set_info_path))
         else:
             set_info = lazyjson.PythonFile({})
         set_config = config()['customSets'].get(set_code, {})
         set_name = set_info.get('name', set_config.get('name', set_code))
         result = 'Wir [draften](https://mtg.fandom.com/wiki/Booster_Draft) [*{}*](https://loreseeker.fenhl.net/set/{}), ein Custom Magic Set.'.format(
             set_name, set_code.lower())
         result += '\r\n\r\n*{}* {}'.format(
             set_name,
             set_config.get('blurb', 'hat noch keine Beschreibung :('))
     return result + '\r\n\r\nWir spielen mit [Proxies](https://mtg.fandom.com/wiki/Proxy_card), der Draft ist also kostenlos. Ihr müsst nichts mitbringen. Es gibt 8 Plätze. Es können gerne alle, die Interesse haben, Plätze reservieren, das ist *keine* verbindliche Anmeldung. Ich selbst spiele nur mit, wenn es ohne mich weniger als 8 Spieler wären. Falls wir am Ende weniger als 5 Menschen sind, spielen wir [Sealed](https://mtg.fandom.com/wiki/Sealed_Deck) statt Draft.'
def download_folder(name, only_hea=False):
    dir_path = output + '/' + name

    create_folder(dir_path)
    db_sub = dir_path + '/' + name + '.json'
    if not file_exists(db_sub):
        create_file(db_sub, contents='{}')
    db_sub = lazyjson.File(db_sub)

    #if 'done' in db_sub:
    #    return 0, 0

    dir_url = physioneturl + '/' + name

    files_to_dl = []
    for f in list_page(dir_url)[5:]:
        if f.endswith('hea') or f.endswith('dat'):
            file_url = dir_url + '/' + f
            file_path = dir_path + '/' + f

            # Check local existance
            if file_exists(file_path):
                if f in db_sub:
                    continue

            delete_file(file_path)
            files_to_dl.append((f, file_url, file_path))

    try:
        res = pool.starmap(process_url, files_to_dl)
    except:
        for _, _, fp in files_to_dl:
            delete_file(fp)
        raise
    total_size = 0
    total_dl = 0
    for f, h, s in res:
        total_size += s
        db_sub[f] = {'hash': h, 'size': s}
        total_dl += 1
    db_sub['done'] = True
    return total_size, total_dl
예제 #6
0
 def data(self):
     return gefolge_web.util.cached_json(
         lazyjson.File(LOCATIONS_ROOT / '{}.json'.format(self.loc_id)))
from bs4 import BeautifulSoup
import requests
import datetime
import multiprocessing

sys.setrecursionlimit(100000)

physioneturl = "https://physionet.org/physiobank/database/mimic3wdb/matched"
db_file = 'mimic3wdb-170315.json'
output = 'data/mimic3wdb-200315'

create_folder(output)

if not file_exists(db_file):
    create_file(db_file, contents='{}')
db = lazyjson.File(db_file)


def list_page(url, string_red=9999999, pre_idx=0):
    print(url)
    page = requests.get(url)
    soup = BeautifulSoup(page.text, 'html.parser')
    tmp = list(
        map(lambda e: e.string[:string_red],
            soup.find_all('pre')[pre_idx].find_all('a')))

    return tmp


folders = list_page(physioneturl, -1, 3)[9:]
print('Got {} folders'.format(len(folders)))
예제 #8
0
def profile_data_for_snowflake(snowflake):
    return gefolge_web.util.cached_json(
        lazyjson.File(PROFILES_ROOT / f'{snowflake}.json')).value()
예제 #9
0
    def profile(person):
        import gefolge_web.event.model

        if not person.is_active:
            return gefolge_web.util.render_template('profile-404',
                                                    mensch=person), 404
        if person.is_mensch and (flask.g.user.is_admin
                                 or flask.g.user.is_treasurer
                                 or flask.g.user == person):
            transfer_money_form = TransferMoneyForm(person)
            if transfer_money_form.submit_transfer_money_form.data and transfer_money_form.validate(
            ):
                recipient = transfer_money_form.recipient.data
                person.add_transaction(
                    gefolge_web.util.Transaction.transfer(
                        recipient, -transfer_money_form.amount.data,
                        transfer_money_form.comment.data))
                recipient.add_transaction(
                    gefolge_web.util.Transaction.transfer(
                        person, transfer_money_form.amount.data,
                        transfer_money_form.comment.data))
                if flask.g.user != person:
                    peter.msg(
                        person,
                        '<@{}> ({}) hat {} von deinem Guthaben an <@{}> ({}) übertragen. {}: <https://gefolge.org/me>'
                        .format(
                            flask.g.user.snowflake, flask.g.user,
                            transfer_money_form.amount.data,
                            recipient.snowflake, recipient,
                            'Kommentar und weitere Infos'
                            if transfer_money_form.comment.data else
                            'Weitere Infos'))
                if flask.g.user != recipient:
                    peter.msg(
                        recipient,
                        '<@{}> ({}) hat {} an dich übertragen. {}: <https://gefolge.org/me>'
                        .format(
                            person.snowflake, person,
                            transfer_money_form.amount.data,
                            'Kommentar und weitere Infos'
                            if transfer_money_form.comment.data else
                            'Weitere Infos'))
                return flask.redirect(flask.g.view_node.url)
            wurstmineberg_transfer_money_form = WurstminebergTransferMoneyForm(
                person)
            if wurstmineberg_transfer_money_form.submit_wurstmineberg_transfer_money_form.data and wurstmineberg_transfer_money_form.validate(
            ):
                transaction = gefolge_web.util.Transaction.wurstmineberg(
                    wurstmineberg_transfer_money_form.amount.data)
                person.add_transaction(transaction)
                gefolge_web.util.cached_json(
                    lazyjson.File('/opt/wurstmineberg/money.json')
                )['transactions'].append({
                    'amount':
                    wurstmineberg_transfer_money_form.amount.data.value,
                    'currency':
                    'EUR',
                    'time':
                    '{:%Y-%m-%dT%H:%M:%SZ}'.format(
                        transaction.time.astimezone(pytz.utc)),
                    'type':
                    'gefolge'
                })
        else:
            transfer_money_form = None
            wurstmineberg_transfer_money_form = None
        return {
            'events': [
                event for event in gefolge_web.event.model.Event
                if person in event.signups
            ],
            'person':
            person,
            'transfer_money_form':
            transfer_money_form,
            'wurstmineberg_transfer_money_form':
            wurstmineberg_transfer_money_form
        }
예제 #10
0
 def treasurer(cls):
     snowflake = gefolge_web.util.cached_json(
         lazyjson.File(
             gefolge_web.util.CONFIG_PATH))['web'].get('treasurer')
     if snowflake is not None:
         return cls(snowflake)
예제 #11
0
 def update_whitelist(self, people_file=None):
     # get wanted whitelist from people file
     if people_file is None:
         people = people.get_people_db().obj_dump(version=3)
     else:
         with open(str(people_file)) as people_fobj:
             people = json.load(people_fobj)['people']
     whitelist = []
     additional = self.config['whitelist']['additional']
     if not self.config['whitelist']['ignorePeople']:
         for person in people:
             if not ('minecraft' in person or 'minecraftUUID' in person):
                 continue
             if person.get('status', 'later') not in [
                     'founding', 'later', 'postfreeze'
             ]:
                 continue
             if person.get('minecraftUUID'):
                 uuid = person['minecraftUUID'] if isinstance(
                     person['minecraftUUID'], str) else format(
                         person['minecraftUUID'], 'x')
                 if 'minecraft' in person:
                     name = person['minecraft']
                 else:
                     name = requests.get(
                         'https://api.mojang.com/user/profiles/{}/names'.
                         format(uuid)).json()[-1]['name']
             else:
                 response_json = requests.get(
                     'https://api.mojang.com/users/profiles/minecraft/{}'.
                     format(person['minecraft'])).json()
                 uuid = response_json['id']
                 name = response_json['name']
             if '-' not in uuid:
                 uuid = uuid[:8] + '-' + uuid[8:12] + '-' + uuid[
                     12:16] + '-' + uuid[16:20] + '-' + uuid[20:]
             whitelist.append({'name': name, 'uuid': uuid})
     # write whitelist
     whitelist_path = self.path / 'whitelist.json'
     with whitelist_path.open('a'):
         os.utime(str(whitelist_path), None)  # touch the file
     with whitelist_path.open('w') as whitelist_json:
         json.dump(whitelist,
                   whitelist_json,
                   sort_keys=True,
                   indent=4,
                   separators=(',', ': '))
     # apply changes to whitelist files
     self.command('whitelist', ['reload'])
     # add people with unknown UUIDs to new whitelist using the command
     for name in additional:
         self.command('whitelist', ['add', name])
     # update people file
     try:
         import lazyjson
     except ImportError:
         return
     try:
         with whitelist_path.open() as whitelist_json:
             whitelist = json.load(whitelist_json)
     except ValueError:
         return
     people = lazyjson.File(CONFIG['paths']['people'])
     for whitelist_entry in whitelist:
         for person in people['people']:
             if person.get('minecraftUUID') == whitelist_entry['uuid']:
                 if 'minecraft' in person and person.get(
                         'minecraft'
                 ) != whitelist_entry['name'] and person.get(
                         'minecraft') not in person.get(
                             'minecraft_previous', []):
                     if 'minecraft_previous' in person:
                         person['minecraft_previous'].append(
                             person['minecraft'])
                     else:
                         person['minecraft_previous'] = [
                             person['minecraft']
                         ]
                 person['minecraft'] = whitelist_entry['name']
             elif person.get('minecraft') == whitelist_entry[
                     'name'] and 'minecraftUUID' not in person:
                 person['minecraftUUID'] = whitelist_entry['uuid']
예제 #12
0
 def userdata(self):
     return gefolge_web.util.cached_json(
         lazyjson.File(USERDATA_ROOT / '{}.json'.format(self.snowflake),
                       init={}))
예제 #13
0
def config():
    return gefolge_web.util.cached_json(
        lazyjson.File(gefolge_web.util.BASE_PATH / 'games' / 'magic.json'))
예제 #14
0
DOCUMENT_ROOT = os.environ.get('FLASK_ROOT_PATH', '/opt/git/github.com/dasgefolge/gefolge.org/master')
WIKI_CHANNEL_ID = 739623881719021728

app = application = flask.Flask('gefolge_web', root_path=DOCUMENT_ROOT, instance_path=DOCUMENT_ROOT)

with app.app_context():
    app.url_map.strict_slashes = False
    app.jinja_env.autoescape = jinja2.select_autoescape(
        default_for_string=True,
        enabled_extensions=('html', 'xml', 'j2')
    )
    # load config
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///gefolge'
    if gefolge_web.util.CONFIG_PATH.exists():
        app.config.update(gefolge_web.util.cached_json(lazyjson.File(gefolge_web.util.CONFIG_PATH)).value())
    # set up database
    db = flask_sqlalchemy.SQLAlchemy(app)
    # set up API clients
    if 'challonge' in app.config:
        challonge.set_credentials(app.config['challonge']['username'], app.config['challonge']['apiKey'])
    if 'smashggToken' in app.config:
        gefolge_web.util.CACHE['smashggClient'] = gql.Client(transport=gql.transport.aiohttp.AIOHTTPTransport(url='https://api.smash.gg/gql/alpha', headers={'Authorization': f'Bearer {app.config["smashggToken"]}'}), fetch_schema_from_transport=True)
    # set up Bootstrap
    flask_bootstrap.Bootstrap(app)
    # set up Markdown
    md = flaskext.markdown.Markdown(app, extensions=['toc'], extension_configs={
        'toc': {
            'marker': ''
        }
    })
예제 #15
0
 def admin(cls):
     return cls(
         gefolge_web.util.cached_json(
             lazyjson.File(
                 gefolge_web.util.CONFIG_PATH))['web']['admin'].value())
예제 #16
0
def update_whitelist(people_file=None):
    import lazyjson
    # get wanted whitelist from people file
    if people_file is None:
        people_file = config('paths')['people']
    whitelist = []
    by_name = []
    additional = config('whitelist').get('additional', [])
    if not config('whitelist').get('ignore_people', False):
        with open(people_file) as people_fobj:
            people = json.load(people_fobj)
            if isinstance(people, dict):
                people = people['people']
            for person in people:
                if not person.get('minecraft'):
                    continue
                if person.get('status', 'later') not in [
                        'founding', 'later', 'postfreeze'
                ]:
                    continue
                if person.get('minecraftUUID'):
                    uuid = person['minecraftUUID'] if isinstance(
                        person['minecraftUUID'], str) else format(
                            person['minecraftUUID'], 'x')
                    if '-' not in uuid:
                        uuid = uuid[:8] + '-' + uuid[8:12] + '-' + uuid[
                            12:16] + '-' + uuid[16:20] + '-' + uuid[20:]
                    whitelist.append({
                        'name': person['minecraft'],
                        'uuid': uuid
                    })
                else:
                    by_name.append(person['minecraft'])
    # write old whitelist
    old_whitelist_path = os.path.join(
        config('paths')['server'], 'white-list.txt')
    with open(old_whitelist_path, 'a'):
        os.utime(old_whitelist_path, None)  # touch the file
    with open(old_whitelist_path, 'w') as whitelistfile:
        print('# DO NOT EDIT THIS FILE', file=whitelistfile)
        print('# it is automatically generated from ' + people_file,
              file=whitelistfile)
        print('# all changes will be lost on the next auto-update',
              file=whitelistfile)
        print(file=whitelistfile)
        if len(whitelist) > 0:
            print('# whitelisted by UUID:', file=whitelistfile)
            for person in whitelist:
                print(person['name'], file=whitelistfile)
        if len(by_name) > 0:
            print('# whitelisted by Minecraft nickname:', file=whitelistfile)
            for name in by_name:
                print(name, file=whitelistfile)
        if len(additional) > 0:
            print('# additional nicks generated from ' + CONFIG_FILE + ':',
                  file=whitelistfile)
            for minecraft_nick in additional:
                print(minecraft_nick, file=whitelistfile)
    # write new whitelist
    new_whitelist_path = os.path.join(
        config('paths')['server'], 'whitelist.json')
    with open(new_whitelist_path, 'a'):
        os.utime(new_whitelist_path, None)  # touch the file
    with open(new_whitelist_path, 'w') as whitelist_json:
        json.dump(whitelist,
                  whitelist_json,
                  sort_keys=True,
                  indent=4,
                  separators=(',', ': '))
    # apply changes to whitelist files
    command('whitelist', ['reload'])
    # add people with unknown UUIDs to new whitelist using the command
    for name in by_name + additional:
        command('whitelist', ['add', name])
    # update people file
    try:
        with open(os.path.join(config('paths')['server'],
                               'whitelist.json')) as whitelist_json:
            whitelist = json.load(whitelist_json)
    except ValueError:
        return
    people = lazyjson.File(config('paths')['people'])
    for whitelist_entry in whitelist:
        for person in people['people']:
            if person.get('minecraftUUID') == whitelist_entry['uuid']:
                if 'minecraft' in person and person.get(
                        'minecraft') != whitelist_entry['name'] and person.get(
                            'minecraft') not in person.get(
                                'minecraft_previous', []):
                    if 'minecraft_previous' in person:
                        person['minecraft_previous'].append(
                            person['minecraft'])
                    else:
                        person['minecraft_previous'] = [person['minecraft']]
                person['minecraft'] = whitelist_entry['name']
            elif person.get('minecraft') == whitelist_entry[
                    'name'] and 'minecraftUUID' not in person:
                person['minecraftUUID'] = whitelist_entry['uuid']
예제 #17
0
 def data(self):
     return gefolge_web.util.cached_json(
         lazyjson.File(EVENTS_ROOT / '{}.json'.format(self.event_id)))