#!/usr/bin/env python3 """Writing data to a new archive using an alternate name. """ #end_pymotw_header from zipfile_infolist import print_info import zipfile with zipfile.ZipFile('write_arcname.zip', mode='w') as zf: zf.write('README.txt', arcname='NOT_README.txt') print_info('write_arcname.zip')
#!/usr/bin/env python # -*- coding: utf-8 -*- """Writing data to a new archive with writestr(). """ import time import zipfile from zipfile_infolist import print_info msg = 'This data did not exist in a file.' with zipfile.ZipFile( 'writestr_zipinfo.zip', mode='w', ) as zf: info = zipfile.ZipInfo( 'from_string.txt', date_time=time.localtime(time.time()), ) info.compress_type = zipfile.ZIP_DEFLATED info.comment = 'Remarks go here' info.create_system = 0 zf.writestr(info, msg) print_info('writestr_zipinfo.zip')
# zipfile_write_compression.py from zipfile_infolist import print_info import zipfile try: import zlib compression = zipfile.ZIP_DEFLATED except (ImportError, AttributeError): compression = zipfile.ZIP_STORED modes = { zipfile.ZIP_DEFLATED: 'compresso', zipfile.ZIP_STORED: 'conservato', } print('creazione archivio') with zipfile.ZipFile('write_compression.zip', mode='w') as zf: mode_name = modes[compression] print('aggiungo LEGGIMI.txt con modalità compressione', mode_name) zf.write('LEGGIMI.txt', compress_type=compression) print() print_info('write_compression.zip')
__author__ = 'rApeNB' # -*- coding: utf-8 -*- from zipfile_infolist import print_info import zipfile try: import zlib compression = zipfile.ZIP_DEFLATED except: compression = zipfile.ZIP_STORED modes = {zipfile.ZIP_DEFLATED: 'deflated', zipfile.ZIP_STORED: 'stored'} print 'creating archive' zf = zipfile.ZipFile('zipfile_write_compression.zip', mode='w') try: print 'adding README with compression mode', modes[compression] zf.write('README', compress_type=compression) finally: print 'closing' zf.close() print print_info('zipfile_write_compression.zip')
# # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN # NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Writing data to a new archive. """ __version__ = "$Id: zipfile_write.py 1882 2009-01-04 15:38:33Z dhellmann $" from zipfile_infolist import print_info import zipfile print 'creating archive' zf = zipfile.ZipFile('zipfile_write.zip', mode='w') try: print 'adding README.txt' zf.write('README.txt') finally: print 'closing' zf.close() print print_info('zipfile_write.zip')
#!/usr/bin/env python # -*- coding: utf-8 -*- """Writing data to a new archive. """ from zipfile_infolist import print_info import zipfile print 'creating archive' with zipfile.ZipFile('write.zip', mode='w') as zf: print 'adding README.txt' zf.write('README.txt') print print_info('write.zip')
#!/usr/bin/env python # -*- coding: UTF-8 -*- from zipfile_infolist import print_info import zipfile zf = zipfile.ZipFile('zipfile_write_arcname.zip', mode='w') try: zf.write('LEGGIMI.txt', arcname='NON_LEGGIMI.txt') finally: zf.close() print_info('zipfile_write_arcname.zip')
#!/usr/bin/env python # -*- coding: utf-8 -*- """Writing data to a new archive with writestr(). """ from zipfile_infolist import print_info import zipfile msg = 'This data did not exist in a file.' with zipfile.ZipFile( 'writestr.zip', mode='w', compression=zipfile.ZIP_DEFLATED, ) as zf: zf.writestr('from_string.txt', msg) print_info('writestr.zip') with zipfile.ZipFile('writestr.zip', 'r') as zf: print zf.read('from_string.txt')
#!/usr/bin/env python """Writing data to a new archive with writestr(). """ #end_pymotw_header import time import zipfile from zipfile_infolist import print_info msg = 'This data did not exist in a file.' with zipfile.ZipFile('writestr_zipinfo.zip', mode='w', ) as zf: info = zipfile.ZipInfo('from_string.txt', date_time=time.localtime(time.time()), ) info.compress_type=zipfile.ZIP_DEFLATED info.comment='Remarks go here' info.create_system=0 zf.writestr(info, msg) print_info('writestr_zipinfo.zip')
# zipfile_write_arcname.py from zipfile_infolist import print_info import zipfile with zipfile.ZipFile('write_arcname.zip', mode='w') as zf: zf.write('LEGGIMI.txt', arcname='NON_LEGGIMI.txt') print_info('write_arcname.zip')
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Writing data to a new archive with writestr(). """ __version__ = "$Id: zipfile_writestr_zipinfo.py 1882 2009-01-04 15:38:33Z dhellmann $" import time import zipfile from zipfile_infolist import print_info msg = 'This data did not exist in a file before being added to the ZIP file' zf = zipfile.ZipFile('zipfile_writestr_zipinfo.zip', mode='w', ) try: info = zipfile.ZipInfo('from_string.txt', date_time=time.localtime(time.time()), ) info.compress_type=zipfile.ZIP_DEFLATED info.comment='Remarks go here' info.create_system=0 zf.writestr(info, msg) finally: zf.close() print_info('zipfile_writestr_zipinfo.zip')
# granted, provided that the above copyright notice appear in all # copies and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of Doug # Hellmann not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. # # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN # NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Writing data to a new archive using an alternate name. """ __version__ = "$Id: zipfile_write_arcname.py 1882 2009-01-04 15:38:33Z dhellmann $" from zipfile_infolist import print_info import zipfile zf = zipfile.ZipFile('zipfile_write_arcname.zip', mode='w') try: zf.write('README.txt', arcname='NOT_README.txt') finally: zf.close() print_info('zipfile_write_arcname.zip')
"""Writing data to a new archive. """ __version__ = "$Id: zipfile_write_compression.py 1882 2009-01-04 15:38:33Z dhellmann $" from zipfile_infolist import print_info import zipfile try: import zlib compression = zipfile.ZIP_DEFLATED except: compression = zipfile.ZIP_STORED modes = { zipfile.ZIP_DEFLATED: 'deflated', zipfile.ZIP_STORED: 'stored', } print 'creating archive' zf = zipfile.ZipFile('zipfile_write_compression.zip', mode='w') try: print 'adding README.txt with compression mode', modes[compression] zf.write('README.txt', compress_type=compression) finally: print 'closing' zf.close() print print_info('zipfile_write_compression.zip')
#!/usr/bin/env python # -*- coding: utf-8 -*- """Writing data to a new archive with writestr(). """ from zipfile_infolist import print_info import zipfile msg = 'This data did not exist in a file.' with zipfile.ZipFile('writestr.zip', mode='w', compression=zipfile.ZIP_DEFLATED, ) as zf: zf.writestr('from_string.txt', msg) print_info('writestr.zip') with zipfile.ZipFile('writestr.zip', 'r') as zf: print zf.read('from_string.txt')
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Writing data to a new archive with writestr(). """ __version__ = "$Id: zipfile_writestr.py 1882 2009-01-04 15:38:33Z dhellmann $" from zipfile_infolist import print_info import zipfile msg = 'This data did not exist in a file before being added to the ZIP file' zf = zipfile.ZipFile( 'zipfile_writestr.zip', mode='w', compression=zipfile.ZIP_DEFLATED, ) try: zf.writestr('from_string.txt', msg) finally: zf.close() print_info('zipfile_writestr.zip') zf = zipfile.ZipFile('zipfile_writestr.zip', 'r') print zf.read('from_string.txt')
def zip(): objectId = request.form['objectId'] modes = { zipfile.ZIP_DEFLATED: 'deflated', zipfile.ZIP_STORED: 'stored', } connection = httplib.HTTPSConnection('api.parse.com', 443) params = urllib.urlencode({"where":json.dumps({ "$relatedTo": { "object": { "__type": "Pointer", "className": "Patient", "objectId": objectId }, "key": "EyeImages" } })}) connection.connect() connection.request('GET', '/1/classes/EyeImage?%s' % params, '', { "X-Parse-Application-Id": "kj1p0NcAg3KwmTebw5N4MtbZCkx2WASRWSxTWuto", "X-Parse-REST-API-Key": "YJD1kZut532YaYB5mnZRIgAu3M4ttbEgtCwVUsTt" }) result = json.loads(connection.getresponse().read()) eyeImageArray = result["results"] connection.request('GET', '/1/classes/Patient/%s' %objectId, '', { "X-Parse-Application-Id": "kj1p0NcAg3KwmTebw5N4MtbZCkx2WASRWSxTWuto", "X-Parse-REST-API-Key": "YJD1kZut532YaYB5mnZRIgAu3M4ttbEgtCwVUsTt" }) patientInfo = json.loads(connection.getresponse().read()) zipName = "" if "cellscope" in patientInfo: zipName += str(patientInfo["cellscope"]) if "examID" in patientInfo: zipName += "-"+str(patientInfo["examID"]) if "patientID" in patientInfo: zipName += "-"+str(patientInfo["patientID"]) dateString = patientInfo["examDate"]["iso"] date = dateutil.parser.parse(dateString) dateFormattedString = date.strftime("%Y%m%d") if dateFormattedString: zipName += "-"+dateFormattedString #If correct Zip name already exists then just return the URL! file_path = './static/'+zipName+'.zip' filename = zipName+'.zip' print file_path if os.path.exists(file_path): zipURL = "https://cellscope4-8080.terminal.com/"+zipName+'.zip' return json.dumps({"zipName": zipURL}) fileName = zipName fileNamesArray=[] filerDownloader = urllib.URLopener() for index, ei in enumerate(eyeImageArray): if "Eye" in ei: fileName += "-" + ei["Eye"] if "Position" in ei: fileName += "-" + ei["Position"] fileName += "-"+ str(index) + ".jpg" fileNamesArray.append(fileName) filerDownloader.retrieve(ei["Image"]["url"], fileName) fileName = zipName print "index "+str(index) print index zipName += ".zip" print 'creating archive' zf = zipfile.ZipFile(zipName, mode='w') try: for i in range(0,index+1): print "i "+str(i) print 'adding file%s with compression mode' %i, modes[compression] zf.write(fileNamesArray[i], compress_type=compression) finally: print 'closing' zf.close() for file in fileNamesArray: os.remove(file) print print_info(zipName) print "Printing zipName" print zipName zipURL = "https://cellscope4-8080.terminal.com/"+zipName sourcePath = "./"+zipName destinationPath = "./static/"+zipName os.rename(sourcePath,destinationPath) return json.dumps({"zipName": zipURL})
# """Writing data to a new archive. """ __version__ = "$Id: zipfile_append.py 1882 2009-01-04 15:38:33Z dhellmann $" from zipfile_infolist import print_info import zipfile print 'creating archive' zf = zipfile.ZipFile('zipfile_append.zip', mode='w') try: zf.write('README.txt') finally: zf.close() print print_info('zipfile_append.zip') print 'appending to the archive' zf = zipfile.ZipFile('zipfile_append.zip', mode='a') try: zf.write('README.txt', arcname='README2.txt') finally: zf.close() print print_info('zipfile_append.zip')
from zipfile_infolist import print_info import zipfile print('creating archive') with zipfile.ZipFile('append.zip', mode='w') as zf: zf.write('README.txt') print() print_info('append.zip') print('appending to the archive') with zipfile.ZipFile('append.zip', mode='a') as zf: zf.write('README.txt', arcname='README2.txt') print() print_info('append.zip')
#!/usr/bin/env python3 """Writing data to a new archive. """ #end_pymotw_header from zipfile_infolist import print_info import zipfile try: import zlib compression = zipfile.ZIP_DEFLATED except: compression = zipfile.ZIP_STORED modes = { zipfile.ZIP_DEFLATED: 'deflated', zipfile.ZIP_STORED: 'stored', } print('creating archive') with zipfile.ZipFile('write_compression.zip', mode='w') as zf: mode_name = modes[compression] print('adding README.txt with compression mode', mode_name) zf.write('README.txt', compress_type=compression) print() print_info('write_compression.zip')
"""Writing data to a new archive. """ __version__ = "$Id$" # end_pymotw_header from zipfile_infolist import print_info import zipfile print "creating archive" zf = zipfile.ZipFile("zipfile_append.zip", mode="w") try: zf.write("README.txt") finally: zf.close() print print_info("zipfile_append.zip") print "appending to the archive" zf = zipfile.ZipFile("zipfile_append.zip", mode="a") try: zf.write("README.txt", arcname="README2.txt") finally: zf.close() print print_info("zipfile_append.zip")