From ecfd62348286015ff237fbf0d416813b75f4b0c7 Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Tue, 17 Jun 2025 15:32:27 +0000 Subject: [PATCH] initial commit --- .gitignore | 4 ++++ ai.py | 19 +++++++++++++++++++ main.py | 41 +++++++++++++++++++++++++++++++++++++++++ template.html | 17 +++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 ai.py create mode 100644 main.py create mode 100644 template.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a81a2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +dist/ +webs/ +__pycache__/ +cyr.zip \ No newline at end of file diff --git a/ai.py b/ai.py new file mode 100644 index 0000000..e9e357d --- /dev/null +++ b/ai.py @@ -0,0 +1,19 @@ +import requests +import json + +def completion(message): + url = "https://ai.hackclub.com/chat/completions" + headers = { + "Content-Type": "application/json" + } + data = { + "messages": [{"role": "user", "content": message}] + } + + response = requests.post(url, headers=headers, data=json.dumps(data)) + + if response.status_code == 200: + j = response.json() + return j.get('choices', [{}])[0].get('message', {}).get('content', '') + else: + return {"error": response.status_code, "message": response.text} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..60eb794 --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +import zipfile +import glob +import os +from ai import completion +import shutil + +html_path_list = [] + +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'
Aquí se pueden ver todas las páginas que habéis hecho. El código para importar las páginas en su sitio es abierto y está en Github.
+Debajo estará una lista con todas las webs. Podéis ver las vuestras y las de vuestros compañeros ;D
+pd: esta web está hecha aplicando los conocimientos que he explicado en clase.
+ + \ No newline at end of file