-
Notifications
You must be signed in to change notification settings - Fork 0
/
anime-tracker.py
282 lines (222 loc) · 10.8 KB
/
anime-tracker.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#my first truly own program! made on 12-12-16 made by montarion
# make a function to watch x episode of an anime.
import json
import os
import webbrowser
from time import sleep
import requests
print('Welcome to the anime tracker! ')
def updater():
#---
#---url for releases, in JSON---#
url = 'http://www.masterani.me/api/releases'
#---needed conversion---#
test = requests.get(url)
test1 = test.text
test = str(test1)
string = json.loads(str(test))
print('list has been updated')
def search():
#---url for releases, in JSON---#
url = 'http://www.masterani.me/api/releases'
#---needed conversion---#
test = requests.get(url)
test1 = test.text
test = str(test1)
string = json.loads(str(test))
anime0 = string[0]['anime']['title']
anime1 = string[1]['anime']['title']
anime2 = string[2]['anime']['title']
anime3 = string[3]['anime']['title']
anime4 = string[4]['anime']['title']
searchq = input('what are you looking for? ')
print('you searched for the term' + ' "' + searchq + '"')
search0 = searchq.lower() in anime0.lower()
search1 = searchq.lower() in anime1.lower()
search2 = searchq.lower() in anime2.lower()
search3 = searchq.lower() in anime3.lower()
search4 = searchq.lower() in anime4.lower()
if searchq == "debug":
print(anime0)
print(anime1)
print(anime2)
print(anime3)
print(anime4)
if search0 == True:
print(anime0 + ' found! ')
animeurl = 'http://www.masterani.me/anime/watch/' + string[0]['anime']['slug'] + '/' +string[0]['episode']
option = input('Do you want to watch it? ')
if option == 'y' or 'yes':
webbrowser.open(animeurl,2)
elif option == 'n':
print('Alright, bye!')
elif search1 == True:
print(anime1 + ' found! ')
animeurl = 'http://www.masterani.me/anime/watch/' + string[1]['anime']['slug'] + '/' +string[1]['episode']
option = input('Do you want to watch it? ')
if option == 'y' or 'yes':
webbrowser.open(animeurl,2)
elif option == 'n':
print('Alright, bye!')
elif search2 == True:
print(anime2 + ' found! ')
animeurl = 'http://www.masterani.me/anime/watch/' + string[2]['anime']['slug'] + '/' +string[2]['episode']
option = input('Do you want to watch it? ')
if option == 'y' or 'yes':
webbrowser.open(animeurl,2)
elif option == 'n':
print('Alright, bye!')
elif search3 == True:
print(anime3 + ' found! ')
animeurl = 'http://www.masterani.me/anime/watch/' + string[3]['anime']['slug'] + '/' +string[3]['episode']
option = input('Do you want to watch it? ')
if option == 'y' or 'yes':
webbrowser.open(animeurl,2)
elif option == 'n':
print('Alright, bye!')
elif search4 == True:
print(anime4 + ' found! ')
animeurl = 'http://www.masterani.me/anime/watch/' + string[4]['anime']['slug'] + '/' +string[4]['episode']
option = input('Do you want to watch it? ')
if option == 'y' or 'yes':
webbrowser.open(animeurl,2)
elif option == 'n':
print('Alright, bye!')
elif search4 == False:
print('The term ' + '"' + searchq + '"' + " didn't give any results")
def alert():
pass
# Play Windows exit sound.
#winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
def loop():
#---url for releases, in JSON---#
url = 'http://www.masterani.me/api/releases'
#---needed conversion---#
test = requests.get(url)
test1 = test.text
test = str(test1)
string = json.loads(str(test))
filecheck = os.path.isfile('lastshow.txt')
airingshow = string[0]['anime']["title"]
if filecheck is False:
print("creating file..")
lastshow = string[0]['anime']["title"]
#---writes last aired show to file---#
infile = open('lastshow.txt', 'w')
infile.write(lastshow)
infile.close()
else:
#---checks if new show has aired---#
outfile = open('lastshow.txt')
check = outfile.read()
if check != airingshow:
#---prints actual message and plays alert sound---#
print('alert! ' + string[0]['anime']["title"] + ' episode ' + string[0]["episode"] + ' has aired.')
alert()
#---writes new 'last' show---#
lastshow = string[0]['anime']["title"]
infile = open('lastshow.txt', 'w')
infile.write(lastshow)
infile.close()
#---url builder---#
animeurl = 'http://www.masterani.me/anime/watch/' + string[0]['anime']['slug'] + '/' +string[0]['episode']
while True:
option = input('Do you want to watch now?')
if option == 'y' or option == 'yes':
while True:
episodeoption = input('Do you want to choose your episode or do you want to watch the latest one? ')
if episodeoption == 'yes' or episodeoption == 'choose' or episodeoption == 'y':
episode = input("what episode do you want to watch? \n(Warning! I can't guarrantee that the episode will be available.) ")
episodeurl = 'http://www.masterani.me/anime/watch/' + string[0]['anime']['slug'] + '/' + episode
webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open(episodeurl)
elif episodeoption == 'no' or episodeoption == 'latest':
webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open(animeurl)
else:
print("please reply with either 'yes' or 'choose' if you want to choose your episode, or with 'no' or 'latest' if you want to watch the latest episode")
quit()
if option == 'n' or option == 'no':
print("Alright, I'll keep checking. ")
loop()
else:
print("Please reply with either 'y 'or ' n'")
else:
nonews = "no new shows have aired"
#print(nonews)
sleep(6)
print("looping")
loop()
def tracker():
while True:
#---url for releases, in JSON---#
url = 'http://www.masterani.me/api/releases'
#---needed conversion---#
test = requests.get(url)
test1 = test.text
test = str(test1)
string = json.loads(str(test))
while True:
#---checks if file containing last aired episode exists. if False, makes it---#
filecheck = os.path.isfile('lastshow.txt')
airingshow = string[0]['anime']["title"]
if filecheck is False:
lastshow = string[0]['anime']["title"]
#---writes last aired show to file---#
infile = open('lastshow.txt', 'w')
infile.write(lastshow)
infile.close()
else:
menu = input('what do you want to do?')
if menu == '1' or menu == 'watch':
#---checks if new show has aired---#
outfile = open('lastshow.txt')
check = outfile.read()
if check != airingshow:
#---prints actual message and plays alert sound---#
print('alert! ' + string[0]['anime']["title"] + ' episode ' + string[0]["episode"] + ' has aired.')
alert()
#---writes new 'last' show---#
lastshow = string[0]['anime']["title"]
infile = open('lastshow.txt', 'w')
infile.write(lastshow)
infile.close()
#---url builder---#
animeurl = 'http://www.masterani.me/anime/watch/' + string[0]['anime']['slug'] + '/' +string[0]['episode']
while True:
option = input('Do you want to watch now?')
if option == 'y' or option == 'yes':
while True:
episodeoption = input('Do you want to choose your episode or do you want to watch the latest one? ')
if episodeoption == 'yes' or episodeoption == 'choose' or episodeoption == 'y':
episode = input("what episode do you want to watch? \n(Warning! I can't guarrantee that the episode will be available.) ")
episodeurl = 'http://www.masterani.me/anime/watch/' + string[0]['anime']['slug'] + '/' + episode
webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open(episodeurl)
elif episodeoption == 'no' or episodeoption == 'latest':
webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open(animeurl)
else:
print("please reply with either 'yes' or 'choose' if you want to choose your episode, or with 'no' or 'latest' if you want to watch the latest episode")
quit()
if option == 'n' or option == 'no' or option == 'back':
print('Alright, Bye!')
tracker()
else:
print("Please reply with either 'y', 'n', or 'back'")
else:
#---loop counter---#
print('no new shows have aired.')
sleep(2)
if menu == '2' or menu == 'search' or menu == 'find':
try:
search()
except:
print("sorry, can't search.")
sleep(2)
if menu == 'help':
print("possible commands are: \n'1' to see if a new show has aired. \n'2' to search for the a show. the 5 most recently aired shows are available for search.\n'3' to start standby checking for new shows.\n'4' to exit the program.")
sleep(2)
if menu == '3' or menu == 'loop' or menu == 'standyby':
print("starting loop check")
loop()
if menu == '4' or menu == 'exit' or menu == 'quit' or menu == 'leave':
print('Alright, goodbye!')
quit()
tracker()