aboutsummaryrefslogtreecommitdiffstats
path: root/onceaday
diff options
context:
space:
mode:
Diffstat (limited to 'onceaday')
-rwxr-xr-xonceaday/Dockerfile10
-rwxr-xr-xonceaday/crontab1
-rwxr-xr-xonceaday/graph.py31
-rwxr-xr-xonceaday/onceaday.py94
-rwxr-xr-xonceaday/requirements.txt1
5 files changed, 0 insertions, 137 deletions
diff --git a/onceaday/Dockerfile b/onceaday/Dockerfile
deleted file mode 100755
index 6f733db..0000000
--- a/onceaday/Dockerfile
+++ /dev/null
@@ -1,10 +0,0 @@
-FROM reg.reaweb.uk/smallytchannelbot
-MAINTAINER Eden Attenborough "eddie.atten.ea29@gmail.com"
-ARG DEBIAN_FRONTEND=noninteractive
-RUN apt-get install -y tzdata cron
-COPY . /app
-WORKDIR /app
-COPY onceaday/crontab /etc/cron.d/oad-crontab
-RUN chmod 0644 /etc/cron.d/oad-crontab && crontab /etc/cron.d/oad-crontab
-RUN pip3 install -r onceaday/requirements.txt
-ENTRYPOINT ["cron", "-f"]
diff --git a/onceaday/crontab b/onceaday/crontab
deleted file mode 100755
index c8ce32a..0000000
--- a/onceaday/crontab
+++ /dev/null
@@ -1 +0,0 @@
-@daily python3 /app/onceaday/onceaday.py /app/onceaday
diff --git a/onceaday/graph.py b/onceaday/graph.py
deleted file mode 100755
index 723997b..0000000
--- a/onceaday/graph.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from mpl_toolkits.axes_grid1 import host_subplot
-import mpl_toolkits.axisartist as AA
-import matplotlib.pyplot as plt
-import matplotlib
-import datetime
-
-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 λ in circulation", 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 \ No newline at end of file
diff --git a/onceaday/onceaday.py b/onceaday/onceaday.py
deleted file mode 100755
index 7762d05..0000000
--- a/onceaday/onceaday.py
+++ /dev/null
@@ -1,94 +0,0 @@
-import os
-import sys
-
-os.chdir(sys.argv[1])
-sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
-
-from operator import itemgetter
-import subreddit
-import database
-import datetime
-import graph
-
-def main():
- subreddit.display("Starting every day program...")
- subreddit.display("Updating database statistics...")
- with database.Database() as db:
- db.update_stats()
- subreddit.display("Posting and updating wiki...")
- update_tables(db.get_scores(), db.get_stats())
-
- subreddit.display("Formatting leaderboard...")
- leaderboard = format_monthly_leaderboard()
- subreddit.display("Made the following leaderboard:\n======================\n%s\n======================\n" % leaderboard)
- subreddit.display("Updating sidebar...")
- #it'd be cool to find a way to access this directly without iteration
- for widget in subreddit.SUBREDDIT.widgets.sidebar:
- if widget.shortName == "Monthly Lambda Leaderboard":
- widget.mod.update(text = leaderboard)
- subreddit.display("Updated in new reddit...")
-
- sidebar = subreddit.SUBREDDIT.mod.settings()["description"]
- oldtable = sidebar.split("------")[-1]
- subreddit.SUBREDDIT.wiki['config/sidebar'].edit(content = sidebar.replace(oldtable, "\n\n## Monthly Lambda Leaderboard\n\n" + leaderboard))
- subreddit.display("Updated in old reddit...")
- subreddit.display("Completed.")
-
- subreddit.logging.info("Called OAD prog @ %s" % subreddit.get_time())
-
-def update_tables(scores, data):
- content = ""
- date = str(datetime.date.today())
- mods = get_mods()
- imagepath = graph.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
-
- 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])
-
- content += "\n\n##Statistics from %s:\n\nIf you're looking at this through the wiki, not through the bot's profile, then" % (date)
- content += "the most up-to-date graph will be shown below. To see the graph at this date, follow [this link.](%s)" % (imageurl)
- content += "\n\n![](%%%%wikigraph%%%%)\n\nTotal λ in circulation|Useful advice given|Unique users\n:--|:--|:--\n%i|%i|%i" % (data[-1][1], data[-1][2], data[-1][3])
-
- subreddit.REDDIT.subreddit("u_SmallYTChannelBot").submit("/r/SmallYTChannel Statistics: %s" % date, url = imageurl).reply(content)
-
-
-def get_mods():
- return [str(i) for i in subreddit.SUBREDDIT.moderator()] + ["AutoModerator"]
-
-def format_monthly_leaderboard():
- with database.Database() as db:
- 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, subreddit.get_medal(λ)[:-1], times_helped, λ)
- return out + "\nLast updated: %s" % subreddit.get_time()
-
-def upload_image(path, date):
- config = {
- 'album': None,
- 'name': 'SmallYTChannelBot Statistics graph: %s' % date,
- 'title': 'SmallYTChannelBot Statistics graph: %s' % date,
- 'description': 'SmallYTChannelBot Statistics graph: %s' % date
- }
-
- image = subreddit.IMGUR.upload_from_path(path, config = config)
-
- return "https://i.imgur.com/%s.png" % image["id"]
-
-if __name__ == "__main__":
- main()
diff --git a/onceaday/requirements.txt b/onceaday/requirements.txt
deleted file mode 100755
index e3a623c..0000000
--- a/onceaday/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-matplotlib==3.3.4