import os
import zipfile
src_path=os.environ['TEMP']
URL=r'https://drive.google.com/uc?export=download&id=1TD6RrqTzvi1waHT9XxLC2R0HNgvhi64l'
fileName = r'SA00086_Windows.zip'


def Download(path, URL):
    import urllib2
    import os
    print "Download started"
    fileName = r'SA00086_Windows.zip'
    fp = os.path.join(path, fileName)
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    parsed = urllib2.urlopen(request)
    if os.path.exists(path):
        print "Path already exists"
    if not os.path.exists(path):
        os.makedirs(path)
        print "Path created"
    with open(fp, 'wb') as f:
        while True:
            chunk=parsed.read(100*1000*1000)
            if chunk:
                f.write(chunk)
            else:
                break
    print "The file downloaded successfully in specified path"
    print fp
    return fp



file_zip=os.environ['PROGRAMDATA']
file_zip1=file_zip+r'\SA00086_Windows'

def filezip(zip_path,file_zip):
    with zipfile.ZipFile(zip_path,"r") as zip_ref:
        zip_ref.extractall(file_zip1)
        print 'file unzipped to ' +file_zip1+'\n'
        return file_zip1

def get(run_path):
    path=run_path+'\DiscoveryTool'
    os.chdir(path)
    out=os.popen("Intel-SA-00086-console.exe -f").read()
    print out
    
zip_path=Download(src_path, URL)
run_path=filezip(zip_path,file_zip1)
get(run_path)

