Download System using Requests - Printable Version

+- Sinisterly (
+-- Forum: Coding (
+--- Forum: Python (
+--- Thread: Download System using Requests (/Thread-Download-System-using-Requests)

Download System using Requests - Inori - 12-16-2015

Using the super popular python module requests, which makes http, POST, and RESTful requests and traversal humanly possible (screw you, urllib2), you can 'get' a raw file from the url source and download it chunk by chunk as you would with raw html to use requests normally.

This project is fairly bug-free, save for the download bar not completing on some operations, but other than that, it's fully functional and works pretty well.

(Full code on github)

Spoiler: source code (used to execute code from the parent directory):
from internals import *


def main():
    a=raw_input('~> ').split()
    if a[0] in cmds:
        if a[0]=='e':
        elif a[0]=='q':
            if len(a)<2:
                print '!> No file supplied'
                if x.status_code==200:
                    for c in x: i+=1
                    print'#> %s returned status code %s'%(uri.split('/')[2],r.status_code)
        elif a[0]=='r':
            while len(q)>0:
            print '\n#> download(s) complete.'
        elif a[0]=='v':
            for i in range(len(q)):
                print '#%s: %s,%s'%(i+1,q[i][-1][1],q[i][-1][2])

        print '!> %s is not a valid command'%a[0]

if tests():
import requests
from sys import stdout
from os import remove,makedirs,path
from threading import Thread

def tests():
    if not path.exists('./PyDownload/Downloads'):
        return True
    except requests.exceptions.ConnectionError:
        print '#> Currently disconnected, try again later.'
        return False

def prog(p):
    text="\r#> [{0}] {1}% ".format("*"*block+" "*(30-block),str(p*100)[:5])

def download(u,s,r,i,a,n=0):
        print '!> file %s already exists'%u
    except IOError:
            print '#> downloading file %s from %s'%(u.split('/')[-1],s)
            with open('./PyDownload/Downloads/%s'%((u.split('/')[-1])+'.html'*('.' not in u.split('/')[-1]),a[-1])[len(a)>2],'wb') as f:
                for c in r.iter_content(chunk_size=512):
        except KeyboardInterrupt:
            print '\n!> download canceled.'

def runq(q):
    for i in q: