forked from trojan-gfw/igniter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a python script to download the newest golibs.aar and replace …
…the older one with it, for convenience. It is necessary to have Python modules [requests] and [lxml] installed before running this script.
- Loading branch information
1 parent
c2261a9
commit 33712ca
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# coding=utf-8 | ||
import os | ||
import requests | ||
from lxml import etree | ||
|
||
|
||
def figure_out_download_url(): | ||
html = requests.get('https://github.com/trojan-gfw/igniter-go-libs/releases/') | ||
if not html.ok: | ||
return None | ||
root = etree.HTML(html.content) | ||
first_release_entry_div = root.find('.//div[@class="release-entry"]') | ||
if first_release_entry_div is None: | ||
return None | ||
download_a = first_release_entry_div.find('.//div/div[2]/details/div/div/div[1]/a') | ||
url_sub_path = download_a.get('href') | ||
return 'https://github.com' + url_sub_path | ||
|
||
|
||
def replace_golibs(): | ||
golibs_path = './app/src/libs/golibs.aar' | ||
if os.path.exists(golibs_path): | ||
os.remove(golibs_path) | ||
os.rename('tmp.aar', golibs_path) | ||
|
||
|
||
def download_golibs(): | ||
print('Figuring out url to download golibs.aar ...') | ||
download_url = figure_out_download_url() | ||
if download_url is None: | ||
print('Failed to figure out download url') | ||
return | ||
print('Download url: {0} downloading ...'.format(download_url)) | ||
r = requests.get(url=download_url, allow_redirects=True) | ||
if not r.ok: | ||
print('Download golibs.aar failed') | ||
return | ||
with open('tmp.aar', 'wb') as output: | ||
output.write(r.content) | ||
print('Download success') | ||
replace_golibs() | ||
print('Done') | ||
|
||
|
||
def main(): | ||
download_golibs() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |