def load_data(): client = connect() db = client[skill_config.DB_NAME] pathlist = Path('files').glob('**/*.txt') for path in pathlist: path = str(path) date = path.replace('files{}'.format(os.sep), '').replace('{}list.txt'.format(os.sep), '').split(os.sep) day = date[-1] month = date[0] print(date) with open(path, 'r', encoding='utf-8') as file: for line in file: db.ephemeris.insert_one({ 'date': '{}/{}'.format(day, month), 'event': line.strip() }) close(client)
def _normalize_path_win_to_DB_lower(path): res = database.view('device/all') for device in res: name = device.value['login'].lower() if path is '\\': return "/%s" %name else: return "/%s" %name + path.replace('\\', '/').lower()
def reversePath(path): cindex = path.find('cache/') if cindex == -1 or path[-6:] != '.cache': raise Exception( "I expect a full cached filepath 'cache/<domain>/<path>.cache'. {0} does not match" .format(path)) path = path[cindex + 6:-6] return path.replace('^', '/')
def tax_file_to_dict(path, out_dict): with open(path) as infile: for line in infile: fields = line.strip().split('\t') # .replace('_nofilter') so that reads from allfilter and nofilter have the same name, but reads from fwd and rev don't. read = path.replace('_nofilter', '') + fields[0] tax_string = fields[1] if len(fields) > 1 else 'n_Unclassified' tax, tax_wranks = parse_tax_string(tax_string) out_dict[read] = tax_wranks
def _path_split(path): ''' ''' res = database.view('device/all') for device in res: login = device.value['login'] if path is '\\': path = "/%s" %login else: path = "/%s" %login + path.replace('\\', '/') (folder_path, name) = os.path.split(path) if folder_path[-1:] == '/': folder_path = folder_path[:-(len(login)+1)] return (folder_path, name)
def read_dir(path, base_path): textures = [] for item in listdir(path): if item != '.' and item != '..': if isfile(join(path, item)): typ = path.replace(base_path, '').replace('/', '.') model = GameTexture( name=item, typ=typ, path=path ) textures.append(model) else: [textures.append(x) for x in read_dir( join(path, item), base_path)] return textures
def get_settings_for_tty(tty): return { name: [path.replace('TTY', tty), value, min, max] for name, (path, value, min, max) in c.SETTINGS.iteritems() }
destiny.close() # making more sizes for the site try: modified = Image.open(destiny_path) for multiplier in conf.TEXTURES_EXTRA_SIZES_MULTIPLIER: sizes = (modified.size[0] * multiplier, modified.size[1] * multiplier) modified_path = destiny_path.replace('.png', '_x%d.png' % multiplier) resized = modified.resize(sizes, Image.NEAREST) resized.save(modified_path, 'PNG') except IOError: pass TEXTURES.append( GameTexture( f, path.replace('jarfile/textures/', ''), join(path, f).replace('jarfile/textures/', '') ) ) if conf.SAVE: for texture in TEXTURES: try: item = Texture.objects.get( name=texture.name, type=texture.type ) except Texture.DoesNotExist: item = Texture( name=texture.name, type=texture.type,
def delete_obj_file(path): os.remove(path) if os.path.exists(path.replace(".obj", ".mtl")): os.remove(path.replace(".obj", ".mtl"))
def _normalize_path_DB_to_win_lower(path): res = database.view('device/all') for device in res: login = device.value['login'].lower() path = path.replace("/%s" %name, '\\') return path.replace('/', '\\').lower()
def reversePath(path): cindex = path.find('cache/') if cindex == -1 or path[-6:] != '.cache': raise Exception("I expect a full cached filepath 'cache/<domain>/<path>.cache'. {0} does not match".format(path)) path = path[cindex+6:-6] return path.replace('^','/')