add the scripts
This commit is contained in:
parent
26501f220e
commit
fcecf1a04b
12 changed files with 490 additions and 0 deletions
42
cloakcatcher/fetch_data.py
Executable file
42
cloakcatcher/fetch_data.py
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
# fetch_data.py
|
||||
# Made by user333_
|
||||
# Meant to be included with main.py
|
||||
|
||||
from requests import post, get
|
||||
from sys import exit
|
||||
|
||||
def fetch_data(url: str, json: dict, request_type: str) -> dict:
|
||||
|
||||
if request_type == "post":
|
||||
|
||||
try:
|
||||
|
||||
data = post(url = url, json = json)
|
||||
return data.json()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
NetworkError(e)
|
||||
|
||||
if request_type == "get":
|
||||
|
||||
try:
|
||||
|
||||
data = get(url = url)
|
||||
return data.json()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
NetworkError(e)
|
||||
|
||||
def NetworkError(e: str):
|
||||
|
||||
raise Exception(f"""[ERROR] Error 1: An exception occured while attempting to fetch data.
|
||||
This could be a result of an invalid request, no network connection, or the server is offline.
|
||||
Exception: {e}""")
|
||||
exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
raise Exception("[ERROR] You ran the wrong script, run main.py instead.")
|
||||
exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue