Zuletzt aktiv 1699432948

Änderung a2ca56adc0616abc9bb0420142587fdd34252af5

EarthLiveCleanCloudinary.py Orginalformat
1# -*- coding: utf-8 -*-
2# Author: Creke
3# HomePage: http://blog.creke.net
4
5import sys
6import urllib, urllib2
7import base64
8import json
9
10URLLIB_DEBUG_LEVEL = 1
11URLLIB_TIMEOUT = 5
12
13def Dict2Uri(dic):
14 return urllib.urlencode(dic)
15
16def GenUrllibReq(url, method, api_key, api_secret, post_data=None):
17 urlreq = None
18 if post_data is None:
19 urlreq = urllib2.Request(url)
20 else:
21 urlreq = urllib2.Request(url, post_data)
22 urlreq.get_method = lambda: method
23 auth_str = base64.b64encode('%s:%s' % (api_key, api_secret))
24 urlreq.add_header("Authorization", "Basic %s" % auth_str)
25 urlreq.add_header('Cache-Control', 'no-cache')
26 return urlreq
27
28def GetApiDelUrl(cloud_name, img_type):
29 url = "https://api.cloudinary.com/v1_1/%s/resources/image/%s" % (cloud_name, img_type)
30 params = {"prefix": "http://himawari8-dl"}
31 url = url + "?" + Dict2Uri(params)
32 return url
33
34def main(argv):
35 arg_idx = 1
36 api_key = argv[arg_idx]
37 arg_idx += 1
38 api_secret = argv[arg_idx]
39 arg_idx += 1
40 cloud_name = argv[arg_idx]
41
42 while True:
43 del_url = GetApiDelUrl(cloud_name, 'fetch')
44 urlreq = GenUrllibReq(del_url, 'DELETE', api_key, api_secret)
45
46 print "==========================="
47 print "Requesting %s" % (del_url)
48 opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=URLLIB_DEBUG_LEVEL))
49 urllib_open = opener.open(urlreq, timeout=URLLIB_TIMEOUT)
50 response = urllib_open.read()
51 print "==========================="
52 print "Response:"
53 print "%s" % (response)
54 print "==========================="
55 urllib_open.close()
56 print "Done Requesting"
57
58 res_json = json.loads(response)
59 deleted_cnt = len(res_json['deleted'])
60 print "Deleted %u himawari8 pics" % (deleted_cnt)
61 print "==========================="
62 if 'next_cursor' in res_json and deleted_cnt>0:
63 print "Due to Cloudinary limits, we're starting a new round"
64 else:
65 break
66
67 return 0
68
69def PrintHelp(argv):
70 print "\t USAGE: %s [api_key] [api_secret] [cloud_name]" % (argv[0])
71
72if __name__ == '__main__':
73 if len(sys.argv) < 4:
74 PrintHelp(sys.argv)
75 exit(1)
76 print "RUNNING main"
77 main(sys.argv)
78 print "DONE main"
EarthLiveCleanCloudinary2exe.py Orginalformat
1# -*- coding: utf-8 -*-
2# Author: Creke
3# HomePage: http://blog.creke.net
4
5from distutils.core import setup
6import py2exe
7
8setup(console=['EarthLiveCleanCloudinary.py'])
Readme.md Orginalformat

《EarthLiveSharp中cloudinary的CDN图片缓存自动清理》

http://blog.creke.net/823.html

Windows编译版本下载:

https://pan.baidu.com/s/1c27fXEo 提取码:k33n