Esempio n. 1
0
def test_seasons_enum_uptodate() -> None:
    """If this is failing, go append new set codes to seasons.SEASONS.
       This needs to be done every few months.

       This test is purely for futureproofing, and failing it does not mean anything is currently broken"""
    if seasons.next_rotation_ex().code in ['???', None]:
        return
    assert seasons.next_rotation_ex().code in seasons.SEASONS
Esempio n. 2
0
def rotation_api() -> Response:
    now = dtutil.now()
    diff = seasons.next_rotation() - now
    result = {
        'last': seasons.last_rotation_ex(),
        'next': seasons.next_rotation_ex(),
        'diff': diff.total_seconds(),
        'friendly_diff': dtutil.display_time(int(diff.total_seconds())),
    }
    return return_json(result)
Esempio n. 3
0
 def all_seasons(self) -> List[SeasonInfoDescription]:
     seasonlist: List[SeasonInfoDescription] = [{
         'name': 'All Time',
         'code': 'all',
         'code_lower': 'all',
         'num': None,
         'url': seasonized_url('all'),
         'decks_url': url_for('seasons.decks', season_id='all'),
         'league_decks_url': url_for('seasons.decks', season_id='all', deck_type=DeckType.LEAGUE.value),
         'competitions_url': url_for('seasons.competitions', season_id='all'),
         'archetypes_url': url_for('seasons.archetypes', season_id='all'),
         'people_url': url_for('seasons.people', season_id='all'),
         'cards_url': url_for('seasons.cards', season_id='all'),
         'rotation_changes_url': url_for('seasons.rotation_changes', season_id='all'),
         'tournament_leaderboards_url': url_for('seasons.tournament_leaderboards', season_id='all'),
         'legality_name': None,
         'legal_cards_url': None,
     }]
     num = 1
     current_code = seasons.current_season_code()
     next_rotation_set_code = seasons.next_rotation_ex().code
     for code in seasons.SEASONS:
         if code == next_rotation_set_code:
             break
         seasonlist.append({
             'name': seasons.season_name(num),
             'code': code,
             'code_lower': code.lower(),
             'num': num,
             'url': seasonized_url(num),
             'decks_url': url_for('seasons.decks', season_id=num),
             'league_decks_url': url_for('seasons.decks', season_id=num, deck_type=DeckType.LEAGUE.value),
             'competitions_url': url_for('seasons.competitions', season_id=num),
             'archetypes_url': url_for('seasons.archetypes', season_id=num),
             'people_url': url_for('seasons.people', season_id=num),
             'cards_url': url_for('seasons.cards', season_id=num),
             'rotation_changes_url': url_for('seasons.rotation_changes', season_id=num),
             'tournament_leaderboards_url': url_for('seasons.tournament_leaderboards', season_id=num),
             'legality_name': 'Penny Dreadful' + ('' if code == current_code else f' {code}'),
             'legal_cards_url': 'https://pdmtgo.com/legal_cards.txt' if code == current_code else f'https://pdmtgo.com/{code}_legal_cards.txt',
         })
         num += 1
     seasonlist.reverse()
     return seasonlist
Esempio n. 4
0
def make_final_list() -> None:
    planes = fetch_tools.fetch_json(
        'https://api.scryfall.com/cards/search?q=t:plane%20or%20t:phenomenon'
    )['data']
    bad_names = [p['name'] for p in planes]
    bad_names.extend(BANNED_CARDS)
    files = rotation.files()
    lines: List[str] = []
    for line in fileinput.input(files):
        line = text.sanitize(line)
        if line.strip() in bad_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)
    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)),
          flush=True)
    setcode = seasons.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()

    do_push()
def pd500_date() -> datetime.datetime:
    if seasons.next_rotation_ex().codename == '???':
        return datetime.datetime(1970, 1, 1)

    end_of_season = seasons.next_rotation()
    return end_of_season - datetime.timedelta(days=12, hours=13, minutes=30)  # This effectively hardcodes a 10:30 PD Sat start time AND a Thu/Fri midnight rotation time.
Esempio n. 6
0
def do_push() -> None:
    print('Pushing to Github...', flush=True)
    gh_repo = os.path.join(configuration.get_str('legality_dir'), 'gh_pages')
    if not os.path.exists(gh_repo):
        subprocess.run([
            'git', 'clone',
            'https://github.com/PennyDreadfulMTG/pennydreadfulmtg.github.io.git',
            gh_repo
        ],
                       check=True)
    setcode = seasons.next_rotation_ex().mtgo_code
    files = ['legal_cards.txt', f'{setcode}_legal_cards.txt']
    for fn in files:
        source = os.path.join(configuration.get_str('legality_dir'), fn)
        dest = os.path.join(gh_repo, fn)
        shutil.copy(source, dest)

    os.chdir(gh_repo)
    subprocess.run(['git', 'add'] + files, check=True)
    subprocess.run(['git', 'commit', '-m', f'{setcode} rotation'], check=True)
    subprocess.run(['git', 'push'], check=True)
    print('done!\nGoing through checklist...', flush=True)
    checklist = f"""{setcode} rotation checklist

https://pennydreadfulmagic.com/admin/rotation/

- [ ] upload legal_cards.txt to S3
- [ ] upload {setcode}_legal_cards.txt to S3
- [ ] ping scryfall
- [ ] email mtggoldfish
- [ ] ping tappedout
"""
    print('Rebooting Discord bot...', flush=True)
    if redis.get_str('discordbot:commit_id'):
        redis.store('discordbot:do_reboot', True)
        print('Done!', flush=True)
    else:
        checklist += '- [ ] restart discordbot\n'
        print('Added to checklist!', flush=True)
    ds = os.path.expanduser('/penny/decksite/')
    failed = False
    try:
        if os.path.exists(ds):
            print('Calling Post Rotation...', flush=True)
            os.chdir(ds)
            subprocess.run(
                ['python3', 'run.py', 'maintenance', 'post_rotation'],
                check=True)
        else:
            failed = True
    except Exception:  # pylint: disable=broad-except
        failed = True
    if failed:
        checklist += '- [ ] run post_rotation\n'

    try:
        print('Updating Gatherling...', flush=True)
        fetch_tools.post(
            'https://gatherling.com/util/updateDefaultFormats.php')
    except fetch_tools.FetchException:
        checklist += '- [ ] Update Gatherling legal cards list\n'

    for path in [
            '/etc/uwsgi/vassals/decksite.ini',
            '/home/discord/vassals/decksite.ini'
    ]:
        srv = pathlib.Path(path)
        if srv.exists():
            print(f'touching {path}', flush=True)
            srv.touch()
            break
    else:
        checklist += '- [ ] touch /etc/uwsgi/vassals/decksite.ini\n'
    print('Sending checklist to Github...', flush=True)
    repo.create_issue(checklist, 'rotation script', 'rotation')
    print('Done!', flush=True)