-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear_image.py
46 lines (40 loc) · 1.46 KB
/
clear_image.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
import requests
import json
import os
def get_token():
headers = {
'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/',
}
params = (
('grant_type', 'client_credential'),
('appid', os.environ.get('wechat_app_id')),
('secret', os.environ.get('wechat_app_secret')),
)
response = requests.get('https://api.weixin.qq.com/cgi-bin/token', headers=headers, params=params)
return response.json()['access_token']
def delete_image():
token = get_token()
headers = {
'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/',
'Content-Type': 'application/json',
}
params = (
('access_token', token),
)
data = { "type":'image', "offset":'0', "count":'20' }
response = requests.post('https://api.weixin.qq.com/cgi-bin/material/batchget_material', headers=headers, params=params, json=data)
response_all_image = requests.get('https://api.weixin.qq.com/cgi-bin/material/get_materialcount', headers=headers, params=params)
print('总素材数:',response_all_image.json())
for media_id in response.json()['item']:
print(media_id['name'])
data = { 'media_id':media_id['media_id']}
response = requests.post('https://api.weixin.qq.com/cgi-bin/material/del_material', headers=headers, params=params,json=data)
#每次最多列20张,需要多次循环删除20*n张
i = 0
while True:
if i < 20:
delete_image()
i +=1
else:
print("finshed")
break