-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_query.py
56 lines (48 loc) · 1.38 KB
/
fetch_query.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
"""
Fetch customer query
"""
import json
import requests
from requests.exceptions import ConnectionError
class FetchQuery:
def __init__(self):
self._API_KEY = "rjJs9xF6YjDDmaGrGIQWGCHKcVDaV7GejhCjIqPuuDv2MS0fAW" # Shoppy API key
def connect(self, id):
"""
Make http request for query
id: str - ID of the query
"""
headers = {
"User-Agent": "QueryFetch",
"Authorization": self._API_KEY
}
url = "https://shoppy.gg/api/v1/queries/"
try:
req = requests.get(f"{url}{id}", headers=headers)
except ConnectionError:
result = {
"status": False,
"message": "<span style='color: red;'>Connection Error</span>"
}
return result
print(req.text)
queries = json.loads(req.text)
result = {
"status": True,
"type": "QUERY ID",
"id": queries['id'],
"email": queries['email'],
"message": queries["message"]
}
return result
# If id isn't found
result = {
"status": False,
"message": f"query ID <span style='color: red;'>{id}</span> not found"
}
return result
def main():
fetch_query = FetchQuery()
fetch_query.connect("vdYfTkp")
if __name__ == "__main__":
main()