Ejemplo n.º 1
0
def last_pd_rotation_changes():
    current_code = rotation.last_rotation_ex()['code']
    previous = multiverse.SEASONS[multiverse.SEASONS.index(current_code) - 1]
    previous_id = multiverse.get_format_id(
        "Penny Dreadful {f}".format(f=previous))
    current_id = multiverse.get_format_id("Penny Dreadful")
    return changes_between_formats(previous_id, current_id)
Ejemplo n.º 2
0
 def prepare_deck(self, d):
     set_stars_and_top8(d)
     if d.get('colors') is not None:
         d.colors_safe = colors_html(d.colors, d.colored_symbols)
     d.person_url = '/people/{id}/'.format(id=d.person_id)
     d.date_sort = dtutil.dt2ts(d.date)
     d.display_date = dtutil.display_date(d.date)
     d.show_record = d.wins or d.losses or d.draws
     if d.competition_id:
         d.competition_url = '/competitions/{id}/'.format(
             id=d.competition_id)
     d.url = '/decks/{id}/'.format(id=d.id)
     d.export_url = '/export/{id}/'.format(id=d.id)
     d.cmc_chart_url = '/charts/cmc/{id}-cmc.png'.format(id=d.id)
     if d.is_in_current_run():
         d.active_safe = '<span class="active" title="Active in the current league">⊕</span>'
         d.stars_safe = '{active} {stars}'.format(
             active=d.active_safe, stars=d.stars_safe).strip()
         d.source_sort = '1'
     d.source_is_external = False if d.source_name == 'League' else True
     d.comp_row_len = len("{comp_name} (Piloted by {person}".format(
         comp_name=d.competition_name, person=d.person))
     if d.get('archetype_id', None):
         d.archetype_url = '/archetypes/{id}/'.format(id=d.archetype_id)
     if d.get('omw') is not None:
         d.omw = str(int(d.omw)) + '%'
     else:
         d.omw = ''
     d.has_legal_format = len(d.legal_formats) > 0
     d.pd_legal = 'Penny Dreadful' in d.legal_formats
     d.legal_icons = ''
     sets = multiverse.SEASONS
     if 'Penny Dreadful' in d.legal_formats:
         icon = rotation.last_rotation_ex()['code'].lower()
         n = sets.index(icon.upper()) + 1
         d.legal_icons += '<a href="{url}"><i class="ss ss-{code} ss-rare ss-grad">S{n}</i></a>'.format(
             url='/seasons/{id}/'.format(id=n), code=icon, n=n)
     past_pd_formats = [
         fmt.replace('Penny Dreadful ', '') for fmt in d.legal_formats
         if 'Penny Dreadful ' in fmt
     ]
     past_pd_formats.sort(key=lambda code: -sets.index(code))
     for code in past_pd_formats:
         n = sets.index(code.upper()) + 1
         d.legal_icons += '<a href="{url}"><i class="ss ss-{set} ss-common ss-grad">S{n}</i></a>'.format(
             url='/seasons/{id}/'.format(id=n), set=code.lower(), n=n)
     if 'Commander' in d.legal_formats:  # I think C16 looks the nicest.
         d.legal_icons += '<i class="ss ss-c16 ss-uncommon ss-grad">CMDR</i>'
     if session.get('admin') or not d.is_in_current_run():
         d.decklist = str(d).replace('\n', '<br>')
     else:
         d.decklist = ''
     total, num_cards = 0, 0
     for c in d.maindeck:
         if 'Land' not in c['card'].type:
             num_cards += c['n']
             total += c['n'] * c['card'].cmc
     d.average_cmc = round(total / max(1, num_cards), 2)
Ejemplo n.º 3
0
def rotation_api():
    now = dtutil.now()
    diff = rotation.next_rotation() - now
    result = {
        "last": rotation.last_rotation_ex(),
        "next": rotation.next_rotation_ex(),
        "diff": diff.total_seconds(),
        "friendly_diff": dtutil.display_time(diff.total_seconds())
    }
    return return_json(result)
Ejemplo n.º 4
0
def rotation_api() -> Response:
    now = dtutil.now()
    diff = rotation.next_rotation() - now
    result = {
        'last': rotation.last_rotation_ex(),
        'next': rotation.next_rotation_ex(),
        'diff': diff.total_seconds(),
        'friendly_diff': dtutil.display_time(diff.total_seconds())
    }
    return return_json(result)
Ejemplo n.º 5
0
def is_good_set(setname: str) -> bool:
    if not BLACKLIST and not WHITELIST:
        if is_supplemental():
            WHITELIST.add(rotation.last_rotation_ex()['mtgo_code'])
        else:
            BLACKLIST.add(rotation.next_rotation_ex()['mtgo_code'])
    if setname in BLACKLIST:
        return False
    if setname in WHITELIST:
        return True
    return not WHITELIST
Ejemplo n.º 6
0
 def prepare_deck(self, d):
     set_stars_and_top8(d)
     if d.get('colors') is not None:
         d.colors_safe = colors_html(d.colors, d.colored_symbols)
         d.name = deck_name.normalize(d)
     d.person_url = url_for('person', person_id=d.person_id)
     d.date_sort = dtutil.dt2ts(d.date)
     d.display_date = dtutil.display_date(d.date)
     d.show_record = d.wins or d.losses or d.draws
     if d.competition_id:
         d.competition_url = url_for('competition',
                                     competition_id=d.competition_id)
     d.url = url_for('decks', deck_id=d.id)
     d.export_url = url_for('export', deck_id=d.id)
     d.cmc_chart_url = url_for('cmc_chart', deck_id=d.id)
     if d.source_name == 'League' and d.wins + d.losses < 5 and d.competition_end_date > dtutil.now(
     ) and not d.get('retired', False):
         d.stars_safe = '<span title="Active in the current league">⊕</span> {stars}'.format(
             stars=d.stars_safe).strip()
         d.source_sort = '1'
     d.comp_row_len = len("{comp_name} (Piloted by {person}".format(
         comp_name=d.competition_name, person=d.person))
     if d.get('archetype_id', None):
         d.archetype_url = url_for('archetype', archetype_id=d.archetype_id)
     if d.omw is not None:
         d.omw = str(int(d.omw)) + '%'
     else:
         d.omw = ''
     d.has_legal_format = len(d.legal_formats) > 0
     d.pd_legal = 'Penny Dreadful' in d.legal_formats
     d.legal_icons = ''
     sets = legality.SEASONS
     if 'Penny Dreadful' in d.legal_formats:
         icon = rotation.last_rotation_ex()['code'].lower()
         n = sets.index(icon.upper()) + 1
         d.legal_icons += '<a href="{url}"><i class="ss ss-{code} ss-rare ss-grad">S{n}</i></a>'.format(
             url=url_for('season', season_id=n), code=icon, n=n)
     past_pd_formats = [
         fmt.replace('Penny Dreadful ', '') for fmt in d.legal_formats
         if 'Penny Dreadful ' in fmt
     ]
     past_pd_formats.sort(key=lambda code: -sets.index(code))
     for code in past_pd_formats:
         n = sets.index(code.upper()) + 1
         d.legal_icons += '<a href="{url}"><i class="ss ss-{set} ss-common ss-grad">S{n}</i></a>'.format(
             url=url_for('season', season_id=n), set=code.lower(), n=n)
     if 'Commander' in d.legal_formats:  # I think C16 looks the nicest.
         d.legal_icons += '<i class="ss ss-c16 ss-uncommon ss-grad">CMDR</i>'
     d.decklist = str(d).replace('\n', '<br>')
Ejemplo n.º 7
0
def init():
    if FORMATS:
        return
    print('Updating Legalities...')
    assert len(oracle.legal_cards()) > 0
    all_known = oracle.load_card('island').legalities

    for s in SEASONS:
        if s == rotation.last_rotation_ex()['code']:
            break
        if not 'Penny Dreadful {s}'.format(s=s) in all_known:
            multiverse.set_legal_cards(season=s)

    FORMATS.clear()
    for v in db().values('SELECT name FROM format'):
        FORMATS.add(v)
Ejemplo n.º 8
0
def make_final_list() -> None:
    planes = fetch_tools.fetch_json(
        'https://api.scryfall.com/cards/search?q=t:plane%20or%20t:phenomenon'
    )['data']
    plane_names = [p['name'] for p in planes]
    files = rotation.files()
    lines: List[str] = []
    for line in fileinput.input(files):
        line = text.sanitize(line)
        if line.strip() in plane_names:
            continue
        lines.append(line)
    scores = Counter(lines).most_common()

    passed: List[str] = []
    for name, count in scores:
        if count >= rotation.TOTAL_RUNS / 2:
            passed.append(name)
    final = list(passed)
    if is_supplemental():
        temp = set(passed)
        final = list(temp.union([c + '\n' for c in fetcher.legal_cards()]))
    final.sort()
    h = open(os.path.join(configuration.get_str('legality_dir'),
                          'legal_cards.txt'),
             mode='w',
             encoding='utf-8')
    h.write(''.join(final))
    h.close()
    print('Generated legal_cards.txt.  {0}/{1} cards.'.format(
        len(passed), len(scores)))

    if is_supplemental():
        setcode = rotation.last_rotation_ex()['mtgo_code']
    else:
        setcode = rotation.next_rotation_ex()['mtgo_code']

    h = open(os.path.join(configuration.get_str('legality_dir'),
                          f'{setcode}_legal_cards.txt'),
             mode='w',
             encoding='utf-8')
    h.write(''.join(final))
    h.close()
Ejemplo n.º 9
0
 def __init__(self, decks):
     active_runs = [d for d in decks if d.is_in_current_run()]
     self.active_runs = ngettext('%(num)d active league run', '%(num)d active league runs', len(active_runs))
     self.decks = [d for d in decks if d not in active_runs]
     self.season_url = url_for('season', season_id=rotation.last_rotation_ex()['code'])
def update_pd_legality():
    for s in SEASONS:
        if s == rotation.last_rotation_ex()['code']:
            break
        set_legal_cards(season=s)