diff --git a/__pycache__/globalState.cpython-311.pyc b/__pycache__/globalState.cpython-311.pyc index 1b1f1c1..cba5c5a 100644 Binary files a/__pycache__/globalState.cpython-311.pyc and b/__pycache__/globalState.cpython-311.pyc differ diff --git a/data.xlsx b/data.xlsx deleted file mode 100644 index bd5d26a..0000000 Binary files a/data.xlsx and /dev/null differ diff --git a/main.py b/main.py index 1822c97..947bda6 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import flet as ft -from views import admins, customers, domains, peerings, subscribers, rewriteRules, download +from views import admins, customers, domains, peerings, subscribers, rewriteRules, download, upload import login def main(page: ft.Page): @@ -20,6 +20,8 @@ def main(page: ft.Page): login.log(page) elif event.route == "/rewriterulesets": rewriteRules.rewrite(page) + elif event.route == "/upload": + upload.upload(page) if event.route == '/login': page.navigation_bar.visible = False @@ -47,13 +49,13 @@ def main(page: ft.Page): ft.NavigationBarDestination(icon=ft.icons.REMOVE_RED_EYE, label="Peerings"), ft.NavigationBarDestination(icon=ft.icons.PERSON_ADD, label="Subscribers"), ft.NavigationBarDestination(icon=ft.icons.NOTES, label= "Rewrite Rules"), - ft.NavigationBarDestination(icon=ft.icons.DOWNLOAD, label="Download info") + ft.NavigationBarDestination(icon=ft.icons.UPLOAD, label="Upload info"), ] page.navigation_bar = ft.NavigationBar( selected_index=0, on_change=lambda e: page.go( - ["/administration", "/customers", "/domains", "/peerings", "/subscribers", "/rewriterulesets"][e.control.selected_index] + ["/administration", "/customers", "/domains", "/peerings", "/subscribers", "/rewriterulesets", "/upload"][e.control.selected_index] ), destinations=destinations, visible=False diff --git a/views/__pycache__/upload.cpython-311.pyc b/views/__pycache__/upload.cpython-311.pyc new file mode 100644 index 0000000..b55cef4 Binary files /dev/null and b/views/__pycache__/upload.cpython-311.pyc differ diff --git a/views/upload.py b/views/upload.py index dbe237f..6c15c3b 100644 --- a/views/upload.py +++ b/views/upload.py @@ -2,9 +2,54 @@ import flet as ft import pandas as pd import requests from requests.auth import HTTPBasicAuth -import json +from globalState import AppState -def upload_info(): - print("Hola") +def upload(page: ft.Page): -upload_info() \ No newline at end of file + user = AppState.user + password = AppState.password + url = AppState.url + + page.title = "Seleccionar archivo y cargar en variable" + page.horizontal_alignment = ft.CrossAxisAlignment.CENTER + page.vertical_alignment = ft.CrossAxisAlignment.CENTER + text = ft.Text( + "¡Nota importante!", + style=ft.TextStyle( + size=30, + font_family="Roboto", + weight=ft.FontWeight.BOLD, + ) + ) + text2 = ft.Text("El archivo debe estar en formato de excel(xlsx)") + + file_picker = ft.FilePicker( + on_result=lambda f: process_file(f) + ) + page.overlay.append(file_picker) + + def select_file(e): + file_picker.pick_files( + allowed_extensions=["xlsx"], + allow_multiple=True + ) + + def process_file(file): + if file: + for f in file.files: + if f.name.endswith('.csv'): + df = pd.read_csv(f.path) + print(f"Datos de {f.name}:\n", df.head()) + elif f.name.endswith('.xlsx'): + sheets = pd.read_excel(f.path, sheet_name=None) + for sheet_name, df in sheets.items(): + print(f"Datos de {sheet_name} en {f.name}:\n", df.head(), "\n") + + upload_button = ft.ElevatedButton(text="Seleccionar archivo", on_click=select_file) + container = ft.Container( + content=upload_button, + ) + + container.margin = ft.margin.only(top=20) + page.add(text, text2) + page.add(container) \ No newline at end of file