def run() -> None:
    files = rotation.files()
    n = len(files)
    time_until = min(
        TIME_UNTIL_FULL_ROTATION,
        TIME_UNTIL_SUPPLEMENTAL_ROTATION) - datetime.timedelta(weeks=1)
    if n >= TOTAL_RUNS:
        print(
            'It is the moment of discovery, the triumph of the mind, and the end of this rotation.'
        )
        return

    if n == 0 and TIME_UNTIL_FULL_ROTATION > datetime.timedelta(
            7) and TIME_UNTIL_SUPPLEMENTAL_ROTATION > datetime.timedelta(7):
        print(
            'The monks of the North Tree rarely saw their kodama until the rotation, when it woke like a slumbering, angry bear.'
        )
        print('ETA: {t}'.format(
            t=dtutil.display_time(time_until.total_seconds())))
        return

    all_prices = {}
    for url in configuration.get_list('cardhoarder_urls'):
        s = fetcher_internal.fetch(url)
        s = ftfy.fix_encoding(s)
        all_prices[url] = parse_cardhoarder_prices(s)
    url = configuration.get_str('mtgotraders_url')
    if url:
        s = fetcher_internal.fetch(url)
        all_prices['mtgotraders'] = parse_mtgotraders_prices(s)

    run_number = process(all_prices)
    if run_number == TOTAL_RUNS:
        make_final_list()
def make_final_list() -> None:
    planes = fetcher_internal.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 in plane_names:
            print(f'DISCARDED: [{line}] is a plane.')
            continue
        lines.append(line)
    scores = Counter(lines).most_common()

    passed: List[str] = []
    for name, count in scores:
        if count >= 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)))
Ejemplo n.º 3
0
def make_final_list() -> None:
    files = rotation.files()
    lines: List[str] = []
    for line in fileinput.input(files):
        line = text.sanitize(line)
        lines.append(line)
    scores = Counter(lines).most_common()

    passed: List[str] = []
    for name, count in scores:
        if count >= 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)))
Ejemplo 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)))
    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 process_sets(seen_sets: Set[str], used_sets: Set[str], hits: Set[str], ignored: Set[str]) -> int:
    files = rotation.files()
    n = len(files) + 1
    path = os.path.join(configuration.get_str('legality_dir'), 'Run_{n}.txt').format(n=n)
    h = open(path, mode='w', encoding='utf-8')
    for card in hits:
        line = card + '\n'
        h.write(line)
    h.close()
    print('Run {n} completed, with {ccards} cards from {csets}/{tsets} sets'.format(n=n, ccards=len(hits), csets=len(used_sets), tsets=len(seen_sets)))
    print('Used:    {sets}'.format(sets=repr(used_sets)))
    print('Missed:  {sets}'.format(sets=repr(ignored)))
    return n
Ejemplo n.º 6
0
def run() -> None:
    files = rotation.files()
    n = len(files)
    time_until = TIME_UNTIL_ROTATION - datetime.timedelta(weeks=1)
    if n >= rotation.TOTAL_RUNS:
        print(
            'It is the moment of discovery, the triumph of the mind, and the end of this rotation.'
        )
        return

    if n == 0 and TIME_UNTIL_ROTATION > datetime.timedelta(7):
        print(
            'The monks of the North Tree rarely saw their kodama until the rotation, when it woke like a slumbering, angry bear.'
        )
        print('ETA: {t}'.format(
            t=dtutil.display_time(int(time_until.total_seconds()))))
        return

    if n == 0:
        rotation.clear_redis(clear_files=True)
    #else:
    #    rotation.clear_redis()

    all_prices = {}
    for url in configuration.get_list('cardhoarder_urls'):
        s = fetch_tools.fetch(url)
        s = ftfy.fix_encoding(s)
        all_prices[url] = parse_cardhoarder_prices(s)
    url = configuration.get_str('mtgotraders_url')
    if url:
        s = fetch_tools.fetch(url)
        all_prices['mtgotraders'] = parse_mtgotraders_prices(s)

    run_number = process(all_prices)
    if run_number == rotation.TOTAL_RUNS:
        make_final_list()

    try:
        url = f'{fetcher.decksite_url()}/api/rotation/clear_cache'
        fetch_tools.fetch(url)
    except Exception as c:  # pylint: disable=broad-except
        print(c)
Ejemplo n.º 7
0
 def read_rotation_files(self) -> None:
     lines = []
     files = rotation.files()
     if len(files) == 0:
         if not os.path.isdir(configuration.get_str('legality_dir')):
             raise DoesNotExistException('Invalid configuration.  Could not find legality_dir.')
         self.runs = 0
         self.runs_percent = 0
         return
     self.latest_list = open(files[-1], 'r').read().splitlines()
     for filename in files:
         for line in self.get_file_contents(filename):
             line = text.sanitize(line)
             lines.append(line.strip())
     scores = Counter(lines).most_common()
     self.runs = scores[0][1]
     self.runs_percent = round(round(self.runs / 168, 2) * 100)
     self.cs = oracle.cards_by_name()
     for name, hits in scores:
         self.process_score(name, hits)
Ejemplo n.º 8
0
 def read_rotation_files(self) -> None:
     lines = []
     files = rotation.files()
     if len(files) == 0:
         files = glob.glob(
             os.path.join(configuration.get_str('legality_dir'), '*.jar'))
         if len(files) == 0:
             raise DoesNotExistException(
                 'Invalid configuration.  Could not find Legality Checker')
         self.runs = 0
         self.runs_percent = 0
         return
     for line in fileinput.input(files):
         line = text.sanitize(line)
         lines.append(line.strip())
     scores = Counter(lines).most_common()
     self.runs = scores[0][1]
     self.runs_percent = round(round(self.runs / 168, 2) * 100)
     self.cs = oracle.cards_by_name()
     for name, hits in scores:
         self.process_score(name, hits)