def test_seasons_enum_uptodate() -> None: """If this is failing, go append new set codes to rotation.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 rotation.next_rotation_ex().code in ['???', None]: return assert rotation.next_rotation_ex().code in rotation.SEASONS
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))) 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() do_push()
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)
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)
def do_push() -> None: 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 = rotation.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) 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 """ if redis.get_str('discordbot:commit_id'): redis.store('discordbot:do_reboot', True) else: checklist += '- [ ] restart discordbot' ds = os.path.expanduser('~/decksite/') failed = False try: if os.path.exists(ds): 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: fetch_tools.post('https://gatherling.com/util/updateDefaultFormats.php') except fetch_tools.FetchException: checklist += '- [ ] Update Gatherling legal cards list' for path in ['/etc/uwsgi/vassals/decksite.ini', '/home/discord/vassals/decksite.ini']: srv = pathlib.Path(path) if srv.exists(): srv.touch() break else: checklist += '- [ ] touch /etc/uwsgi/vassals/decksite.ini\n' repo.create_issue(checklist, 'rotation script', 'rotation')
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
def __init__(self): self.seasons = [] num = 1 next_rotation_set_code = rotation.next_rotation_ex()['code'] for code in multiverse.SEASONS: if code == next_rotation_set_code: break self.seasons.append({ 'code': code, 'num': num, 'decks_url': url_for('season', season_id=code), 'league_decks_url': url_for('season', season_id=code, deck_type='league'), }) num += 1
def all_seasons(self) -> List[SeasonInfoDescription]: seasons: List[SeasonInfoDescription] = [{ 'name': 'All Time', 'code': 'all', 'code_lower': 'all', 'num': None, 'url': seasonized_url('all'), 'decks_url': url_for('seasons.season', season_id='all'), 'league_decks_url': url_for('seasons.season', season_id='all', deck_type='league'), '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') }] num = 1 next_rotation_set_code = rotation.next_rotation_ex()['code'] for code in rotation.SEASONS: if code == next_rotation_set_code: break seasons.append({ 'name': rotation.season_name(num), 'code': code, 'code_lower': code.lower(), 'num': num, 'url': seasonized_url(num), 'decks_url': url_for('seasons.season', season_id=num), 'league_decks_url': url_for('seasons.season', season_id=num, deck_type='league'), '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) }) num += 1 seasons.reverse() return seasons
def all_seasons(self) -> List[SeasonInfoDescription]: seasons: 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'), 'legal_cards_url': None }] num = 1 next_rotation_set_code = rotation.next_rotation_ex().code for code in rotation.SEASONS: if code == next_rotation_set_code: break seasons.append({ 'name': rotation.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), 'legal_cards_url': f'https://pdmtgo.com/{code}_legal_cards.txt' }) num += 1 seasons.reverse() return seasons
def test_seasons_enum_uptodate(): """If this is failing, go append new set codes to multiverse.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""" assert rotation.next_rotation_ex()['code'] in multiverse.SEASONS