-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_url.py
51 lines (49 loc) · 1.59 KB
/
get_url.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
import json
import requests
import time
class GetURL:
def __init__(self, urls, wait_time):
self.wait_time = wait_time
self.urls = urls
self.main_loop()
self.GetData()
# This function takes an id as an input then will return back the url for that id
def checkURL(self, id):
r = requests.get(self.urls).json()['data']
data = json.dumps(r)
data_dict = json.loads(data)
for items in data_dict:
if id == items['id']:
with open("url_file.txt", 'w') as urlfile:
pass
urlfile = open("url_file.txt", "w+")
urlfile.write(items['url'])
urlfile.close()
return items['url']
return 'id not found'
# This function takes an id as an input then will return back the isLive value for that id
def checkLive(self, id):
num = 0
r = requests.get(self.urls).json()['data']
data = json.dumps(r)
data_dict = json.loads(data)
for items in data_dict:
if id == items['id']:
with open("isLive.txt",'w') as livefile:
pass
livefile = open("isLive.txt", "w+")
livefile.write(str(items['isLive']))
livefile.close()
return items['isLive']
return 'id not found'
# This is the loop funtion to update the ID and run the two functions above
def main_loop(self):
while True:
time.sleep(self.wait_time)
idfile = open("new_id.txt",'r')
newid = int(idfile.read())
idfile.close()
print(f"Data Loaded")
self.checkURL(newid)
print(f"Got URL")
self.checkLive(newid)