-
Notifications
You must be signed in to change notification settings - Fork 8
/
cacheclear.py
38 lines (29 loc) · 1.01 KB
/
cacheclear.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
import sys
sys.path.append('/home/ansibler/thunderbird-website/')
import CloudFlare
import os
import settings
# these need to be in the environment
apikey = os.environ['CF_KEY']
email = os.environ['CF_EMAIL']
zone = os.environ['CF_ZONE_IDENTIFIER']
# Cloudflare has a 30-item limit on API cache purges now.
def chunks(lst, n):
for i in xrange(0, len(lst), n):
yield lst[i:i + n]
# Build URL list
tb = 'https://www.thunderbird.net/'
urls = []
for lang in settings.PROD_LANGUAGES:
urls.append(tb+lang+'/')
urls.append('https://www.thunderbird.net/en-US/thunderbird/releases/')
urls.append('https://www.thunderbird.net/en-US/thunderbird/all/')
urls.append('https://www.thunderbird.net/media/js/common-bundle.js')
cf = CloudFlare.CloudFlare(email=email, token=apikey)
lists = chunks(urls, 30) # Split into 30-item requests.
for url_list in lists:
# Put it in the format the API expects.
api_req = {'files': url_list}
a = cf.zones.purge_cache.post(zone, data=api_req)
print a
print "Completed."