-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagic_item_delete.py
52 lines (40 loc) · 1.46 KB
/
magic_item_delete.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
# Import for data-typing
from google.auth.transport.requests import AuthorizedSession
# Built-in libraries
import json
# Created modules
import connection_error
# ----------------------------------------------------------------------------------
def main(
auth_session: AuthorizedSession,
index_json: dict[str,str],
index_json_dir: str,
full_URL: str,
file_name: str,
) -> None:
"""
Main function to delete JSONs from the database
Args:
auth_session (AuthorizedSession): Authenticated request object
index_json (dict): Dictionary of index.json
index_json_dir (str): Directory of index.json
full_URL (str): Entire URL of target file
file_name (str): Name of file to remove from database
"""
# Sends response to the server to delete the json
response = auth_session.delete(full_URL)
# If the database says it was a good request
if response.status_code == 200:
# Deletes file from dictionary
del index_json[file_name]
# Overwrites file
with open(index_json_dir, "w", encoding="utf-8") as f:
json.dump(index_json_dir, f, indent=4, sort_keys=True)
print(f"{file_name} successfully delete!")
else:
# Runs through error code lookup
connection_error.main(response.status_code, file_name)
if __name__ == "__main__":
print(
"This code is not meant to be executed directly, please execute main.py instead."
)