From 171daf88a753d5683dda695ff83013ae90a76809 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 19 Apr 2021 21:54:00 +0100 Subject: fixed some bugs --- graph.py | 31 ------------------------------- onceaday/graph.py | 31 +++++++++++++++++++++++++++++++ runprog.py | 23 ----------------------- subreddit.py | 7 ++++++- ytapi.py | 8 +++++++- 5 files changed, 44 insertions(+), 56 deletions(-) delete mode 100755 graph.py create mode 100755 onceaday/graph.py delete mode 100755 runprog.py diff --git a/graph.py b/graph.py deleted file mode 100755 index 723997b..0000000 --- a/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/graph.py b/onceaday/graph.py new file mode 100755 index 0000000..723997b --- /dev/null +++ b/onceaday/graph.py @@ -0,0 +1,31 @@ +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/runprog.py b/runprog.py deleted file mode 100755 index 2cac32a..0000000 --- a/runprog.py +++ /dev/null @@ -1,23 +0,0 @@ -from time import sleep -import subprocess -import multiprocessing - -def thread_(): - subprocess.run(["python3", "subreddit.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) - diff --git a/subreddit.py b/subreddit.py index e8c37bb..f4eb8fe 100755 --- a/subreddit.py +++ b/subreddit.py @@ -11,7 +11,12 @@ import json import re import os -with open("config.json", "r") as f: +if os.path.split(os.getcwd())[-1] == "onceaday": + configpath = "../config.json" +else: + configpath = "config.json" + +with open(configpath, "r") as f: CONFIG = json.load(f) REDDIT = praw.Reddit(**CONFIG["redditapi"]) diff --git a/ytapi.py b/ytapi.py index f134018..509cb7f 100755 --- a/ytapi.py +++ b/ytapi.py @@ -2,8 +2,14 @@ from googleapiclient.discovery import build from googleapiclient.errors import HttpError import json import js2py +import os -with open("config.json", "r") as f: +if os.path.split(os.getcwd())[-1] == "onceaday": + configpath = "../config.json" +else: + configpath = "config.json" + +with open(configpath, "r") as f: CONFIG = json.load(f) ERROR_DICT = { -- cgit v1.2.3