Skip to content

Commit

Permalink
Create a python script to download the newest golibs.aar and replace …
Browse files Browse the repository at this point in the history
…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
TchaikovDriver authored and wongsyrone committed Apr 16, 2021
1 parent c2261a9 commit 33712ca
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pull_golibs.py
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()

0 comments on commit 33712ca

Please sign in to comment.