Last active
December 14, 2015 04:39
Revisions
-
psychok7 revised this gist
Feb 25, 2013 . 1 changed file with 15 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,25 +35,27 @@ def getFileName(url,openUrl): finally: r.close() def getmodelandtexture(): if os.path.exists('./models'): os.chdir("models") for files in os.listdir("."): if files.endswith("dae"): print files os.chdir("../") if os.path.exists('./images'): os.chdir("images") for files in os.listdir("."): if files.endswith("png") or files.endswith("jpg") or files.endswith("jpeg"): print files def main(): download(url,"temp_kmz") os.mkdir('./temp') os.chdir("temp") extractAll("../temp_kmz") #extracted_foldername = os.walk('.').next()[1][0] getmodelandtexture() #shutil.rmtree(extracted_foldername) main() -
psychok7 revised this gist
Feb 25, 2013 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ def getFileName(url,openUrl): r.close() def getmodelandtexture(extracted_foldername): os.chdir("models") for files in os.listdir("."): if files.endswith("dae"): print files @@ -49,7 +49,9 @@ def getmodelandtexture(extracted_foldername): def main(): download(url,"temp_kmz") os.mkdir('./temp') os.chdir("temp") extractAll("../temp_kmz") extracted_foldername = os.walk('.').next()[1][0] getmodelandtexture(extracted_foldername) #shutil.rmtree(extracted_foldername) -
psychok7 created this gist
Feb 25, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ import urllib2 ,argparse, shutil, urlparse , os , zipfile, os.path from zipfile import ZipFile as zip parser = argparse.ArgumentParser(description="Download and Unzip") parser.add_argument('url', help='The action to take (e.g. install, remove, etc.)') args = parser.parse_args() url = args.url def extractAll(zipName): z = zip(zipName) for f in z.namelist(): if f.endswith('/'): os.makedirs(f) else: z.extract(f) def download(url, fileName=None): def getFileName(url,openUrl): if 'Content-Disposition' in openUrl.info(): # If the response has Content-Disposition, try to get filename from it cd = dict(map( lambda x: x.strip().split('=') if '=' in x else (x.strip(),''), openUrl.info()['Content-Disposition'].split(';'))) if 'filename' in cd: filename = cd['filename'].strip("\"'") if filename: return filename # if no filename was found above, parse it out of the final URL. return os.path.basename(urlparse.urlsplit(openUrl.url)[2]) r = urllib2.urlopen(urllib2.Request(url)) try: fileName = fileName or getFileName(url,r) with open(fileName, 'wb') as f: shutil.copyfileobj(r,f) finally: r.close() def getmodelandtexture(extracted_foldername): os.chdir(extracted_foldername+"/models") for files in os.listdir("."): if files.endswith("dae"): print files os.chdir("../") os.chdir("images") for files in os.listdir("."): if files.endswith("png") or files.endswith("jpg") or files.endswith("jpeg"): print files def main(): download(url,"temp_kmz") extractAll("temp_kmz") extracted_foldername = os.walk('.').next()[1][0] getmodelandtexture(extracted_foldername) #shutil.rmtree(extracted_foldername) main()