-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_manifest_and_json.py
65 lines (50 loc) · 1.5 KB
/
get_manifest_and_json.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import tempfile
import os
import json
import shutil
from utils import download_file, examine, unzip_file
unzip = True
parse = True
check_manifest_exists = True
copy_manifest = True
root = os.path.join(os.path.abspath(os.curdir), 'extensions')
def get_extension(id, download=True):
id = id.strip()
if not id:
return
dest = tempfile.mkdtemp()
os.chdir(dest)
id = id.split('/')[-1]
if (check_manifest_exists and
os.path.exists('%s/apis/%s.json' % (root, id))
):
print 'Manifest %s already exists, skipping' % id
return
destfile = os.path.join(dest, id + '.crx')
print 'Downloading...', id
try:
download_file(
destfile,
'https://clients2.google.com/service/update2/crx?response=redirect&prodversion=46.0&x=id%3D' + id + '%26uc')
except:
print '...failed'
return
if unzip:
unzip_file(destfile)
if copy_manifest:
manifest = os.path.join(dest, 'manifest.json')
os.system('cp manifest.json %s/manifests/%s.json' % (root, id))
print 'Got manifest for', id
json_file = '%s/apis/%s.json' % (root, id)
if parse:
res = examine(dest)
json.dump(res, open(json_file, 'w'))
return dest
if __name__=='__main__':
data = json.load(open('result.json', 'r'))
for line in data:
dest = get_extension(line.split('/')[-1])
if dest:
print 'Deleting temp files in...', dest
shutil.rmtree(dest)