-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaltyJson.py
28 lines (27 loc) · 1.05 KB
/
SaltyJson.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
import requests
import time
class SaltyJson():
def __init__(self):
self.url = "https://www.saltybet.com/state.json"
self.session = requests.Session()
self.session.headers.update({"User-Agent": "Mozilla/5.0", "Accept":"application/json"})
def get_json(self):
try:
self.response = self.session.get(self.url)
if self.response.status_code != 200:
print(f"Received {self.response.status_code} status code, retrying... ")
time.sleep(1)
return self.get_json()
elif not self.response.text:
print("Blank response receieved, retrying...")
time.sleep(1)
return self.get_json()
else:
return self.response.json()
except requests.exceptions.ConnectionError:
time.sleep(1)
return self.get_json()
except requests.exceptions.JSONDecodeError:
print("Error Decoding JSON, retrying...")
time.sleep(1)
return self.get_json()