1. is equally likely events
2. is mutually exclusive events
3. is find complement(A) event
4. is union of events (A or B or both)
5. is intersection of events (A and B)
events and probability
python to download zipfile and unzip
#This simple script can use for download zip file from any url and unzip data. you need to have wget utility to download file.
import sys
import time
from urllib.request import FancyURLopener
import os
from datetime import datetime,date
import calendar
from os import path
import zipfile
def unzip(zf):
print("================unziping"+zf+"================")
zip = zipfile.ZipFile(zf,"r")
zip.extractall()
def runsystemcmd(cmd):
print("Cmd : " + cmd)
os.system(cmd)
class TestOpener(FancyURLopener, object):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11',
def downloadFile(url):
starttime = time.time()
testurlopen = TestOpener();
response = testurlopen.open(url)
meta = response.info()
logging.error(meta)
urlcontentlen = meta["Content-Length"]
if urlcontentlen==None:
urlcontentlen = 0
outfile = url.split('/')[-1]
f = open(outfile, "wb")
read_bytes = response.read(1024*10)
while read_bytes:
f.write(read_bytes)
read_bytes = response.read(1024*10)
f.close()
print("Elapsed Time: " +str(time.time() - starttime))
def unzipfile(zf):
if(os.path.exists(zf)):
unzip(zf)
os.remove(zf)
else:
print("File not exist " + zipfile)
if __name__ == '__main__':
url="put the zipfile url here"
downloadFile(url)
zf = url.split('/')[-1]
unzipfile(zf)
print("Finishing current downloads")
Subscribe to:
Posts (Atom)