import log,variables import datetime,itertools,re,requests from bs4 import BeautifulSoup themonth = datetime.datetime.today().replace(day=1) - datetime.timedelta(days=1) artshop = None artstudio = None recycledart = None mastery = None donations = input("Paste comma-separated deck donation URLs here or press Enter to skip: ").split(", ") if donations[0] == "": donations = None print("Generating …") games = {} gamecount = 0 trades = {} for event in log.log: if event["date"].year == themonth.year: if event["date"].month >= themonth.month: if re.compile(r" [0-9][0-9][0-9]$").search(event["event"]): if len(games) < 37: game = event["url"] gamepage = requests.get(game) gamesoup = BeautifulSoup(gamepage.content, "html.parser") comment = gamesoup.find(class_="comment") thedate = comment.find(class_="datetime").text if datetime.datetime.strftime(themonth,"%Y-%m") in thedate: games.update({event["event"]:event["url"]}) gamecount += 1 elif event["date"].month == themonth.month: if "trade with " in event["event"]: try: if event["received"]: trades.update({event["event"][11:]:event["url"]}) except: pass elif event["event"] == "art shop": if not artshop: try: if event["received"]: pass except: artshop = event["url"] elif event["event"] == "art studio": if not artstudio: try: if event["lost"]: artstudio = event["url"] except: pass elif event["event"] == "recycled art": if not recycledart: try: if event["received"]: recycledart = event["date"] except: pass elif "mastered " in event["event"]: if not mastery: mastery = event["url"] games = dict(sorted(games.items())) trades = dict(sorted(trades.items())) if len(games) >= 35: games = dict(itertools.islice(games.items(),35)) elif len(games) >= 30: games = dict(itertools.islice(games.items(),30)) elif len(games) >= 25: games = dict(itertools.islice(games.items(),25)) elif len(games) >= 20: games = dict(itertools.islice(games.items(),20)) elif len(games) >= 15: games = dict(itertools.islice(games.items(),15)) elif len(games) >= 10: games = dict(itertools.islice(games.items(),10)) elif len(games) >= 5: games = dict(itertools.islice(games.items(),5)) if len(trades) >= 21: trades = dict(itertools.islice(trades.items(),21)) elif len(trades) >= 18: trades = dict(itertools.islice(trades.items(),18)) elif len(trades) >= 15: trades = dict(itertools.islice(trades.items(),15)) elif len(trades) >= 12: trades = dict(itertools.islice(trades.items(),12)) elif len(trades) >= 9: trades = dict(itertools.islice(trades.items(),9)) elif len(trades) >= 6: trades = dict(itertools.islice(trades.items(),6)) elif len(trades) >= 3: trades = dict(itertools.islice(trades.items(),3)) services = 0 if artshop: services += 1 if artstudio: services += 1 if recycledart: services += 1 if mastery: services += 1 if donations: services += 1 print("\nYour name: " + variables.name + "\nCard post: " + variables.url) if len(games) > 4: print("Category: Games") if len(games) == 35: print("Tier: VII") elif len(games) == 30: print("Tier: VI") elif len(games) == 25: print("Tier: V") elif len(games) == 20: print("Tier: IV") elif len(games) == 15: print("Tier: III") elif len(games) == 10: print("Tier: II") elif len(games) == 5: print("Tier: I") gamestring = "Activity: " precomma = False gameindex = 1 for game in games: if precomma: gamestring += " · " gamestring += str(gameindex) + ". " + game + "" precomma = True gameindex += 1 print(gamestring) if len(trades) > 2: print("Category: Trades") if len(trades) == 21: print("Tier: VII") elif len(trades) == 18: print("Tier: VI") elif len(trades) == 15: print("Tier: V") elif len(trades) == 12: print("Tier: IV") elif len(trades) == 9: print("Tier: III") elif len(trades) == 6: print("Tier: II") elif len(trades) == 3: print("Tier: I") tradestring = "Activity: " precomma = False tradeindex = 1 for trade in trades: if precomma: tradestring += " · " tradestring += str(tradeindex) + ". " + trade + "" precomma = True tradeindex += 1 print(tradestring) if services > 0: print("Category: Services") if services == 5: print("Tier: V") elif services == 4: print("Tier: IV") elif services == 3: print("Tier: III") elif services == 2: print("Tier: II") elif services == 1: print("Tier: I") servicestring = "Activity: " precomma = False serviceindex = 1 if artshop: servicestring += str(serviceindex) + ". art shop" precomma = True serviceindex += 1 if artstudio: if precomma: servicestring += " · " servicestring += str(serviceindex) + ". art studio" precomma = True serviceindex += 1 if recycledart: if precomma: servicestring += " · " servicestring += str(serviceindex) + ". recycled art – " + datetime.datetime.strftime(recycledart,"%-d %B").lower() precomma = True serviceindex += 1 if mastery: if precomma: servicestring += " · " servicestring += str(serviceindex) + ". masteries" precomma = True serviceindex += 1 if donations: if precomma: servicestring += " · " servicestring += str(serviceindex) + ". " if len(donations) == 1: servicestring += "deck donations" else: servicestring += "deck donations: 🌸 🌸" print(servicestring)