-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathConfigLoader.py
83 lines (66 loc) · 2.54 KB
/
ConfigLoader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import json
import random
from datetime import datetime
class ConfigLoader():
def ReadConfig(self):
self.hashtags = []
self.comments = []
with open("settings/settings.json") as jsonfile:
data = json.load(jsonfile)
for key, value in data.items():
if key == "hashtags":
self.hashtags = value
if key == "likestoday":
self.likestoday = int(value)
if key == "commentstoday":
self.commentstoday = int(value)
if key == "comments":
self.comments = value
def RandomComment(self):
return random.choice(self.comments)
def RandomHashtag(self):
return random.choice(self.hashtags)
def ReadLikedPhotos(self):
with open("settings/liked.json") as file:
data = json.load(file)
return data["liked"]
def SaveLikedPhoto(self, link):
with open("settings/liked.json") as oldfile:
data = json.load(oldfile)
data["liked"].append(link)
with open("settings/liked.json", "w+") as newfile:
json.dump(data, newfile, indent=4)
def SaveCommentsPosted(self, link):
with open("settings/comment.json") as oldfile:
data = json.load(oldfile)
data["comment"].append(link)
with open("settings/comment.json", "w+") as newfile:
json.dump(data, newfile, indent=4)
def ReadCommentsPosted(self):
with open("settings/comment.json") as file:
data = json.load(file)
return data["comment"]
def ReadFollowedProfiles(self):
with open("settings/followed.json") as file:
data = json.load(file)
profiles_followed = []
profiles_to_unfollow = []
for follow in data['follow'][:]:
link = follow['link']
timex = follow['timestamp']
if self.check_time(timex) == True:
profiles_to_unfollow.append(link)
else:
profiles_followed.append(link)
return [profiles_followed, profiles_to_unfollow]
def check_time(self, datex):
followed_time = datetime.strptime(datex, "%Y-%m-%d %H:%M:%S")
time_now = datetime.strptime(datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")
td_mins = int(
round(abs((followed_time - time_now).total_seconds()) / 60))
# 24 Stunden
if (td_mins/60) >= 24:
return True
else:
return False