In EarthLiveSharp, cloudinary's CDN image cache automatically cleans up python scripts,

Source: Internet
Author: User

In EarthLiveSharp, cloudinary's CDN image cache automatically cleans up python scripts,

It happened that there was a "EarthLiveSharp" that could be used to set the real-time Earth images of the Japanese sunflower Satellite 8 as screensaver. The official website of the earth's real-time images of sunflower Satellite 8 is: Beijing.
Cloudinary is used for CDN to reduce the burden on the sunflower 8 server and improve the acquisition success rate of the earth's real-time images. The registration configuration is described in the software.

At present, EarthLiveSharp does not clean up the cloudinary CDN image cache function, so I wrote a python, and tried to use gist management, address: https://gist.github.com/creke/c5a8a18fa41b8f5c1a0719a7e0cf4de6

At the same time, for your convenience, By the way compiled into Windows executable files, download: https://pan.baidu.com/s/1c27fXEo extraction code: k33n
For ease of retrieval, the python script source code is attached here, which can be used as an example of how to use the RESTful interface in python. The related tool functions are also convenient for reference.

EarthLiveCleanCloudinary. py

# -*- coding: utf-8 -*-# Author: Creke# HomePage: http://blog.creke.netimport sysimport urllib, urllib2import base64import jsonURLLIB_DEBUG_LEVEL = 1URLLIB_TIMEOUT = 5def Dict2Uri(dic):  return urllib.urlencode(dic)def GenUrllibReq(url, method, api_key, api_secret, post_data=None):  urlreq = None  if post_data is None:    urlreq = urllib2.Request(url)  else:    urlreq = urllib2.Request(url, post_data)  urlreq.get_method = lambda: method  auth_str = base64.b64encode('%s:%s' % (api_key, api_secret))  urlreq.add_header("Authorization", "Basic %s" % auth_str)  urlreq.add_header('Cache-Control', 'no-cache')  return urlreqdef GetApiDelUrl(cloud_name, img_type):  url = "https://api.cloudinary.com/v1_1/%s/resources/image/%s" % (cloud_name, img_type)  params = {"prefix": "http://himawari8-dl"}  url = url + "?" + Dict2Uri(params)  return urldef main(argv):  arg_idx = 1  api_key = argv[arg_idx]  arg_idx += 1  api_secret = argv[arg_idx]  arg_idx += 1  cloud_name = argv[arg_idx]  while True:    del_url = GetApiDelUrl(cloud_name, 'fetch')    urlreq = GenUrllibReq(del_url, 'DELETE', api_key, api_secret)    print "==========================="    print "Requesting %s" % (del_url)    opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=URLLIB_DEBUG_LEVEL))    urllib_open = opener.open(urlreq, timeout=URLLIB_TIMEOUT)    response = urllib_open.read()    print "==========================="    print "Response:"    print "%s" % (response)    print "==========================="    urllib_open.close()    print "Done Requesting"    res_json = json.loads(response)    deleted_cnt = len(res_json['deleted'])    print "Deleted %u himawari8 pics" % (deleted_cnt)    print "==========================="    if 'next_cursor' in res_json and deleted_cnt>0:      print "Due to Cloudinary limits, we're starting a new round"    else:      break  return 0def PrintHelp(argv):  print "\t USAGE: %s [api_key] [api_secret] [cloud_name]" % (argv[0])if __name__ == '__main__':  if len(sys.argv) < 4:    PrintHelp(sys.argv)    exit(1)  print "RUNNING main"  main(sys.argv)  print "DONE main"

EarthLiveCleanCloudinary2exe. py

# -*- coding: utf-8 -*-# Author: Creke# HomePage: http://blog.creke.netfrom distutils.core import setupimport py2exesetup(console=['EarthLiveCleanCloudinary.py'])

Download Windows compiled version:

Link: https://pan.baidu.com/s/1skADZeH password: rdgb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.