-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_status.py
More file actions
44 lines (40 loc) · 1.75 KB
/
memory_status.py
File metadata and controls
44 lines (40 loc) · 1.75 KB
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
import json
import requests
from geo import path
# Получение токена и id навыка из json файла
file = open(path('token.json'), 'r', encoding="utf-8")
tokens = json.loads(file.read())
file.close()
token = tokens['token']
skill_id = tokens['skill_id']
# Получение данных об использованной памяти
url = "https://dialogs.yandex.net/api/v1/status"
response = requests.get(url, headers={'Authorization': f'OAuth {token}'})
info = response.json()['images']['quota']
# Отображение её в процентах
total = int(info['total'])
used = int(info['used'])
used_per = round(used / total * 100, 1)
print(f"Использовано {str(used_per)}% памяти.")
# Спрашивает пользователя о дальнейших действиях
print("Удалить все изображения? y/n")
flag = False
while not flag:
ans = str(input())
if ans == 'y':
flag = True
# Получение списка изображений
url = f'https://dialogs.yandex.net/api/v1/skills/{skill_id}/images'
images_id = requests.get(url, headers={'Authorization': f'OAuth {token}'}).json()['images']
for image in images_id:
# Удаление изображения
try:
url = f'https://dialogs.yandex.net/api/v1/skills/{skill_id}/images/' + str(image['id'])
res = requests.delete(url, headers={'Authorization': f'OAuth {token}'}).json()
print(str(image['id']) + ' delete status: ' + res['result'])
except Exception:
print('error')
print('Удаление завершено')
elif ans == 'n':
flag = True
print('Сеанс окончен')