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 @@ + + + + + Exemplo HTML 1 + + +

Exemplo HTML 1

+ + \ No newline at end of file diff --git a/1ano/2semestre/labi/tema05/src/example1.py b/1ano/2semestre/labi/tema05/src/example1.py new file mode 100644 index 0000000..c8f28e6 --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/example1.py @@ -0,0 +1,10 @@ +import cherrypy + + +class HelloWorld(object): + @cherrypy.expose + def index(self): + return "You have successfully reached " + cherrypy.request.headers["Host"] + + +cherrypy.quickstart(HelloWorld()) diff --git a/1ano/2semestre/labi/tema05/src/form1.html b/1ano/2semestre/labi/tema05/src/form1.html new file mode 100644 index 0000000..fc47044 --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/form1.html @@ -0,0 +1,17 @@ + + + + + Form 1 + + +
+

Username

+ +

Password

+ +

+

+
+ + \ No newline at end of file diff --git a/1ano/2semestre/labi/tema05/src/getter_example.py b/1ano/2semestre/labi/tema05/src/getter_example.py new file mode 100644 index 0000000..d284391 --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/getter_example.py @@ -0,0 +1,5 @@ +import requests + + +f = requests.get("https://www.ua.pt") +print(f.text) diff --git a/1ano/2semestre/labi/tema05/src/poster_example.py b/1ano/2semestre/labi/tema05/src/poster_example.py new file mode 100644 index 0000000..55f683a --- /dev/null +++ b/1ano/2semestre/labi/tema05/src/poster_example.py @@ -0,0 +1,7 @@ +import requests + + +url = "http://127.0.0.1:8080/form" +data = {"username": "admin", "password": "admin"} +f = requests.post(url, data=data) +print(f.status_code)