doracoin ha revisionato questo gist . Vai alla revisione
3 files changed, 93 insertions
EarthLiveCleanCloudinary.py(file creato)
| @@ -0,0 +1,78 @@ | |||
| 1 | + | # -*- coding: utf-8 -*- | |
| 2 | + | # Author: Creke | |
| 3 | + | # HomePage: http://blog.creke.net | |
| 4 | + | ||
| 5 | + | import sys | |
| 6 | + | import urllib, urllib2 | |
| 7 | + | import base64 | |
| 8 | + | import json | |
| 9 | + | ||
| 10 | + | URLLIB_DEBUG_LEVEL = 1 | |
| 11 | + | URLLIB_TIMEOUT = 5 | |
| 12 | + | ||
| 13 | + | def Dict2Uri(dic): | |
| 14 | + | return urllib.urlencode(dic) | |
| 15 | + | ||
| 16 | + | def 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 | + | ||
| 28 | + | def 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 | + | ||
| 34 | + | def 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 | + | ||
| 69 | + | def PrintHelp(argv): | |
| 70 | + | print "\t USAGE: %s [api_key] [api_secret] [cloud_name]" % (argv[0]) | |
| 71 | + | ||
| 72 | + | if __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(file creato)
| @@ -0,0 +1,8 @@ | |||
| 1 | + | # -*- coding: utf-8 -*- | |
| 2 | + | # Author: Creke | |
| 3 | + | # HomePage: http://blog.creke.net | |
| 4 | + | ||
| 5 | + | from distutils.core import setup | |
| 6 | + | import py2exe | |
| 7 | + | ||
| 8 | + | setup(console=['EarthLiveCleanCloudinary.py']) | |
Readme.md(file creato)
| @@ -0,0 +1,7 @@ | |||
| 1 | + | 《EarthLiveSharp中cloudinary的CDN图片缓存自动清理》 | |
| 2 | + | ||
| 3 | + | http://blog.creke.net/823.html | |
| 4 | + | ||
| 5 | + | Windows编译版本下载: | |
| 6 | + | ||
| 7 | + | https://pan.baidu.com/s/1c27fXEo 提取码:k33n | |