-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.py
147 lines (103 loc) · 4.4 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
import sys
import yaml
import os
from utils import convert_num, display_num, download_image
from tweet import twitter_post, twitter_post_image, twitter_repost, set_test_mode
from birthdays import check_birthdays
# from instagram import instagram_data
from youtube import youtube_data
from spotify import spotify_data
from billboard_charts import billboard_data
from radio import radio_data
def load_group():
"""Reads the data.yaml YAML file
Data about a group is stored inside the data.yaml file in the same directory as the script
Returns:
A dictionary that contains all the informations about the group
"""
print("Loading data from YAML file...")
with open('data.yaml', encoding="utf-8") as file:
group = yaml.load(file, Loader=yaml.FullLoader)
out = "{} consist of ".format(group["name"])
for artist in group["members"]:
out += artist["name"]
out += " "
print(out + "\n")
return group
def write_group(group):
"""Writes the data.yaml YAML file
Data about a group is stored inside the data.yaml file in the same directory as the script
Args:
group: dictionary that contains all the informations about the group
"""
print("Writing data to YAML file...")
with open('data.yaml', 'w', encoding="utf-8") as file:
yaml.dump(group, file, sort_keys=False, allow_unicode=True)
def check_args():
"""Checks the arguments passed by the command line
By passing one or more parameters, you can disable a single module source.
Actual parameters allowed are:
* `-no-instagram`: disables Instagram source
* `-no-youtube`: disables YouTube source
* `-no-spotify`: disables Spotify source
* `-no-birthday`: disables birthdays events source
* `-no-twitter`: disables Twitter source (used for reposting)
Remember that `-no-twitter` is different than `-no-tweet`:
`-no-tweet` actually prevents the bot from tweeting any update from the enabled sources. The output will still be visible on the console. This is really useful for **testing**.
Returns:
A dictionary that contains all the sources and their state (enabled or disabled, True or False)
"""
source = {"instagram": True, "radio": True, "youtube": True, "spotify": True, "birthday": True, "twitter": True, "billboard": True}
write = True
if len(sys.argv) > 1:
for arg in sys.argv:
if arg == "-no-tweet":
print("-no-tweet parameter passed!\nTest mode enabled: the bot won't tweet anything")
set_test_mode()
if arg == "-no-instagram":
print("-no-instagram parameter passed!")
source["instagram"] = False
if arg == "-no-radio":
print("-no-radio parameter passed!")
source["radio"] = False
if arg == "-no-spotify":
print("-no-spotify parameter passed!")
source["spotify"] = False
if arg == "-no-youtube":
print("-no-youtube parameter passed!")
source["youtube"] = False
if arg == "-no-birthday":
print("-no-birthday parameter passed!")
source["birthday"] = False
if arg == "-no-billboard":
print("-no-billboard parameter passed!")
source["billboard"] = False
if arg == "-no-twitter":
print("-no-twitter parameter passed!")
source["twitter"] = False
if arg == "-no-write":
print("-no-write parameter passed!")
write = False
print()
return source, write
if __name__ == '__main__':
source, write = check_args()
group = load_group()
if source["birthday"]:
group = check_birthdays(group)
if source["youtube"]:
group = youtube_data(group)
if source["twitter"]:
group = twitter_repost(group)
if source["instagram"]:
# group = instagram_data(group)
print()
if source["spotify"]:
group = spotify_data(group)
if source["billboard"]:
group = billboard_data(group)
if source["radio"]:
radio_data()
if write:
write_group(group)