-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibraryManagement.py
51 lines (42 loc) · 1.42 KB
/
LibraryManagement.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
import requests
import json
import sys
import settings
admin_api_keys = settings.admin_api
api_keys = {}
api_keys['Admin']=admin_api_keys
payload={}
base_url = settings.base_url
def main():
for api_key, api_value in api_keys.items():
api = "libraries"
url = base_url + api
libraries = callimmich(url, api_value, "GET", payload)
scanlib(api_value,libraries)
sendtg(f"All Libraries Scanned")
def sendtg(message):
TOKEN = settings.tg_token
chat_id = settings.chat_id
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}"
print(requests.get(url).json()) # this sends the message
def scanlib(api_value,libraries):
for library in libraries:
id = library['id']
name = library['name']
api = f"libraries/{id}/scan"
url = base_url + api
scan_library = callimmich(url,api_value, "POST", payload)
print(name,api_value,scan_library, url,api_value, payload)
def callimmich(url,api_value, method, payload):
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-api-key': api_value
}
response = requests.request(method, url, headers=headers, data=payload)
if method == "GET":
return response.json()
else:
return response.status_code
if __name__ == '__main__':
main()