From deeb5518d35f2bda31f2747111eb9fe775ab625d Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Fri, 19 May 2023 16:10:23 +0100 Subject: [PATCH] [LABI] tema05 part1 added - Missing only the free exercise of including CSS/JS on the html static file --- 1ano/2semestre/labi/tema05/src/Actions.py | 10 ++++ 1ano/2semestre/labi/tema05/src/Website.py | 54 +++++++++++++++++++ .../labi/tema05/src/coords_getter.py | 12 +++++ 1ano/2semestre/labi/tema05/src/example1.html | 10 ++++ 1ano/2semestre/labi/tema05/src/example1.py | 10 ++++ 1ano/2semestre/labi/tema05/src/form1.html | 17 ++++++ .../labi/tema05/src/getter_example.py | 5 ++ .../labi/tema05/src/poster_example.py | 7 +++ 8 files changed, 125 insertions(+) create mode 100644 1ano/2semestre/labi/tema05/src/Actions.py create mode 100644 1ano/2semestre/labi/tema05/src/Website.py create mode 100644 1ano/2semestre/labi/tema05/src/coords_getter.py create mode 100644 1ano/2semestre/labi/tema05/src/example1.html create mode 100644 1ano/2semestre/labi/tema05/src/example1.py create mode 100644 1ano/2semestre/labi/tema05/src/form1.html create mode 100644 1ano/2semestre/labi/tema05/src/getter_example.py create mode 100644 1ano/2semestre/labi/tema05/src/poster_example.py diff --git a/1ano/2semestre/labi/tema05/src/Actions.py b/1ano/2semestre/labi/tema05/src/Actions.py new file mode 100644 index 0000000..6f16337 --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/Actions.py @@ -0,0 +1,10 @@ +import cherrypy + + +class Actions(object): + @cherrypy.expose + def do_login(self, username=None, password=None): + if username is None or password is None: + return "Preencha os campos!" + else: + return "Bem-vindo, %s!" % username diff --git a/1ano/2semestre/labi/tema05/src/Website.py b/1ano/2semestre/labi/tema05/src/Website.py new file mode 100644 index 0000000..ae61b3d --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/Website.py @@ -0,0 +1,54 @@ +import os +import cherrypy +import Actions + + +PATH = os.path.abspath(os.path.dirname(__file__)) + + +class HTMLDocument(object): + @cherrypy.expose + def index(self): + with open("example1.html", "r") as f: + return f.read() + + +class Node(object): + @cherrypy.expose + def index(self): + return "Eu sou o índice do Node (Node.index)" + + @cherrypy.expose + def page(self): + return "Eu sou um método do Node (Node.page)" + + +class Root(object): + def __init__(self): + self.node = Node() + self.html = HTMLDocument() + self.actions = Actions.Actions() + + @cherrypy.expose + def index(self): + return "Eu sou o índice do Root (Root.index)" + + @cherrypy.expose + def page(self): + return "Eu sou um método do Root (Root.page)" + + @cherrypy.expose + def form(self): + cherrypy.response.headers["Content-Type"] = "text/html" + return open("form1.html") + + +if __name__ == "__main__": + conf = { + "/": { + "tools.staticdir.on": True, + "tools.staticdir.dir": PATH, + } + } + cherrypy.quickstart(Root(), "/", config=conf) + \ No newline at end of file diff --git a/1ano/2semestre/labi/tema05/src/coords_getter.py b/1ano/2semestre/labi/tema05/src/coords_getter.py new file mode 100644 index 0000000..0560ac5 --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/coords_getter.py @@ -0,0 +1,12 @@ +import json +import requests + + +address = "Universidade de Aveiro, 3810-193 Aveiro, Portugal" + +servurl = "https://nominatim.openstreetmap.org/search.php?format=json&q=%s" % address + +r = requests.get(servurl) + +print(json.dumps(r.json(), indent=4, sort_keys=True)) +print("Latitude:", r.json()[0]["lat"], "\nLongitude:", r.json()[0]["lon"]) diff --git a/1ano/2semestre/labi/tema05/src/example1.html b/1ano/2semestre/labi/tema05/src/example1.html new file mode 100644 index 0000000..a11cc84 --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/example1.html @@ -0,0 +1,10 @@ + + +
+ +