From 0544c26c6f122e978e2d83665dbb4cd12a6c89a0 Mon Sep 17 00:00:00 2001 From: Jeff Elkner Date: Sat, 29 Apr 2023 22:02:16 -0400 Subject: [PATCH] Add archives --- archives/elknet.py | 46 ++++++++ archives/old_homepage.php | 227 ++++++++++++++++++++++++++++++++++++++ archives/quotes.py | 77 +++++++++++++ 3 files changed, 350 insertions(+) create mode 100644 archives/elknet.py create mode 100644 archives/old_homepage.php create mode 100644 archives/quotes.py diff --git a/archives/elknet.py b/archives/elknet.py new file mode 100644 index 0000000..f254845 --- /dev/null +++ b/archives/elknet.py @@ -0,0 +1,46 @@ +import os +import sys +import argparse +import quotes +from bottle import route, run, template, static_file + + +# get current location, set as current location, and append to path +current_dir = os.path.dirname(os.path.abspath(__file__)) +os.chdir(current_dir) +sys.path.append(current_dir) + +# get absolute path of database file +dbfile = current_dir + '/quotes.db' +print(dbfile) + + +@route('/') +def index(): + quote = quotes.get_random_quote(dbfile) + return template('templates/index.tpl', text=quote[0], author=quote[1]) + + +@route('/static/') +def server_static(filename): + return static_file(filename, root=os.path.join(current_dir, 'static')) + + +@route('/contact') +def contact(): + quote = quotes.get_random_quote(dbfile) + return template('templates/contact.tpl', text=quote[0], author=quote[1]) + + +def get_port(): + description = 'A bottle server for the HILT Institute' + parser = argparse.ArgumentParser(description) + parser.add_argument('-p', '--port', type=int, + help="The port number the server will run on") + args = parser.parse_args() + + return args.port if args.port else 8080 + + +if __name__ == '__main__': + run(host='0.0.0.0', port=get_port(), reloader=True, debug=True) diff --git a/archives/old_homepage.php b/archives/old_homepage.php new file mode 100644 index 0000000..a18c645 --- /dev/null +++ b/archives/old_homepage.php @@ -0,0 +1,227 @@ + + + + +Welcome to elkner.net! + + + + +
+ +

Welcome to elkner.net!

+

+I'm *WAY* too busy with all the exciting projects I'm working on to do much +with this page, so let me just include contact information and some links. +Check them out! +

+

+-- Jeff Elkner

+
+ +

+Weblog | +Contact Information | +Resume +

+ +
+ + +
+

NOVA Web Development:

+ +
+
+ +
+ + + +
+ +
+ + +
+

Exits:

+ +
+
+ +

Papers/Articles/Presentations:

+ + +
+

{{text}}

+

-- {{author}}

+
+ + + + + diff --git a/archives/quotes.py b/archives/quotes.py new file mode 100644 index 0000000..da6b89b --- /dev/null +++ b/archives/quotes.py @@ -0,0 +1,77 @@ +import sqlite3 +import random + + +def query(db, stmnt): + con = sqlite3.connect(db) + cur = con.cursor() + cur.execute(stmnt) + results = cur.fetchall() + con.close() + return results + + +def get_authors(db): + return query(db, 'SELECT * FROM Author ORDER BY lname') + + +def get_quotes(db): + stmnt = """SELECT qtext, fname, lname, source, qdate FROM Quote + NATURAL JOIN Author ORDER BY RANDOM()""" + return query(db, stmnt) + + +def format_quote(raw_quote): + """ + Return a tuple containing (text, source) for a quote given a raw quote + containing [text, author first name, author last name, source document, + quote date] where all fields accept text are possibly None values. Source + should be set to "Anonymous" if no other info is provided. + + Examples: + + >>> format_quote(['Quote', 'F', 'L', 'Source', 'Date']) + ('Quote', 'F L, Source, Date') + >>> format_quote(['Quote', 'F', 'L', None, None]) + ('Quote', 'F L') + >>> format_quote(['Quote', 'F', 'L', 'Source', None]) + ('Quote', 'F L, Source') + >>> format_quote(['Quote', 'F', 'L', None, 'Date']) + ('Quote', 'F L, Date') + >>> format_quote(['Quote', None, 'L', None, None]) + ('Quote', 'L') + >>> format_quote(['Quote', None, None, 'Source', None]) + ('Quote', 'Source') + >>> format_quote(['Quote', None, None, None, None]) + ('Quote', 'Anonymous') + """ + text = raw_quote[0] + source = [] + + # append author name (first and last) to source list if provided + if raw_quote[1] and raw_quote[2]: + source.append("%s %s" % (raw_quote[1], raw_quote[2])) + elif raw_quote[2]: # only last name provided + source.append(raw_quote[2]) + + # append source document and date to source list if provided + for item in raw_quote[-2:]: + if item: + source.append(item) + + # join the pieces into a string seperated by comma and space + if source: + source = ", ".join(source) + else: # no source information provided, so make it "Anonymous" + source = "Anonymous" + + return text, source + + +def get_random_quote(db): + return format_quote(get_quotes(db)[0]) + + +if __name__ == '__main__': + import doctest + doctest.testmod()