Extract files from zip without keeping the structure using python ZipFile?

This opens file handles of members of the zip archive, extracts the filename and copies it to a target file (that’s how ZipFile.extract works, without taking care of subdirectories). import os import shutil import zipfile my_dir = r”D:\Download” my_zip = r”D:\Download\my_file.zip” with zipfile.ZipFile(my_zip) as zip_file: for member in zip_file.namelist(): filename = os.path.basename(member) # skip directories … Read more

python pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working

If you’re running a recent-ish version of pandas then you can use the datetime accessor dt to access the datetime components: In [6]: df[‘date’] = pd.to_datetime(df[‘date’]) df[‘year’], df[‘month’] = df[‘date’].dt.year, df[‘date’].dt.month df Out[6]: date Count year month 0 2010-06-30 525 2010 6 1 2010-07-30 136 2010 7 2 2010-08-31 125 2010 8 3 2010-09-30 84 … Read more

How to parse the Manifest.mbdb file in an iOS 4.0 iTunes Backup

Thank you, user374559 and reneD — that code and description is very helpful. My stab at some Python to parse and print out the information in a Unix ls-l like format: #!/usr/bin/env python import sys def getint(data, offset, intsize): “””Retrieve an integer (big-endian) and new offset from the current offset””” value = 0 while intsize … Read more

Read Content from Files which are inside Zip file

If you’re wondering how to get the file content from each ZipEntry it’s actually quite simple. Here’s a sample code: public static void main(String[] args) throws IOException { ZipFile zipFile = new ZipFile(“C:/test.zip”); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while(entries.hasMoreElements()){ ZipEntry entry = entries.nextElement(); InputStream stream = zipFile.getInputStream(entry); } } Once you have the InputStream … Read more

Extract images from PDF without resampling, in python?

You can use the module PyMuPDF. This outputs all images as .png files, but worked out of the box and is fast. import fitz doc = fitz.open(“file.pdf”) for i in range(len(doc)): for img in doc.getPageImageList(i): xref = img[0] pix = fitz.Pixmap(doc, xref) if pix.n < 5: # this is GRAY or RGB pix.writePNG(“p%s-%s.png” % (i, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)