def o2sc(): app = current_app._get_current_object() if request.method == 'POST': # get the form data file = request.files['file'] delimiter = str(request.form['delimiter']) quote_char = str(request.form['quote-char']) doc_type = str(request.form['doc-type']) file_path_field = str(request.form['file-path-field']) unique_id = str(request.form['unique-id']) omit = str(request.form['omit']) header_mapping = str(request.form['header-mapping']) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) c = Converter() if '.zip' in filename: z = Zip() extracted_list = z.unzip(app.config['UPLOAD_FOLDER'], filename) for filename in extracted_list: c.convert_file(app.config['UPLOAD_FOLDER'], app.config['DOWNLOAD_FOLDER'], filename, delimiter, quote_char, doc_type, file_path_field, unique_id, omit, header_mapping) zip_archive = z.zip(app.config['DOWNLOAD_FOLDER'], extracted_list) response = make_response(zip_archive) response.headers["Content-Disposition"] = "attachment; filename=_converted_zip_archive.zip" return response else: converted_file = c.convert_file(app.config['UPLOAD_FOLDER'], app.config['DOWNLOAD_FOLDER'], filename, delimiter, quote_char, doc_type, file_path_field, unique_id, omit, header_mapping) response = make_response(converted_file) response.headers["Content-Disposition"] = "attachment; filename=_converted_" + filename return response return render_template('o2sc/upload.html')
def getRiskValue(self, name: str, infoString: str): entries = infoString.split("###") summedRisk = 0 for entry in entries: fields = entry.split("\n") risks = "" date = 0 startTime = 0 endTime = 0 zipcode = 0 address = "" for x in range(6): if x > 2: risks += fields[x] + ";" elif x == 0: date = formatDate(fields[x]) elif x == 1: startTime, endTime = formatTimeRangeIntoInts(fields[x]) else: address, zipcode = getLocationData(fields[x]) currentPerson = Person(name, risks) if zipcode not in self.zips: self.zips[zipcode] = Zip(zipcode) summedRisk += self.zips[zipcode].getRiskValue(date, (startTime, endTime), address, currentPerson) return summedRisk
def add_zip(self, name: str, lon: float, lat: float): """ add zip to the network :param name: :param lon: :param lat: :return: """ zipcode = Zip(name, lon, lat) self.zips.append(zipcode)
class AtaqueFuerzaBruta(object): def __init__(self, rutaArchivo, rutaDiccionario, destino): self.__datos = self.__cargarArchivo(rutaDiccionario) self.__L = len(self.__datos) self.__archivo = Zip(rutaArchivo, destino) self.__progreso = BarraProgreso() def __cargarArchivo(self, nombreArchivo): datos = [] archivo = open(nombreArchivo, "r") for palabra in archivo: datos.append(palabra.replace("\n", "")) archivo.close() return datos def __coincide(self, clave): return self.__archivo.extraer(clave) def atacar(self): print() inicio = time() n = 1 for candidata in self.__datos: if self.__coincide(candidata): print() fin = time() print("\nTiempo transcurrido:", str(round(fin - inicio, 5)) + "s") print("Clave:", candidata) return candidata self.__progreso.printProgressBar(n, self.__L) n += 1 fin = time() print("\nTiempo transcurrido:", str(round(fin - inicio, 5)) + "s") print("Clave no encontrada") return ""
def osx_log(self, log_data): """ 发送OSX客户端的日志 :param bytes log_data: 日志记录数据 :return bool: 是否发送成功 """ url = 'http://music.163.com/api/feedback/client/log' music_u = self._cookie.get_cookie('MUSIC_U') if music_u is not None: url += '?MUSIC_U=' + music_u file_name = time.strftime( str(self._user_id) + '_%Y-%m-%d %H:%M:%S.log') # 压缩日志 zip_data = Zip.compress_data({file_name: log_data}) resp = self._request( 'POST', url, {'attach': ('%dlog.zip' % self._user_id, zip_data)}) if resp is not None: data = json.loads(resp.data.decode()) return data['code'] == 200 return False
def __init__(self, rutaArchivo, rutaDiccionario, destino): self.__datos = self.__cargarArchivo(rutaDiccionario) self.__L = len(self.__datos) self.__archivo = Zip(rutaArchivo, destino) self.__progreso = BarraProgreso()
def __init__(self, filename=''): Zip.__init__(self, filename) self.manifest = self.get_manifest() self.is_manifest_created = False
def add_file(self, name, content='', write_to_manifest=True): Zip.add_file(self, name, content) if write_to_manifest: self.__add_file_to_manifest(name)