forked from raph-son/shoppy_query_fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_query.py
58 lines (49 loc) · 1.43 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
57
58
"""
Fetch customer query
"""
import json
import requests
from requests.exceptions import ConnectionError
class FetchQuery:
def __init__(self):
self._API_KEY = "" # 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(url, headers=headers)
except ConnectionError:
result = {
"status": False,
"message": "<span style='color: red;'>Connection Error</span>"
}
return result
result = json.loads(req.text)
for queries in result:
if queries['id'] == id:
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()