#!/usr/bin/env python
# coding: utf-8

# In[ ]:


enviroment_variable=['FRGEN','FRCDS','DKGEN','UKGEN','MAGEN','ESDCS']

links=['http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/2001220048/AcroRdrDC2001220048_fr_FR.exe',
      'http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/2001220048/AcroRdrDC2001220048_fr_FR.exe',
      'http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/2001220048/AcroRdrDC2001220048_en_US.exe',
      'http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/2001220048/AcroRdrDC2001220048_en_US.exe',
      'http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/2001220048/AcroRdrDC2001220048_fr_FR.exe',
      'http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/2001220048/AcroRdrDC2001220048_es_ES.exe']

import os
from subprocess import PIPE,Popen
class my_dictionary(dict): 
    def __init__(self): 
        self = dict() 
    def add(self, key, value): 
        self[key] = value 
values= my_dictionary()         
for i,j in zip(enviroment_variable,links):
     values.add(i,j)
print values



def location():
    res=Popen('SET ComputerLocation',stdout=PIPE,stderr=PIPE,shell=True)
    out,err=res.communicate()
    if err:
        return err
    else:
        var=out.split('=')[-1]
        #print out
        #var='UKGEN'
        return values[var]


url=location()
def Download(URL):
    import urllib2
    import os
    import time
    print "Download started"
    fileName =URL.split('/')[-1]
    src_path=os.environ['ProgramData']
    fp = os.path.join(src_path, fileName)
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    parsed = urllib2.urlopen(request)
    if os.path.exists(src_path):
        print "Path already exists"
    if not os.path.exists(src_path):
        os.makedirs(src_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"+fp
    try:
        print'Downloaded Application %s Installation Started'%fileName
        dircty=os.environ['PROGRAMFILES']
        os.popen(fp+" /S INSTALLDIR="+dircty).read()
        time.sleep(100)
        print '%s Application Successfully Installed'%fileName
    except:
        return 'No : '+fp+' is exist'


Download(url)


