Last active
September 24, 2015 09:29
-
-
Save vuryleo/274e8d972919bc66e94a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# $File: downloadIITC.py | |
# $Date: Thu Sep 24 11:28:10 2015 +0200 | |
# $Author: Xiaoyu Liu <i[at]vuryleo[dot]com> | |
import requests | |
from bs4 import BeautifulSoup | |
import os | |
baseURL = 'https://secure.jonatkins.com/iitc/release/' | |
folder = 'scripts' | |
plugins = 'plugins' | |
def download_file(url, folder='.'): | |
print("downloading file {}".format(url)) | |
local_filename = url.split('/')[-1] | |
r = requests.get(url, stream=True) | |
with open(os.path.join(folder, local_filename), 'wb') as f: | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: # filter out keep-alive new chunks | |
f.write(chunk) | |
f.flush() | |
return local_filename | |
def download_js(url, folder='.'): | |
print("downloading js in {}".format(url)) | |
r = requests.get(url) | |
doc = BeautifulSoup(r.text, 'html.parser') | |
links = doc.find_all('a') | |
for l in links: | |
if ".js" == l.get_text()[-3:]: | |
download_file("{}{}".format(url, l.get('href')), folder) | |
if __name__ == '__main__': | |
try: | |
os.mkdir(folder) | |
except: | |
pass | |
try: | |
os.mkdir(os.path.join(folder, plugins)) | |
except: | |
pass | |
download_js(baseURL, folder) | |
download_js("{}{}/".format(baseURL, plugins), os.path.join(folder, plugins)) | |
# vim: foldmethod=marker | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment