mirror of
https://github.com/ieshuelin/cyr3a25.git
synced 2026-06-06 01:16:48 +00:00
initial commit
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dist/
|
||||||
|
webs/
|
||||||
|
__pycache__/
|
||||||
|
cyr.zip
|
||||||
19
ai.py
Normal file
19
ai.py
Normal file
@@ -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}
|
||||||
41
main.py
Normal file
41
main.py
Normal file
@@ -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'<li><a href="/{owner}">{owners} (/{owner})</a></li>')
|
||||||
|
|
||||||
|
|
||||||
|
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 hecho')
|
||||||
17
template.html
Normal file
17
template.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Webs de 3ºA</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hola!</h1>
|
||||||
|
<p>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 <a href="https://github.com/ieshuelin/cyr3a25">Github</a>.</p>
|
||||||
|
<p>Debajo estará una lista con todas las webs. Podéis ver las vuestras y las de vuestros compañeros ;D</p>
|
||||||
|
<ul>
|
||||||
|
{{LIST}}
|
||||||
|
</ul>
|
||||||
|
<p>pd: esta web está hecha aplicando los conocimientos que he explicado en clase.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user