import json, sys, os, glob from rapidfuzz import process, fuzz from collections import namedtuple from dateutil import parser Episode = namedtuple('Episode', ['n', 'date', 'title']) WellFormed = namedtuple('WellFormed', ['n', 'date', 'title', 'season']) EpCounter = namedtuple('EpCounter', ['abs', 'rel']) def reset(counter, season): season += 1 # we are calling reset from the previous if season == 11: rel = 136 elif season == 12: rel = 236 else: rel = 1 return EpCounter(counter.abs, rel) def inc(counter): return EpCounter(counter.abs + 1, counter.rel + 1) mesi = ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"] months= ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"] month_table = dict(zip(mesi, months)) def parse_date(dstr): dstr = dstr.lower() for k, v in month_table.items(): if k in dstr: dstr = dstr.replace(k, v) return parser.parse(dstr) counter = EpCounter(1, 1) melevisione = dict() scarti = {'Il Genio della pietra'} for i in range(1, 18): with open(f'{i}.txt', 'r') as fp: c = json.loads(fp.read()) eps = [Episode(i[0], i[1], i[2]) for i in c] eps = [e for e in eps if e[2] not in scarti] melevisione[i] = eps expected = { 1: 103, 2: 162, 3: 151, 4: 127, 5: 144, 6: 165, 7: 144, 8: 156, 9: 130, 10: 135, 11: 100, 12: 128, 13: 45, 14: 100, 15: 100, 16: 75, 17: 70 } def make(n, maybedate, maybetitle, stagione): def clean(str): str = str.replace('º', '').replace('\n', ' ') if '= best_score: best_title, best_score = r[0], score found = all_episodes[best_title] print('---------------------') print(f'\t{t} -> {found}') print('---------------------')