diff --git a/webserver.py b/webserver.py index e44a5b3f5c..ab19863de5 100644 --- a/webserver.py +++ b/webserver.py @@ -1,3 +1,7 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from database_setup import Base, Restaurant + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import cgi @@ -9,49 +13,32 @@ class webserverHanlder (BaseHTTPRequestHandler): def do_GET(self): try: - if self.path.endswith("/hello"): + engine = create_engine('sqlite:///restaurantmenu.db') + Base.metadata.bind = engine + DBSession = sessionmaker(bind = engine) + ses = DBSession() + + restoList = ses.query(Restaurant).all() + if self.path.endswith("/restaurant"): self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() - output="" - output+="" - output+="

Hello!

" - output+= """ -
What would you like me to say? - - -
- """ - output+="" - self.wfile.write(output) - print output - return - if self.path.endswith("/hola"): - self.send_response(200) - self.send_header('Content-Type', 'text/html') - self.end_headers() + output="" output+="" - output+=""" -

¡Hola!

- Back to Hello - """ - output+= """ -
What would you like me to say? - - -
- """ - output+="" + output+="

Restaurant list

" + output+="
" + output+="" self.wfile.write(output) print output - return - + return except IOError: self.send_error(404, "File not Fount %s" % self.path)