aboutsummaryrefslogtreecommitdiffstats
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
parent8de537dc2e4c88aabaccd5e775be9a8d8f13e9e5 (diff)
downloadSmallYTChannelBot-ba7dabc6811dbc1548cbcb6a94b7a619d75753bd.tar.gz
SmallYTChannelBot-ba7dabc6811dbc1548cbcb6a94b7a619d75753bd.zip
added lambda timestamping
-rwxr-xr-xdatabase.py8
-rwxr-xr-xsubreddit.py30
2 files changed, 37 insertions, 1 deletions
diff --git a/database.py b/database.py
index 26b8e43..3a0a15c 100755
--- a/database.py
+++ b/database.py
@@ -92,4 +92,10 @@ class Database:
links = self.get_lambda(user)[1]
return permalink in links or permalink.replace("https://www.reddit.com", "") in links
-
+ def get_all_lambdas(self):
+ self.cursor.execute("SELECT lambdas.lambdaID, lambdas.permalink, users.user_name, lambdas.created FROM lambdas INNER JOIN users ON lambdas.userID = users.userID;")
+ return self.cursor.fetchall()
+
+ def add_date_to_permalink(self, permalink, date):
+ self.cursor.execute("UPDATE lambdas SET created = ? WHERE permalink = ?;", (date, permalink))
+ self.connection.commit() \ No newline at end of file
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()))