import zipfile import glob import os from ai import completion import shutil import requests html_path_list = [] if not os.path.exists('cyr.zip'): print('Descargando zip...') zip_cdn = requests.get(os.environ['ZIP_DL'], headers={'User-Agent': 'build'}) with open('cyr.zip', 'wb') as cyr_zip: cyr_zip.write(zip_cdn.content) archive = zipfile.ZipFile('cyr.zip') archive.extractall() shutil.move('webs cyr/', 'webs/') if os.path.exists('dist'): shutil.rmtree('dist') for fname in glob.glob('./webs/**/*.zip'): dirs = fname.split('/') owners = dirs[2] print(f'Procesando a {owners}') owner = completion(f'you are an ai that only gets the first person\'s name and returns it in lowercase. here is the current directory name: {owners}. you must only return the lowercase name and nothing else. you mustn\'t return special characters, only english ones. return names composed of more than one word with underscores') dist_loc = f'dist/{owner}' os.makedirs(dist_loc) archive = zipfile.ZipFile(fname) archive_dirs = archive.namelist() root_zip_dir = archive_dirs[0].split('/')[0] for dirs in archive_dirs: if dirs.startswith(f'{root_zip_dir}/dist'): archive.extract(dirs, dist_loc) shutil.move(f'{dist_loc}/{dirs}', dist_loc) shutil.rmtree(f'{dist_loc}/{root_zip_dir}') html_path_list.append(f'
  • {owners} (/{owner})
  • ') with open('template.html', 'r') as template: print('Escribiendo plantilla') template_text = template.read() with open('dist/index.html', 'w') as final_index: str_path_list = '\n'.join(html_path_list) final_index.write(template_text.replace('{{LIST}}', str_path_list)) print('Todo listo')