aboutsummaryrefslogtreecommitdiffstats
path: root/subreddit.py
diff options
context:
space:
mode:
authorjwanek <eddie.atten.ea29@gmail.com>2020-05-25 21:50:43 +0100
committerjwanek <eddie.atten.ea29@gmail.com>2020-05-25 21:50:43 +0100
commitba7dabc6811dbc1548cbcb6a94b7a619d75753bd (patch)
tree6f83fbce7e12eb3f44496950b4b92bf9ff336b70 /subreddit.py
parent8de537dc2e4c88aabaccd5e775be9a8d8f13e9e5 (diff)
downloadSmallYTChannelBot-ba7dabc6811dbc1548cbcb6a94b7a619d75753bd.tar.gz
SmallYTChannelBot-ba7dabc6811dbc1548cbcb6a94b7a619d75753bd.zip
added lambda timestamping
Diffstat (limited to 'subreddit.py')
-rwxr-xr-xsubreddit.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/subreddit.py b/subreddit.py
index 4afe77a..dbb2e1e 100755
--- a/subreddit.py
+++ b/subreddit.py
@@ -349,6 +349,36 @@ def main():
display("{ERROR} %s" % e)
continue
+def get_submission_times(permalink):
+ if not permalink.startswith("https://www.reddit.com"):
+ permalink = "https://www.reddit.com" + permalink
+
+ submission = REDDIT.submission(url = permalink)
+ return submission.created_utc
+
+def add_times_to_lambdas():
+ updated_permalinks = []
+ for id_, permalink, user, created in db.get_all_lambdas():
+ if created is None and permalink not in updated_permalinks:
+ db.add_date_to_permalink(permalink, get_submission_times(permalink))
+ updated_permalinks.append(permalink)
+ 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")
+
+
+
if __name__ == "__main__":
file = open("pid.txt", "w")
file.write(str(os.getpid()))