Add activity rewards script
This commit is contained in:
parent
0218ec4e6f
commit
da586e7ca2
2 changed files with 213 additions and 1 deletions
|
@ -3,7 +3,7 @@ Python scripts to generate a mobile-friendly static site for tracking tcg cards
|
|||
|
||||
** Instructions
|
||||
*** Requirements
|
||||
- =python3= (needs the following libraries: =bs4, collections, datetime, os, random, re, requests=)
|
||||
- =python3= (needs the following libraries: =bs4, collections, datetime, itertools, os, random, re, requests=)
|
||||
- server space
|
||||
- subdomain pointing to your site root on the server
|
||||
- =rclone= with your server set up as a remote
|
||||
|
|
212
rewards.py
Normal file
212
rewards.py
Normal file
|
@ -0,0 +1,212 @@
|
|||
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("\n<b>Your name</b>: " + variables.name + "\n<b>Card post</b>: " + variables.url)
|
||||
|
||||
if len(games) > 4:
|
||||
print("<b>Category</b>: Games")
|
||||
if len(games) == 35:
|
||||
print("<b>Tier</b>: VII")
|
||||
elif len(games) == 30:
|
||||
print("<b>Tier</b>: VI")
|
||||
elif len(games) == 25:
|
||||
print("<b>Tier</b>: V")
|
||||
elif len(games) == 20:
|
||||
print("<b>Tier</b>: IV")
|
||||
elif len(games) == 15:
|
||||
print("<b>Tier</b>: III")
|
||||
elif len(games) == 10:
|
||||
print("<b>Tier</b>: II")
|
||||
elif len(games) == 5:
|
||||
print("<b>Tier</b>: I")
|
||||
gamestring = "<b>Activity</b>: "
|
||||
precomma = False
|
||||
gameindex = 1
|
||||
for game in games:
|
||||
if precomma:
|
||||
gamestring += " · "
|
||||
gamestring += str(gameindex) + ". <a href=\"" + games[game] + "\">" + game + "</a>"
|
||||
precomma = True
|
||||
gameindex += 1
|
||||
print(gamestring)
|
||||
|
||||
if len(trades) > 2:
|
||||
print("<b>Category</b>: Trades")
|
||||
if len(trades) == 21:
|
||||
print("<b>Tier</b>: VII")
|
||||
elif len(trades) == 18:
|
||||
print("<b>Tier</b>: VI")
|
||||
elif len(trades) == 15:
|
||||
print("<b>Tier</b>: V")
|
||||
elif len(trades) == 12:
|
||||
print("<b>Tier</b>: IV")
|
||||
elif len(trades) == 9:
|
||||
print("<b>Tier</b>: III")
|
||||
elif len(trades) == 6:
|
||||
print("<b>Tier</b>: II")
|
||||
elif len(trades) == 3:
|
||||
print("<b>Tier</b>: I")
|
||||
tradestring = "<b>Activity</b>: "
|
||||
precomma = False
|
||||
tradeindex = 1
|
||||
for trade in trades:
|
||||
if precomma:
|
||||
tradestring += " · "
|
||||
tradestring += str(tradeindex) + ". <a href=\"" + trades[trade] + "\">" + trade + "</a>"
|
||||
precomma = True
|
||||
tradeindex += 1
|
||||
print(tradestring)
|
||||
|
||||
if services > 0:
|
||||
print("<b>Category</b>: Services")
|
||||
if services == 5:
|
||||
print("<b>Tier</b>: V")
|
||||
elif services == 4:
|
||||
print("<b>Tier</b>: IV")
|
||||
elif services == 3:
|
||||
print("<b>Tier</b>: III")
|
||||
elif services == 2:
|
||||
print("<b>Tier</b>: II")
|
||||
elif services == 1:
|
||||
print("<b>Tier</b>: I")
|
||||
servicestring = "<b>Activity</b>: "
|
||||
precomma = False
|
||||
serviceindex = 1
|
||||
if artshop:
|
||||
servicestring += str(serviceindex) + ". <a href=\"" + artshop + "\">art shop</a>"
|
||||
precomma = True
|
||||
serviceindex += 1
|
||||
if artstudio:
|
||||
if precomma:
|
||||
servicestring += " · "
|
||||
servicestring += str(serviceindex) + ". <a href=\"" + artstudio + "\">art studio</a>"
|
||||
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) + ". <a href=\"" + mastery + "\">masteries</a>"
|
||||
precomma = True
|
||||
serviceindex += 1
|
||||
if donations:
|
||||
if precomma:
|
||||
servicestring += " · "
|
||||
servicestring += str(serviceindex) + ". "
|
||||
if len(donations) == 1:
|
||||
servicestring += "<a href=\"" + donations[0] + "\">deck donations</a>"
|
||||
else:
|
||||
servicestring += "deck donations: <a href=\"" + "\">🌸</a> <a href=\"".join(donations) + "\">🌸</a>"
|
||||
print(servicestring)
|
Loading…
Add table
Add a link
Reference in a new issue