From 720f9901c5d7bfe1ec1f67ba2d664ea390303461 Mon Sep 17 00:00:00 2001 From: jwansek <37976823+jwansek@users.noreply.github.com> Date: Sun, 16 Dec 2018 16:08:19 +0000 Subject: Initial commit --- .gitignore | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 21 +++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..894a44c --- /dev/null +++ b/.gitignore @@ -0,0 +1,104 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5e307b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 jwansek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. -- cgit v1.2.3 From 379a3330624e31365fc38b7d6ff91f984ff186d7 Mon Sep 17 00:00:00 2001 From: jwansek <37976823+jwansek@users.noreply.github.com> Date: Sun, 16 Dec 2018 16:09:08 +0000 Subject: Updated list of files to ignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 894a44c..aef518c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +login.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -7,6 +9,7 @@ __pycache__/ *.so # Distribution / packaging +.vs/ .Python build/ develop-eggs/ -- cgit v1.2.3 From 824ebfd153bf8e63a812ec2b9145bf49c8285435 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 16 Dec 2018 16:11:43 +0000 Subject: added files --- .vs/ProjectSettings.json | 3 + .vs/SmallYTChannelBot/v15/.suo | Bin 0 -> 17920 bytes .vs/VSWorkspaceState.json | 7 + .vs/slnx.sqlite | Bin 0 -> 73728 bytes SmallYTChannelBotSubmissions.py | 166 +++++++++++++++++++++ SmallYTChannelDatabase.db | Bin 0 -> 43008 bytes __pycache__/SmallYTChannelBot.cpython-35.pyc | Bin 0 -> 2359 bytes .../SmallYTChannelBotSubmissions.cpython-36.pyc | Bin 0 -> 5875 bytes __pycache__/database.cpython-35.pyc | Bin 0 -> 3437 bytes __pycache__/database.cpython-36.pyc | Bin 0 -> 3933 bytes __pycache__/login.cpython-36.pyc | Bin 0 -> 330 bytes archive_posts.py | 28 ++++ database.py | 86 +++++++++++ login.py | 7 + 14 files changed, 297 insertions(+) create mode 100644 .vs/ProjectSettings.json create mode 100644 .vs/SmallYTChannelBot/v15/.suo create mode 100644 .vs/VSWorkspaceState.json create mode 100644 .vs/slnx.sqlite create mode 100644 SmallYTChannelBotSubmissions.py create mode 100644 SmallYTChannelDatabase.db create mode 100644 __pycache__/SmallYTChannelBot.cpython-35.pyc create mode 100644 __pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc create mode 100644 __pycache__/database.cpython-35.pyc create mode 100644 __pycache__/database.cpython-36.pyc create mode 100644 __pycache__/login.cpython-36.pyc create mode 100644 archive_posts.py create mode 100644 database.py create mode 100644 login.py diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..866f1e1 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/SmallYTChannelBot/v15/.suo b/.vs/SmallYTChannelBot/v15/.suo new file mode 100644 index 0000000..08ba5aa Binary files /dev/null and b/.vs/SmallYTChannelBot/v15/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..5fef1c5 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\SmallYTChannelBotSubmissions.py", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..3cb47c4 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py new file mode 100644 index 0000000..cb1dc21 --- /dev/null +++ b/SmallYTChannelBotSubmissions.py @@ -0,0 +1,166 @@ +from operator import itemgetter +from database import Database +import datetime +import login +import time +import praw +import re + +reddit = login.REDDIT + +subreddit = reddit.subreddit("SmallYTChannel") +#subreddit = reddit.subreddit("jwnskanzkwktest") +db = Database() + +def get_lambda_from_flair(s): + result = re.search("\[(.*)\]", s) + if result is not None and "λ" in result.group(1): + return result.group(1) + else: + return "" + +def update_users_flair(comment): + username = str(comment.author) + flairscore = get_lambda_from_flair(str(comment.author_flair_text)) + flairtext = comment.author_flair_text + if flairtext is None: + flairtext = "" + else: + flairtext = str(flairtext.replace("[%s] " % flairscore, "")) + if username in [str(i) for i in subreddit.moderator()] + ["AutoModerator"]: + newflair = "[∞λ] %s" % (flairtext) + else: + actualscore = db.get_lambda(username)[0] + newflair = "[%iλ] %s" % (actualscore, flairtext) + subreddit.flair.set(redditor = username, text = newflair) + +def get_mods(): + return [str(i) for i in subreddit.moderator()] + ["AutoModerator"] + +def update_tables(): + content = "" + date = str(datetime.date.today()) + mods = get_mods() + data = db.get_scores() + bylambda = [i for i in sorted(data, key = itemgetter(1), reverse = True) if i[0] not in mods][:10] + byhelps = sorted(data, key = itemgetter(2), reverse = True)[:10] + + content += "\n\n#/r/SmallYTChannel lambda tables: %s" % date + + content += "\n\n##By lambda:" + content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" + for line in bylambda: + content += "\n/u/%s|%i|%i" % (line[0], line[1], line[2]) + + content += "\n\n##By Help given:" + content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" + for line in byhelps: + λ = str(line[1]) + if line[0] in mods: + λ = "∞" + content += "\n/u/%s|%s|%i" % (line[0], λ, line[2]) + + subreddit.wiki["lambdatables"].edit(content, reason = "Update: %s" % date) + +def main(): + tail = "\n\n\n ^/u/SmallYTChannelBot ^*made* ^*by* ^/u/jwnskanzkwk. ^*PM* ^*for* ^*bug* ^*reports.* ^*For* ^*more* ^*information,* ^*read* ^*the* ^[FAQ.](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)" + + comment_stream = subreddit.stream.comments(pause_after=-1) + submission_stream = subreddit.stream.submissions(pause_after=-1) + while True: + try: + for comment in comment_stream: + if comment is None: + break + if not db.id_in_blacklist(comment.id): + db.add_to_blacklist(comment.id) + + if "!mylambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + author = str(comment.author) + λ, links = db.get_lambda(author) + if author in get_mods(): + text = "/u/%s is a moderator, and therefore has ∞λ." % author + else: + if λ == 0: + text = "/u/%s has 0λ." % author + else: + text = "/u/%s has %iλ, from helping the following posts:" % (author, λ) + count = 0 + for link in links: + if "www.reddit.com" not in link: + link = "https://www.reddit.com" + link + + #set a max limit on the number of times this will iterate to stop it + #breaking because of Reddit's character limit. + count += 1 + text += "\n\n- [%s](%s)" % (reddit.submission(url = link).title, link) + if count > 20: #experminent with this number + text += "\n\n[%i more...]" % len(links) - count + break + + reply = comment.reply(text + tail) + reply.mod.distinguish(sticky = False) + update_users_flair(comment) + + + if "!givelambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + submission = comment.submission + parentauthour = str(comment.parent().author) + op = str(comment.author) + if op == parentauthour: + text = "You cannot give yourself λ." + elif op == "SmallYTChannelBot": + text = "Please only give lambda to humans." + elif op != str(submission.author): + text = "Only the OP can give λ." + elif comment.is_root: + text = "You can only give λ to top-level comments." + else: + print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) + text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) + + if not db.link_in_db(submission.permalink) or not db.link_in_db(submission.permalink.replace("https://www.reddit.com", "")): + db.give_lambda(parentauthour, submission.permalink, op) + print("The OP has received lambda too!") + else: + db.give_lambda(parentauthour, submission.permalink) + + update_users_flair(comment) + update_users_flair(comment.parent()) + reply = comment.reply(text + tail) + reply.mod.distinguish() + + for submission in submission_stream: + if submission is None: + break + if not db.id_in_blacklist(submission.id): + db.add_to_blacklist(submission.id) + print("There has been a new submission: '%s', with flair '%s'" % (submission.title, submission.link_flair_text)) + + if str(submission.author) not in get_mods(): + score = db.get_lambda(str(submission.author))[0] + if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: + text = "Your post is a discussion, meta or collab post so it costs 0λ." + else: + if score < 3: + text = """Thank you for submitting to /r/SmallYTChannel. Please be aware that soon you will need to have at least 3λ to submit here. + You currently have %iλ. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You will be rewarded 1λ if you + do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) + #submission.mod.remove() + else: + #db.change_lambda(str(submission.author), -3) + text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. Soon + you will have to spend your λ to post here. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You + will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) + + update_users_flair(submission) + reply = submission.reply(text + tail) + reply.mod.distinguish(sticky = True) + + except Exception as e: + print("[ERROR]\t%s" % e) + continue + +if __name__ == "__main__": + main() + diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db new file mode 100644 index 0000000..2423b66 Binary files /dev/null and b/SmallYTChannelDatabase.db differ diff --git a/__pycache__/SmallYTChannelBot.cpython-35.pyc b/__pycache__/SmallYTChannelBot.cpython-35.pyc new file mode 100644 index 0000000..c2a99da Binary files /dev/null and b/__pycache__/SmallYTChannelBot.cpython-35.pyc differ diff --git a/__pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc b/__pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc new file mode 100644 index 0000000..e9d82cd Binary files /dev/null and b/__pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc differ diff --git a/__pycache__/database.cpython-35.pyc b/__pycache__/database.cpython-35.pyc new file mode 100644 index 0000000..042d938 Binary files /dev/null and b/__pycache__/database.cpython-35.pyc differ diff --git a/__pycache__/database.cpython-36.pyc b/__pycache__/database.cpython-36.pyc new file mode 100644 index 0000000..5bca449 Binary files /dev/null and b/__pycache__/database.cpython-36.pyc differ diff --git a/__pycache__/login.cpython-36.pyc b/__pycache__/login.cpython-36.pyc new file mode 100644 index 0000000..bf91463 Binary files /dev/null and b/__pycache__/login.cpython-36.pyc differ diff --git a/archive_posts.py b/archive_posts.py new file mode 100644 index 0000000..ec6206b --- /dev/null +++ b/archive_posts.py @@ -0,0 +1,28 @@ +import praw +import database + +reddit = praw.Reddit(client_id = "PyyyRXa3veWsWA", + client_secret = "hAMbhuzdHIew5hmn1CFwWb5FurM", + user_agent = "SmallYTChannelBot", + username = "SmallYTChannelBot", + password = "6NEWGNPBjJjbOjk3lbtm") + +subreddit = reddit.subreddit("SmallYTChannel") +db = database.Database() + +comment_stream = subreddit.stream.comments(pause_after=-1) +submission_stream = subreddit.stream.submissions(pause_after=-1) +while True: + for comment in comment_stream: + if comment is None: + break + if not db.id_in_blacklist(comment.id): + print("archived: ", comment.id) + db.add_to_blacklist(comment.id) + + for submission in submission_stream: + if submission is None: + break + if not db.id_in_blacklist(submission.id): + print("archived: ", submission.id) + db.add_to_blacklist(submission.id) diff --git a/database.py b/database.py new file mode 100644 index 0000000..f31a338 --- /dev/null +++ b/database.py @@ -0,0 +1,86 @@ +import sqlite3 + +class Database: + def __init__(self): + self.connection = sqlite3.connect("SmallYTChannelDatabase.db") + self.cursor = self.connection.cursor() + + def change_lambda(self, user, changeby): + #this will make it go negative. You must check this operation is allowed. + self.cursor.execute("UPDATE users SET lambda = ((SELECT lambda FROM users WHERE user_name = ?) + ?) WHERE user_name = ?;", (user, changeby, user)) + self.connection.commit() + + def give_lambda(self, user, link, op = None): + def give(user, link = None): + #check if the user has an entry in the database + self.cursor.execute("SELECT userID FROM users WHERE user_name = ?;", (user, )) + try: + id_ = self.cursor.fetchone()[0] + except TypeError: + #the user isn't in the database + self.cursor.execute("INSERT INTO users (user_name, lambda) VALUES (?, 1);", (user, )) + self.connection.commit() + if link is not None: + self.cursor.execute("INSERT INTO lambdas (userID, permalink) VALUES ((SELECT userID FROM users WHERE user_name = ?), ?);", (user, link)) + else: + #update their lambda and add to lambdas + self.change_lambda(user, 1) + if link is not None: + self.cursor.execute("INSERT INTO lambdas (userID, permalink) VALUES (?, ?);", (id_, link)) + + self.connection.commit() + + #give one lambda to both the user and the OP + give(user, link) + if op is not None: + give(op) + + def get_lambda(self, user): + self.cursor.execute("SELECT lambda FROM users WHERE user_name = ?", (user, )) + try: + lambda_ = self.cursor.fetchone()[0] + except TypeError: + #the user isn't in the database, and therefore has no lambda + return 0, [] + else: + self.cursor.execute("SELECT permalink FROM lambdas WHERE userID = (SELECT userID FROM users WHERE user_name = ?);", (user, )) + links = [i[0] for i in self.cursor.fetchall()] + + return lambda_, links + + def link_in_db(self, link): + self.cursor.execute("SELECT permalink FROM lambdas;") + try: + links = [i[0] for i in self.cursor.fetchall()] + except TypeError: + links = [] + + return link in links + + def add_to_blacklist(self, id): + self.cursor.execute("INSERT INTO blacklist (prawID) VALUES (?);", (id, )) + self.connection.commit() + + def id_in_blacklist(self, id): + self.cursor.execute("SELECT prawID FROM blacklist;") + try: + ids = [i[0] for i in self.cursor.fetchall()] + except TypeError: + ids = [] + + return id in ids + + def get_scores(self): + self.cursor.execute("SELECT users.user_name, users.lambda, COUNT(users.user_name) FROM lambdas INNER JOIN users ON users.userID = lambdas.userID GROUP BY users.user_name;") + return self.cursor.fetchall() + + + def update_stats(self): + query = """INSERT INTO stats (lambdaCount, helpGiven, uniqueUsers, date) VALUES ( + (SELECT SUM(lambda) FROM users), + (SELECT COUNT(lambdaID) FROM lambdas), + (SELECT COUNT(user_name) FROM users), + (SELECT strftime('%Y-%m-%d')));""" + + self.cursor.execute(query) + self.connection.commit() diff --git a/login.py b/login.py new file mode 100644 index 0000000..67eb525 --- /dev/null +++ b/login.py @@ -0,0 +1,7 @@ +import praw + +REDDIT = praw.Reddit(client_id = "PyyyRXa3veWsWA", + client_secret = "hAMbhuzdHIew5hmn1CFwWb5FurM", + user_agent = "SmallYTChannelBot", + username = "SmallYTChannelBot", + password = "6NEWGNPBjJjbOjk3lbtm") -- cgit v1.2.3 From be4875fa0dc1d534df3504861dbd0991ac5e27bd Mon Sep 17 00:00:00 2001 From: jwansek <37976823+jwansek@users.noreply.github.com> Date: Sun, 16 Dec 2018 16:16:48 +0000 Subject: Deleted a file --- login.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 login.py diff --git a/login.py b/login.py deleted file mode 100644 index 67eb525..0000000 --- a/login.py +++ /dev/null @@ -1,7 +0,0 @@ -import praw - -REDDIT = praw.Reddit(client_id = "PyyyRXa3veWsWA", - client_secret = "hAMbhuzdHIew5hmn1CFwWb5FurM", - user_agent = "SmallYTChannelBot", - username = "SmallYTChannelBot", - password = "6NEWGNPBjJjbOjk3lbtm") -- cgit v1.2.3 From 704cc4e17c74dc96964673085dfc8d509204008a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 16 Dec 2018 16:19:44 +0000 Subject: removed some files --- .vs/ProjectSettings.json | 3 --- .vs/SmallYTChannelBot/v15/.suo | Bin 17920 -> 0 bytes .vs/VSWorkspaceState.json | 7 ------- .vs/slnx.sqlite | Bin 73728 -> 0 bytes SmallYTChannelDatabase.db | Bin 43008 -> 43008 bytes __pycache__/SmallYTChannelBot.cpython-35.pyc | Bin 2359 -> 0 bytes .../SmallYTChannelBotSubmissions.cpython-36.pyc | Bin 5875 -> 0 bytes __pycache__/database.cpython-35.pyc | Bin 3437 -> 0 bytes __pycache__/database.cpython-36.pyc | Bin 3933 -> 0 bytes __pycache__/login.cpython-36.pyc | Bin 330 -> 0 bytes login.py | 7 ------- 11 files changed, 17 deletions(-) delete mode 100644 .vs/ProjectSettings.json delete mode 100644 .vs/SmallYTChannelBot/v15/.suo delete mode 100644 .vs/VSWorkspaceState.json delete mode 100644 .vs/slnx.sqlite delete mode 100644 __pycache__/SmallYTChannelBot.cpython-35.pyc delete mode 100644 __pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc delete mode 100644 __pycache__/database.cpython-35.pyc delete mode 100644 __pycache__/database.cpython-36.pyc delete mode 100644 __pycache__/login.cpython-36.pyc delete mode 100644 login.py diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json deleted file mode 100644 index 866f1e1..0000000 --- a/.vs/ProjectSettings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "CurrentProjectSetting": null -} \ No newline at end of file diff --git a/.vs/SmallYTChannelBot/v15/.suo b/.vs/SmallYTChannelBot/v15/.suo deleted file mode 100644 index 08ba5aa..0000000 Binary files a/.vs/SmallYTChannelBot/v15/.suo and /dev/null differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json deleted file mode 100644 index 5fef1c5..0000000 --- a/.vs/VSWorkspaceState.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ExpandedNodes": [ - "" - ], - "SelectedNode": "\\SmallYTChannelBotSubmissions.py", - "PreviewInSolutionExplorer": false -} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite deleted file mode 100644 index 3cb47c4..0000000 Binary files a/.vs/slnx.sqlite and /dev/null differ diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index 2423b66..b94dc41 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ diff --git a/__pycache__/SmallYTChannelBot.cpython-35.pyc b/__pycache__/SmallYTChannelBot.cpython-35.pyc deleted file mode 100644 index c2a99da..0000000 Binary files a/__pycache__/SmallYTChannelBot.cpython-35.pyc and /dev/null differ diff --git a/__pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc b/__pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc deleted file mode 100644 index e9d82cd..0000000 Binary files a/__pycache__/SmallYTChannelBotSubmissions.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/database.cpython-35.pyc b/__pycache__/database.cpython-35.pyc deleted file mode 100644 index 042d938..0000000 Binary files a/__pycache__/database.cpython-35.pyc and /dev/null differ diff --git a/__pycache__/database.cpython-36.pyc b/__pycache__/database.cpython-36.pyc deleted file mode 100644 index 5bca449..0000000 Binary files a/__pycache__/database.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/login.cpython-36.pyc b/__pycache__/login.cpython-36.pyc deleted file mode 100644 index bf91463..0000000 Binary files a/__pycache__/login.cpython-36.pyc and /dev/null differ diff --git a/login.py b/login.py deleted file mode 100644 index 67eb525..0000000 --- a/login.py +++ /dev/null @@ -1,7 +0,0 @@ -import praw - -REDDIT = praw.Reddit(client_id = "PyyyRXa3veWsWA", - client_secret = "hAMbhuzdHIew5hmn1CFwWb5FurM", - user_agent = "SmallYTChannelBot", - username = "SmallYTChannelBot", - password = "6NEWGNPBjJjbOjk3lbtm") -- cgit v1.2.3 From 9b50352292cd3349a0e8f6f797c77506232d434e Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 16 Dec 2018 16:29:22 +0000 Subject: test --- SmallYTChannelDatabase.db | Bin 43008 -> 43008 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index b94dc41..306b119 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ -- cgit v1.2.3 From 60ecebe1a08dfc70194259922783ce06cc8894aa Mon Sep 17 00:00:00 2001 From: jwansek Date: Sun, 16 Dec 2018 16:37:59 +0000 Subject: test --- SmallYTChannelDatabase.db | Bin 43008 -> 43008 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index 306b119..e883bfe 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ -- cgit v1.2.3 From fcf50be2e34e0eb82fbd301e119f8873d2735cf9 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 17 Dec 2018 16:37:46 +0000 Subject: added statistics --- .gitignore | 1 + SmallYTChannelBotSubmissions.py | 77 ++++++++++++++++++++++++++++++++++++---- SmallYTChannelDatabase.db | Bin 43008 -> 43008 bytes database.py | 5 ++- 4 files changed, 75 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index aef518c..8b220d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ login.py +graph.png # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index cb1dc21..965258c 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -1,5 +1,10 @@ +from mpl_toolkits.axes_grid1 import host_subplot +import mpl_toolkits.axisartist as AA +from imgurpython import ImgurClient +import matplotlib.pyplot as plt from operator import itemgetter from database import Database +import matplotlib import datetime import login import time @@ -37,22 +42,51 @@ def update_users_flair(comment): def get_mods(): return [str(i) for i in subreddit.moderator()] + ["AutoModerator"] -def update_tables(): +def _make_graph(data): + fig = plt.figure() + + lambdaCount = [i[1] for i in data] + helpGiven = [i[2] for i in data] + uniqueUsers = [i[3] for i in data] + date = [datetime.datetime.strptime(i[4], "%Y-%m-%d") for i in data] + + fig, ax1 = plt.subplots() + ax1.plot(date, lambdaCount, label = "Total λ given", color = "r") + ax1.set_ylabel("Total λ / help given") + + ax1.plot(date, helpGiven, label = "Times help given", color = "g") + + ax2 = ax1.twinx() + ax2.plot(date, uniqueUsers, label = "Unique users") + ax2.set_ylabel("No. Unique Users") + + ax1.legend() + ax2.legend(loc = 4) + fig.autofmt_xdate() + + filepath = "graph.png" + fig.savefig(filepath) + return filepath + +def _update_tables(scores, data): content = "" date = str(datetime.date.today()) mods = get_mods() - data = db.get_scores() - bylambda = [i for i in sorted(data, key = itemgetter(1), reverse = True) if i[0] not in mods][:10] - byhelps = sorted(data, key = itemgetter(2), reverse = True)[:10] + imagepath = _make_graph(data) + imageurl = _upload_image(imagepath, date) + bylambda = [i for i in sorted(scores, key = itemgetter(1), reverse = True) if i[0] not in mods][:10] + byhelps = sorted(scores, key = itemgetter(2), reverse = True)[:10] - content += "\n\n#/r/SmallYTChannel lambda tables: %s" % date + subreddit.stylesheet.upload("wikigraph", imagepath) - content += "\n\n##By lambda:" + content += "\n\n##/r/SmallYTChannel lambda tables: %s" % date + + content += "\n\n###By lambda:" content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" for line in bylambda: content += "\n/u/%s|%i|%i" % (line[0], line[1], line[2]) - content += "\n\n##By Help given:" + content += "\n\n###By Help given:" content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" for line in byhelps: λ = str(line[1]) @@ -60,7 +94,36 @@ def update_tables(): λ = "∞" content += "\n/u/%s|%s|%i" % (line[0], λ, line[2]) + content += "\n\n##Statistics from %s:\n\n![](%%%%wikigraph%%%%)\n\nTotal λ given|Useful advice given|Unique users\n:--|:--|:--\n%i|%i|%i" % (date, data[-1][1], data[-1][2], data[-1][3]) + + reddit.subreddit("u_SmallYTChannelBot").submit("/r/SmallYTChannel Statistics: %s" % date, url = imageurl).reply(content).mod.distinguish(sticky = True) + subreddit.wiki["lambdatables"].edit(content, reason = "Update: %s" % date) + subreddit.wiki[date].edit(content, reason = "Update: %s" % date) + + currentdata = subreddit.wiki["index"].content_md + currentdata += "\n\n* [%s](/r/SmallYTChannel/wiki/%s)" % (date, date) + + subreddit.wiki["index"].edit(currentdata, reason = "Update: %s" % date) + +def _upload_image(path, date): + client = login.IMGUR + + config = { + 'album': None, + 'name': 'SmallYTChannelBot Statistics graph: %s' % date, + 'title': 'SmallYTChannelBot Statistics graph: %s' % date, + 'description': 'SmallYTChannelBot Statistics graph: %s' % date + } + + image = client.upload_from_path(path, config = config) + + return "https://i.imgur.com/%s.png" % image["id"] + +def every_day(): + db.update_stats() + _update_tables(db.get_scores(), db.get_stats()) + def main(): tail = "\n\n\n ^/u/SmallYTChannelBot ^*made* ^*by* ^/u/jwnskanzkwk. ^*PM* ^*for* ^*bug* ^*reports.* ^*For* ^*more* ^*information,* ^*read* ^*the* ^[FAQ.](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)" diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index e883bfe..bd19d26 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ diff --git a/database.py b/database.py index f31a338..0048296 100644 --- a/database.py +++ b/database.py @@ -74,7 +74,6 @@ class Database: self.cursor.execute("SELECT users.user_name, users.lambda, COUNT(users.user_name) FROM lambdas INNER JOIN users ON users.userID = lambdas.userID GROUP BY users.user_name;") return self.cursor.fetchall() - def update_stats(self): query = """INSERT INTO stats (lambdaCount, helpGiven, uniqueUsers, date) VALUES ( (SELECT SUM(lambda) FROM users), @@ -84,3 +83,7 @@ class Database: self.cursor.execute(query) self.connection.commit() + + def get_stats(self): + self.cursor.execute("SELECT * FROM stats;") + return self.cursor.fetchall() -- cgit v1.2.3 From e22d7f764d1b3cc8924b6c7937830cab0cb9f7bf Mon Sep 17 00:00:00 2001 From: jwansek <37976823+jwansek@users.noreply.github.com> Date: Mon, 17 Dec 2018 16:41:48 +0000 Subject: Deleted a file --- archive_posts.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 archive_posts.py diff --git a/archive_posts.py b/archive_posts.py deleted file mode 100644 index ec6206b..0000000 --- a/archive_posts.py +++ /dev/null @@ -1,28 +0,0 @@ -import praw -import database - -reddit = praw.Reddit(client_id = "PyyyRXa3veWsWA", - client_secret = "hAMbhuzdHIew5hmn1CFwWb5FurM", - user_agent = "SmallYTChannelBot", - username = "SmallYTChannelBot", - password = "6NEWGNPBjJjbOjk3lbtm") - -subreddit = reddit.subreddit("SmallYTChannel") -db = database.Database() - -comment_stream = subreddit.stream.comments(pause_after=-1) -submission_stream = subreddit.stream.submissions(pause_after=-1) -while True: - for comment in comment_stream: - if comment is None: - break - if not db.id_in_blacklist(comment.id): - print("archived: ", comment.id) - db.add_to_blacklist(comment.id) - - for submission in submission_stream: - if submission is None: - break - if not db.id_in_blacklist(submission.id): - print("archived: ", submission.id) - db.add_to_blacklist(submission.id) -- cgit v1.2.3 From a06d007ed2a7d36553082580ec020a418417d038 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 17 Dec 2018 16:42:40 +0000 Subject: removed a file --- archive_posts.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 archive_posts.py diff --git a/archive_posts.py b/archive_posts.py deleted file mode 100644 index ec6206b..0000000 --- a/archive_posts.py +++ /dev/null @@ -1,28 +0,0 @@ -import praw -import database - -reddit = praw.Reddit(client_id = "PyyyRXa3veWsWA", - client_secret = "hAMbhuzdHIew5hmn1CFwWb5FurM", - user_agent = "SmallYTChannelBot", - username = "SmallYTChannelBot", - password = "6NEWGNPBjJjbOjk3lbtm") - -subreddit = reddit.subreddit("SmallYTChannel") -db = database.Database() - -comment_stream = subreddit.stream.comments(pause_after=-1) -submission_stream = subreddit.stream.submissions(pause_after=-1) -while True: - for comment in comment_stream: - if comment is None: - break - if not db.id_in_blacklist(comment.id): - print("archived: ", comment.id) - db.add_to_blacklist(comment.id) - - for submission in submission_stream: - if submission is None: - break - if not db.id_in_blacklist(submission.id): - print("archived: ", submission.id) - db.add_to_blacklist(submission.id) -- cgit v1.2.3 From aae7b7bbe9433624507ed926265c70440be9a9ac Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 17 Dec 2018 16:48:40 +0000 Subject: updated database --- SmallYTChannelDatabase.db | Bin 43008 -> 63488 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index e883bfe..7600586 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ -- cgit v1.2.3 From e5692e2ff13b3a7533e157308061aadbe0ecd12d Mon Sep 17 00:00:00 2001 From: jwansek <37976823+jwansek@users.noreply.github.com> Date: Mon, 17 Dec 2018 16:50:03 +0000 Subject: Temporarily deleted the main database --- SmallYTChannelDatabase.db | Bin 43008 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 SmallYTChannelDatabase.db diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db deleted file mode 100644 index bd19d26..0000000 Binary files a/SmallYTChannelDatabase.db and /dev/null differ -- cgit v1.2.3 From a9a0cf77566631bb9244a1d43595a0d91a305c9a Mon Sep 17 00:00:00 2001 From: jwansek Date: Wed, 19 Dec 2018 16:21:06 +0000 Subject: added stats program caller --- SmallYTChannelDatabase.db | Bin 63488 -> 104448 bytes onceaday.py | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 onceaday.py diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index 7600586..1376c85 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ diff --git a/onceaday.py b/onceaday.py new file mode 100644 index 0000000..593a514 --- /dev/null +++ b/onceaday.py @@ -0,0 +1,8 @@ +import SmallYTChannelBotSubmissions +from time import sleep + +SECONDS_IN_DAY = 25 * 60 * 60 + +while True: + SmallYTChannelBotSubmissions.every_day() + sleep(SECONDS_IN_DAY) -- cgit v1.2.3 From 981a30eb4483638a17e908c176887b2b3a4f7d5f Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 31 Dec 2018 23:25:35 +0000 Subject: updated database --- SmallYTChannelDatabase.db | Bin 104448 -> 289792 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index 1376c85..2c7f6a7 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ -- cgit v1.2.3 From 388d15fe0640bb50438fa2d3640b2f29bc07ada7 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 31 Dec 2018 23:27:11 +0000 Subject: removed posts with insufficient lambda, etc. --- SmallYTChannelBotSubmissions.py | 35 +++++++++++++++++++++-------------- database.py | 6 ++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 965258c..38dd49a 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -13,8 +13,9 @@ import re reddit = login.REDDIT -subreddit = reddit.subreddit("SmallYTChannel") -#subreddit = reddit.subreddit("jwnskanzkwktest") +#subreddit = reddit.subreddit("SmallYTChannel") +subreddit = reddit.subreddit("jwnskanzkwktest") + db = Database() def get_lambda_from_flair(s): @@ -138,7 +139,7 @@ def main(): if not db.id_in_blacklist(comment.id): db.add_to_blacklist(comment.id) - if "!mylambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + if "!mylambda" in comment.body.lower() and str(comment.author) != "SmallYTChannelBot": author = str(comment.author) λ, links = db.get_lambda(author) if author in get_mods(): @@ -166,18 +167,21 @@ def main(): update_users_flair(comment) - if "!givelambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + if "!givelambda" in comment.body.lower() and str(comment.author) != "SmallYTChannelBot": submission = comment.submission parentauthour = str(comment.parent().author) op = str(comment.author) if op == parentauthour: text = "You cannot give yourself λ." - elif op == "SmallYTChannelBot": + elif parentauthour == "SmallYTChannelBot": text = "Please only give lambda to humans." + elif str(comment.author) in get_mods(): + text = "The moderator /u/%s has given /u/%s 1λ. /u/%s now has %iλ." % (str(comment.author), parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) + db.give_lambda(parentauthour, submission.permalink) elif op != str(submission.author): text = "Only the OP can give λ." - elif comment.is_root: - text = "You can only give λ to top-level comments." + elif db.user_given_lambda(parentauthour, str(submission.permalink)): + text = "You have already given /u/%s λ for this submission. Why not give λ to another user instead?" % parentauthour else: print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) @@ -203,18 +207,21 @@ def main(): if str(submission.author) not in get_mods(): score = db.get_lambda(str(submission.author))[0] if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: - text = "Your post is a discussion, meta or collab post so it costs 0λ." + if "youtube.com" in str(submission.url): + text = "Your post has been removed because it has the wrong flair. [Discussion], [Meta] and [Collab] flairs are only for text submissions." + submission.mod.remove() + else: + text = "Your post is a discussion, meta or collab post so it costs 0λ." else: if score < 3: - text = """Thank you for submitting to /r/SmallYTChannel. Please be aware that soon you will need to have at least 3λ to submit here. - You currently have %iλ. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You will be rewarded 1λ if you - do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) - #submission.mod.remove() + text = """Thank you for submitting to /r/SmallYTChannel. Unfortunally, you submission has been removed since you do not have enough λ. You need + 3λ to post. You currently have %iλ. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % score + submission.mod.remove() else: - #db.change_lambda(str(submission.author), -3) text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. Soon you will have to spend your λ to post here. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You - will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) + will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score - 3, str(submission.author)) + db.change_lambda(str(submission.author), -3) update_users_flair(submission) reply = submission.reply(text + tail) diff --git a/database.py b/database.py index 0048296..26b8e43 100644 --- a/database.py +++ b/database.py @@ -87,3 +87,9 @@ class Database: def get_stats(self): self.cursor.execute("SELECT * FROM stats;") return self.cursor.fetchall() + + def user_given_lambda(self, user, permalink): + links = self.get_lambda(user)[1] + return permalink in links or permalink.replace("https://www.reddit.com", "") in links + + -- cgit v1.2.3 From 7d50f8192ebd000a7a0b5a2b70dc62fb305d78e0 Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:26:11 +0000 Subject: updated database --- SmallYTChannelDatabase.db | Bin 289792 -> 292864 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index 2c7f6a7..2c1a0b7 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ -- cgit v1.2.3 From bebe783ec55d789b11343a621acc9c89df91a673 Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:27:10 +0000 Subject: added mod removal lambda --- SmallYTChannelBotSubmissions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 38dd49a..fa8f209 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -125,7 +125,6 @@ def every_day(): db.update_stats() _update_tables(db.get_scores(), db.get_stats()) - def main(): tail = "\n\n\n ^/u/SmallYTChannelBot ^*made* ^*by* ^/u/jwnskanzkwk. ^*PM* ^*for* ^*bug* ^*reports.* ^*For* ^*more* ^*information,* ^*read* ^*the* ^[FAQ.](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)" @@ -196,6 +195,24 @@ def main(): update_users_flair(comment.parent()) reply = comment.reply(text + tail) reply.mod.distinguish() + + if comment.body[:11] == "!takelambda" and str(comment.author) in get_mods(): + try: + splitted = comment.body.split() + user = splitted[1].replace("/u/", "") + toremove = int(splitted[2]) + reason = " ".join(splitted[3:]) + + text = "/u/%s has had %iλ taken away from them for the reason '%s'. /u/%s now has %iλ" % (user, toremove, reason, user, db.get_lambda(user)[0] - toremove) + db.change_lambda(user, -toremove) + except Exception as e: + print("[ERROR while removing λ] %s" % e) + text = r"An error was encountered. Please use the syntax `!givelambda [user] [how much to remove {integer}] [reason]`" + + update_users_flair(comment) + reply = comment.reply(text + tail) + reply.mod.distinguish() + for submission in submission_stream: if submission is None: -- cgit v1.2.3 From c8087aea0dbff1a2abf474a987465e817e5ad611 Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:34:50 +0000 Subject: fixed a bug and added archive prog --- SmallYTChannelBotSubmissions.py | 2 +- archive_posts.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 archive_posts.py diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index fa8f209..2a58aae 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -207,7 +207,7 @@ def main(): db.change_lambda(user, -toremove) except Exception as e: print("[ERROR while removing λ] %s" % e) - text = r"An error was encountered. Please use the syntax `!givelambda [user] [how much to remove {integer}] [reason]`" + text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" update_users_flair(comment) reply = comment.reply(text + tail) diff --git a/archive_posts.py b/archive_posts.py new file mode 100644 index 0000000..a68feaf --- /dev/null +++ b/archive_posts.py @@ -0,0 +1,25 @@ +import praw +import database +import login + +reddit = login.REDDIT + +subreddit = reddit.subreddit("jwnskanzkwktest") +db = database.Database() + +comment_stream = subreddit.stream.comments(pause_after=-1) +submission_stream = subreddit.stream.submissions(pause_after=-1) +while True: + for comment in comment_stream: + if comment is None: + break + if not db.id_in_blacklist(comment.id): + print("archived: ", comment.id) + db.add_to_blacklist(comment.id) + + for submission in submission_stream: + if submission is None: + break + if not db.id_in_blacklist(submission.id): + print("archived: ", submission.id) + db.add_to_blacklist(submission.id) \ No newline at end of file -- cgit v1.2.3 From d6e05c8118561980f5675e2a7d086d1bf60e3f8e Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:42:45 +0000 Subject: made a slight modification --- SmallYTChannelBotSubmissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 2a58aae..ed4a339 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -209,7 +209,7 @@ def main(): print("[ERROR while removing λ] %s" % e) text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" - update_users_flair(comment) + update_users_flair(comment.parent()) reply = comment.reply(text + tail) reply.mod.distinguish() -- cgit v1.2.3 From b7b724c24220b9396e83787f6311082a9b6680e1 Mon Sep 17 00:00:00 2001 From: jwansek Date: Thu, 3 Jan 2019 13:59:38 +0000 Subject: fixed a tiny bug --- SmallYTChannelBotSubmissions.py | 8 ++++---- SmallYTChannelDatabase.db | Bin 292864 -> 324608 bytes 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index ed4a339..2a95c48 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -13,8 +13,8 @@ import re reddit = login.REDDIT -#subreddit = reddit.subreddit("SmallYTChannel") -subreddit = reddit.subreddit("jwnskanzkwktest") +subreddit = reddit.subreddit("SmallYTChannel") +#subreddit = reddit.subreddit("jwnskanzkwktest") db = Database() @@ -235,8 +235,8 @@ def main(): 3λ to post. You currently have %iλ. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % score submission.mod.remove() else: - text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. Soon - you will have to spend your λ to post here. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You + text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. + /u/%s, please comment `!givelambda` to the most helpful advice you are given. You will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score - 3, str(submission.author)) db.change_lambda(str(submission.author), -3) diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index 2c1a0b7..ada38e6 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ -- cgit v1.2.3 From 93c4146644ea2125fd13a971c456a9ffcf6a274d Mon Sep 17 00:00:00 2001 From: jwansek Date: Sun, 6 Jan 2019 20:43:49 +0000 Subject: added feature that restarts the program every two hours and fixed one bug --- SmallYTChannelBotSubmissions.py | 21 +++++++++++++++++---- SmallYTChannelDatabase.db | Bin 324608 -> 406528 bytes onceaday.py | 1 + runprog.py | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 runprog.py diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 2a95c48..712f5b0 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -10,6 +10,7 @@ import login import time import praw import re +import os reddit = login.REDDIT @@ -18,6 +19,10 @@ subreddit = reddit.subreddit("SmallYTChannel") db = Database() +def get_time(): + #this is not the correct way to do this but I don't care + return str(datetime.datetime.now().time())[:8] + def get_lambda_from_flair(s): result = re.search("\[(.*)\]", s) if result is not None and "λ" in result.group(1): @@ -182,9 +187,9 @@ def main(): elif db.user_given_lambda(parentauthour, str(submission.permalink)): text = "You have already given /u/%s λ for this submission. Why not give λ to another user instead?" % parentauthour else: - print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) + print("[%s] '/u/%s' has given '/u/%s' lambda!" % (get_time(), op, parentauthour)) text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) - + if not db.link_in_db(submission.permalink) or not db.link_in_db(submission.permalink.replace("https://www.reddit.com", "")): db.give_lambda(parentauthour, submission.permalink, op) print("The OP has received lambda too!") @@ -208,6 +213,9 @@ def main(): except Exception as e: print("[ERROR while removing λ] %s" % e) text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" + reply = comment.reply(text + tail) + reply.mod.distinguish() + continue update_users_flair(comment.parent()) reply = comment.reply(text + tail) @@ -219,12 +227,12 @@ def main(): break if not db.id_in_blacklist(submission.id): db.add_to_blacklist(submission.id) - print("There has been a new submission: '%s', with flair '%s'" % (submission.title, submission.link_flair_text)) + print("[%s] There has been a new submission: '%s', with flair '%s'" % (get_time(), submission.title, submission.link_flair_text)) if str(submission.author) not in get_mods(): score = db.get_lambda(str(submission.author))[0] if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: - if "youtube.com" in str(submission.url): + if "youtube.com" in str(submission.url) or "youtu.be" in str(submission.url): text = "Your post has been removed because it has the wrong flair. [Discussion], [Meta] and [Collab] flairs are only for text submissions." submission.mod.remove() else: @@ -249,5 +257,10 @@ def main(): continue if __name__ == "__main__": + #file = open("pid.txt", "w") + #file.write(str(os.getpid())) + #file.close() + + print("\n####################\n[%s] RESTARTED\n####################\n" % get_time()) main() diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.db index ada38e6..07a077e 100644 Binary files a/SmallYTChannelDatabase.db and b/SmallYTChannelDatabase.db differ diff --git a/onceaday.py b/onceaday.py index 593a514..a84b0d9 100644 --- a/onceaday.py +++ b/onceaday.py @@ -5,4 +5,5 @@ SECONDS_IN_DAY = 25 * 60 * 60 while True: SmallYTChannelBotSubmissions.every_day() + print("Called @ %s" % SmallYTChannelBotSubmissions.get_time) sleep(SECONDS_IN_DAY) diff --git a/runprog.py b/runprog.py new file mode 100644 index 0000000..a564678 --- /dev/null +++ b/runprog.py @@ -0,0 +1,23 @@ +from time import sleep +import subprocess +import multiprocessing + +def thread_(): + subprocess.run(["python3", "SmallYTChannelBotSubmissions.py"]) + +while True: + thread = multiprocessing.Process(target = thread_, args = ()) + thread.start() + + sleep(60 * 60 * 2) + + #print("closing...") + #file = open("pid.txt", "r") + #pid = file.readlines()[0] + #file.close() + + #subprocess.run(["kill", pid]) + thread.terminate() + + #print("killed ", pid) + -- cgit v1.2.3