Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pack
- import requests
- from requests.auth import HTTPBasicAuth
- from tqdm import tqdm
- import os
- import sys
- user = 'santaf@gmail.com'
- password = 'Pqntslc0$'
- def doDownload(url, file_name):
- r = requests.get(url, auth=HTTPBasicAuth(user, password))
- so_far = 0
- total = int(r.headers['Content-Length'])
- # print "# using chunk size =", chunk_size
- try:
- with tqdm(total=total) as pbar:
- with open(file_name, 'wb') as fd:
- for chunk in r.iter_content(chunk_size=1):
- so_far += len(chunk)
- fd.write(chunk)
- pbar.update(len(chunk))
- except Exception as e:
- pass
- finally:
- if so_far == total:
- downloaded = True
- return True
- else:
- if os.path.exists(file_name):
- print '# did not download file entirely, will delete', file_name
- os.remove(file_name)
- return False
- if len(sys.argv) < 3:
- print "use: script <TAG> <DEST>"
- sys.exit(-1)
- # get tag
- TAG = sys.argv[1]
- DEST = sys.argv[2]
- # log
- print "# using tag", TAG
- URL_BASE="https://bitbucket.org/francosantapy"
- REPO="api_set"
- REMOTE_FILE = URL_BASE + "/" + REPO + "/get/" + TAG + ".zip"
- print REMOTE_FILE
- file_name = '' + TAG + '.zip'
- ret = doDownload(REMOTE_FILE, file_name);
- if ret is False:
- print "download failed"
- sys.exit(-1)
- import zipfile
- print "# uncompressing", file_name
- zip_ref = zipfile.ZipFile(file_name, 'r')
- zip_ref.extractall("./vamos_rafa")
- zip_ref.close()
- print "# deleting", file_name
- os.remove(file_name)
- folder_name = None
- for f in os.listdir('./vamos_rafa'):
- import re
- match = re.search('api_set', f)
- if match is not None and match.group(0) == 'api_set':
- folder_name = './vamos_rafa/' + f
- print "# using", folder_name
- break
- if folder_name is None:
- print "internal error, could not find folder"
- sys.exit(-1)
- print "# deleting", DEST
- try:
- os.remove(DEST+"/api_set")
- except OSError as e:
- pass
- print "# copy all new data to", DEST
- import shutil
- shutil.copytree(folder_name, DEST + "/api_set")
- # echo "Downloading remote $REMOTE_FILE"
- # curl --user $USER:$PASS $REMOTE_FILE -o $TAG.tar.gz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement