def do_zipf(self, inp): file_list = [] for file in os.listdir(os.getcwd()): if os.path.isfile(os.path.join(os.getcwd(), file)) and not file.startswith('.'): file_list.append(file) questions = [ inquirer.Checkbox( 'files', message= "Select Files to Zip (use Spacebar to select and Enter to confirm)", choices=file_list) ] answers = inquirer.prompt(questions) print(answers['files']) try: with ZipFile(os.path.basename(os.getcwd()) + '.zip', 'w') as zip: for i in range(len(answers['files'])): print(answers['files'][i]) zip.write(answers['files'][i]) print('All file(s) zipped successfully!') except PermissionError: print("Requires Root Access") args = ['sudo', sys.executable] + sys.argv + [os.environ] os.execlpe('sudo', *args)
def do_zipd(self, inp): file_list = [] for file in os.listdir(os.getcwd()): if not os.path.isfile(os.path.join( os.getcwd(), file)) and not file.startswith('.'): file_list.append(file) questions = [ inquirer.Checkbox( 'files', message= "Select Folders to Zip (use Spacebar to select and Enter to confirm)", choices=file_list) ] answers = inquirer.prompt(questions) try: zipf = ZipFile("MyShellPy.zip", 'w') for dir in answers['files']: for root, dirs, files in os.walk(dir): for file in files: zipf.write( os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(dir, '..'))) zipf.close() print('All file(s) zipped successfully!') except PermissionError: print("Requires Root Access") args = ['sudo', sys.executable] + sys.argv + [os.environ] os.execlpe('sudo', *args)
def zip(self, path_folder): print('Begin zipped file ' + str(path_folder) + '.zip') directory = path_folder file_paths = self.get_all_file_paths(directory) with ZipFile(path_folder + '.zip', 'w') as zip: for file in file_paths: zip.write(file) print('All files zipped successfully!')
def transfer(self): if self.channel == CHANNEL_1 or self.channel == CHANNEL_2: with ZipFile('SAMPLES.zip', 'w') as zipf: zipf.write('z.voltage_ch' + str(self.channel) + self.format) zipf.write('z.current_ch' + str(self.channel) + self.format) if self.channel == CHANNEL_12: with ZipFile('SAMPLES.zip', 'w') as zipf: zipf.write('z.voltage_ch1' + self.format) zipf.write('z.current_ch1' + self.format) zipf.write('z.voltage_ch2' + self.format) zipf.write('z.current_ch2' + self.format) with open('SAMPLES.zip', 'rb') as f: data = f.read(self.CHUNK_SIZE) while data: self.conn.sendall(data) data = f.read(self.CHUNK_SIZE) print("File has been sent")
def do_unzip(self, inp): file_list = [] for file in os.listdir(os.getcwd()): if file.endswith('.zip'): file_list.append(file) questions = [ inquirer.Checkbox( 'files', message= "Select Folders to UnZip (use Spacebar to select and Enter to confirm)", choices=file_list) ] answers = inquirer.prompt(questions) for i in range(len(answers['files'])): print(os.path.abspath(os.getcwd()) + "/" + answers['files'][i]) with ZipFile(os.getcwd() + "/" + answers['files'][i], 'r') as zip: print('Extracting all the files now...') print(zip.namelist()[1]) if zip.filename in os.listdir(os.getcwd()): zip.filename = zip.filename + " Copy" zip.extractall() print('Done!')
def __init__(self, folder, file_name): self.file_path = os.path.join(folder, file_name) self.zip_file = ZipFile(self.file_path) self.zip_first_item = self.zip_file.namelist()[0]
def zipextractor(): print("enter") fn = "bhavcopy.zip" with ZipFile(fn, 'r') as zip: print("extractibh") zip.extractall()
def generate_reports(): with open("shodanout.json") as f: js = json.load(f) x = json2html.convert(json=js) f1 = open("shodanout.html", 'w') f1.write(x) f1.close() with open("shodanout.json") as f: data = f.read().replace('\n', '') f2 = open("shodanout.txt", 'w') f2.write(data) f2.close() with open("ip2proxyout.json") as f: js = json.load(f) x = json2html.convert(json=js) f1 = open("ip2proxyout.html", 'w') f1.write(x) f1.close() with open("ip2proxyout.json") as f: data = f.read().replace('\n', '') f2 = open("ip2proxyout.txt", 'w') f2.write(data) f2.close() with open("ipqualityout.json") as f: js = json.load(f) x = json2html.convert(json=js) f1 = open("ipqualityout.html", 'w') f1.write(x) f1.close() with open("ipqualityout.json") as f: data = f.read().replace('\n', '') f2 = open("ipqualityout.txt", 'w') f2.write(data) f2.close() with open("whoisout.json") as f: js = json.load(f) x = json2html.convert(json=js) f1 = open("whoisout.html", 'w') f1.write(x) f1.close() with open("whoisout.json") as f: data = f.read().replace('\n', '') f2 = open("whoisout.txt", 'w') f2.write(data) f2.close() with open("vpnapiout.json") as f: js = json.load(f) x = json2html.convert(json=js) f1 = open("vpnapiout.html", 'w') f1.write(x) f1.close() with open("vpnapiout.json") as f: data = f.read().replace('\n', '') f2 = open("vpnapiout.txt", 'w') f2.write(data) f2.close() pdfkit.from_file('whoisout.html', 'whoisout.pdf') pdfkit.from_file('ipqualityout.html', 'ipqualityout.pdf') pdfkit.from_file('ip2proxyout.html', 'ip2proxyout.pdf') pdfkit.from_file('shodanout.html', 'shodanout.pdf') pdfkit.from_file('vpnapiout.html', 'vpnapiout.pdf') with ZipFile('pdf_reports.zip', 'w') as zipObj2: # Add multiple files to the zip zipObj2.write('whoisout.pdf') zipObj2.write('shodanout.pdf') zipObj2.write('ipqualityout.pdf') zipObj2.write('ip2proxyout.pdf') zipObj2.write('vpnapiout.pdf') with ZipFile('html_reports.zip', 'w') as zipObj2: # Add multiple files to the zip zipObj2.write('whoisout.html') zipObj2.write('shodanout.html') zipObj2.write('ipqualityout.html') zipObj2.write('ip2proxyout.html') zipObj2.write('vpnapiout.html') with ZipFile('txt_reports.zip', 'w') as zipObj2: # Add multiple files to the zip zipObj2.write('whoisout.txt') zipObj2.write('shodanout.txt') zipObj2.write('ipqualityout.txt') zipObj2.write('ip2proxyout.txt') zipObj2.write('vpnapiout.txt') with ZipFile('json_reports.zip', 'w') as zipObj2: # Add multiple files to the zip zipObj2.write('whoisout.json') zipObj2.write('shodanout.json') zipObj2.write('ipqualityout.json') zipObj2.write('ip2proxyout.json') zipObj2.write('vpnapiout.json')