forked from tzutalin/android-ndk-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatetable.py
executable file
·39 lines (31 loc) · 1.11 KB
/
updatetable.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
#!/usr/bin/env python
__author__ = 'TzuTaLin'
import urllib2
import os
from bs4 import BeautifulSoup
import json
def getSoup(url):
return BeautifulSoup(urllib2.urlopen(url).read().decode('utf-8'), 'html.parser')
def appendToTable(title, link):
json_data = None
jsonFile='table.json'
with open(jsonFile) as json_file:
json_data = json.load(json_file)
if json_data is not None:
print "Append a new ndk download_link if not existed:" + title
json_data[title] = link
with open(jsonFile, mode='w') as f:
json.dump(json_data, f, indent=4, sort_keys=True)
if __name__=='__main__':
print 'Getting the latest NDK version'
soup = getSoup('https://developer.android.com/ndk/downloads/index.html')
all_td = soup.findAll('td')
download_os = ['linux', 'windows', 'darwin']
for os_td in download_os:
for each_td in all_td:
if os_td in str(each_td):
os_td = each_td
break
download_link=os_td.a.get('href')
title=os_td.a.getText().split('.', 1)[0]
appendToTable(title, download_link)