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 @@ + + +
+ +