From 0592ce320bcd278741b7ce59600427289067a460 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 16 Dec 2015 17:21:39 -0600 Subject: [PATCH] Initial commit --- index.html | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ site.py | 56 ++++++++++++++++++++++ songquotes.yml | 40 ++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 index.html create mode 100644 site.py create mode 100644 songquotes.yml diff --git a/index.html b/index.html new file mode 100644 index 0000000..f508dcf --- /dev/null +++ b/index.html @@ -0,0 +1,125 @@ + + + + + + Dustin C. Hatch + + + + + + +
+ +
+

{{ quote.quote }}

+

+ {{ quote.title }} + by {{ quote.artist }} +

+
+
+ + + diff --git a/site.py b/site.py new file mode 100644 index 0000000..aac5d0c --- /dev/null +++ b/site.py @@ -0,0 +1,56 @@ +from milla.dispatch import routing +from webob import acceptparse +import jinja2 +import milla +import os +import random +import yaml + + +OFFERS = [ + 'application/xhtml+xml', + 'text/html', +] + + +try: + YamlLoader = yaml.CLoader +except AttributeError: + YamlLoader = yaml.Loader + + +env = jinja2.Environment( + loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), +) + + +with open(os.path.join(os.path.dirname(__file__), 'songquotes.yml')) as f: + songquotes = yaml.load(f, Loader=YamlLoader) + + +def home(request): + response = request.ResponseClass() + accept = acceptparse.MIMEAccept( + request.accept.header_value.replace('*/*', '') + ) + response.content_type = accept.best_match(OFFERS, + response.default_content_type) + tmpl = env.get_template('index.html') + response.text = tmpl.render(quote=random.choice(songquotes)) + return response + + +router = routing.Router() +router.add_route('/', home) +application = milla.Application(router) + + +if __name__ == '__main__': + from wsgiref import simple_server + httpd = simple_server.make_server('', 8080, application) + try: + httpd.serve_forever() + except KeyboardInterrupt: + print('') + httpd.shutdown() + httpd.server_close() diff --git a/songquotes.yml b/songquotes.yml new file mode 100644 index 0000000..cfa0fe0 --- /dev/null +++ b/songquotes.yml @@ -0,0 +1,40 @@ +- quote: I was given the seal and the key, and I will keep it until I die + title: A Prophecy of Worlds to Fall + artist: Xandria + album: Neverworld's End + year: 2012 +- quote: From ashes we were born, in silence we unite + title: Wander + artist: Kamelot + album: Epica + year: 2003 +- quote: It's hard to light a candle, easy to curse the dark instead + title: Last Ride of the Day + artist: Nightwish + album: Imaginaerum + year: 2012 +- quote: The truth will appear, forever I'm there for you and sing… + title: Sacrimony + artist: Kamelot + album: Silverthorn + year: 2012 +- quote: …The end of all they scare us with will be a million empty brains… + title: The Seven Angels + artist: Avantasia + album: The Metal Opera Part II + year: 2002 +- quote: Wide open minds will divine without reason + title: Spectres + artist: Avantasia + album: The Mystery of Time + year: 2013 +- quote: How come I want you, like the soil yearns for the rain + title: EdenEcho + artist: Kamelot + album: Ghost Opera + year: 2007 +- quote: Grant me just one look into the mystery behind + title: The Great Mystery + artist: Avantasia + album: The Mystery of Time + year: 2013