aboutsummaryrefslogtreecommitdiffstats
path: root/subreddit.py
diff options
context:
space:
mode:
authorjwnskanzkwk <eddie.atten@yahoo.co.uk>2020-05-29 17:49:46 +0100
committerjwnskanzkwk <eddie.atten@yahoo.co.uk>2020-05-29 17:49:46 +0100
commit7677d95c729ab88080d742461fcb3b07c8b421f7 (patch)
tree6022a7011c0e85b28124cdbf555b9bdce341217b /subreddit.py
parenta09665a696da60481900aeef435cca48afa698fb (diff)
downloadSmallYTChannelBot-7677d95c729ab88080d742461fcb3b07c8b421f7.tar.gz
SmallYTChannelBot-7677d95c729ab88080d742461fcb3b07c8b421f7.zip
added leaderboard to sidebar
Diffstat (limited to 'subreddit.py')
-rwxr-xr-xsubreddit.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/subreddit.py b/subreddit.py
index 8a1755d..205995b 100755
--- a/subreddit.py
+++ b/subreddit.py
@@ -133,9 +133,24 @@ def upload_image(path, date):
return "https://i.imgur.com/%s.png" % image["id"]
def every_day():
- display("Updated statistics")
+ display("Starting every day program...")
+ display("Updating database statistics...")
db.update_stats()
+ display("Posting and updating wiki...")
update_tables(db.get_scores(), db.get_stats())
+ display("Formatting leaderboard...")
+ leaderboard = format_monthly_leaderboard()
+ display("Updating sidebar...")
+ #it'd be cool to find a way to access this directly without iteration
+ for widget in SUBREDDIT.widgets.sidebar:
+ if widget.shortName == "Monthly Lambda Leaderboard":
+ widget.mod.update(text = leaderboard)
+ display("Updated in new reddit...")
+ sidebar = SUBREDDIT.mod.settings()["description"]
+ oldtable = sidebar.split("------")[-1]
+ SUBREDDIT.mod.update(description = sidebar.replace(oldtable, "\n\n## Monthly Lambda Leaderboard\n\n" + leaderboard))
+ display("Updated in old reddit...")
+ display("Completed.")
def handle_mylambda(comment):
author = str(comment.author)
@@ -365,17 +380,12 @@ def add_times_to_lambdas():
logging.info("Added date for permalink %s" % permalink)
-def get_monthly_leaderboard():
- add_times_to_lambdas()
- all_lambdas = db.get_all_lambdas()
- thresh = time.time() - 30 * 24 * 60 * 60
- ordered_leaderboard = []
- for id_, permalink, user, created in all_lambdas:
- if created is not None:
- if created > thresh:
- print(user, permalink)
- else:
- print(permalink, " is too old")
+def format_monthly_leaderboard():
+ leaderboard = db.get_lambda_leaderboard()
+ out = "**Username**|**Medal**|**Times Helped**|**Lambda**\n:-|:-|:-|:-\n"
+ for username, times_helped, λ in leaderboard:
+ out += "/u/%s|%1s|%s|%sλ\n" % (username, get_medal(λ)[:-1], times_helped, λ)
+ return out + "\nLast updated: %s" % get_time()
@@ -384,8 +394,6 @@ if __name__ == "__main__":
file.write(str(os.getpid()))
file.close()
- # logging.basicConfig(filename = "api.log", format = "[%(asctime)s] %(process)d\t%(message)s", level = logging.DEBUG)
-
display("\n####################\n[%s] RESTARTED\n####################\n" % get_time())
main()