-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (33 loc) · 999 Bytes
/
main.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
import requests
import os
from dotenv import load_dotenv
load_dotenv()
API_ENDPOINT = os.environ['API_ENDPOINT']
API_KEY = os.environ['API_KEY']
HEADERS = {
'X-MICROCMS-API-KEY': API_KEY
}
def get_media_list():
url = f"{API_ENDPOINT}"
params = {
'imageOnly': 'true', # 画像のみ取得するパラメータ
'limit': 100 # 最大100件取得
}
response = requests.get(url, headers=HEADERS, params=params)
response.raise_for_status()
return response.json()
def delete_media(media_url):
delete_url = f"{API_ENDPOINT}"
params = {
'url': media_url
}
response = requests.delete(delete_url, headers=HEADERS, params=params)
response.raise_for_status()
print(f"Deleted media with URL: {media_url}")
def main():
media_data = get_media_list()
for media in media_data['media']:
media_url = media['url'] # メディアのURLを取得
delete_media(media_url)
if __name__ == '__main__':
main()