Created
February 22, 2010 08:52
-
-
Save dchud/310938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!./bin/python | |
import os | |
import sqlite3 | |
import web | |
import pymarc | |
print 'Clearing out old db' | |
try: | |
os.remove('data.sqlite3') | |
except: | |
pass | |
conn = sqlite3.connect('data.sqlite3') | |
c = conn.cursor() | |
c.execute(''' | |
CREATE TABLE title ( | |
id SERIAL PRIMARY KEY, | |
title TEXT, | |
who TEXT); | |
''') | |
c.close() | |
conn.close() | |
db = web.database(dbn='sqlite', db='data.sqlite3') | |
records = [] | |
urls = ( | |
'/', 'index', | |
) | |
app = web.application(urls, globals()) | |
class index: | |
def GET (self): | |
web.header('Content-Type', 'text/html') | |
out = [] | |
recs = db.select('title') | |
for rec in recs: | |
out.append("<p>%s, %s</p>" % (rec['title'], rec['who'])) | |
return 'hi' + '\n'.join(out) | |
if __name__ == '__main__': | |
print 'Loading records' | |
#reader = pymarc.MARCReader(open('../data/marc-00428000-00429999.mrc')) | |
reader = pymarc.MARCReader(open('../data/magic-testing-marc.mrc')) | |
for rec in reader: | |
records.append(rec) | |
title = rec['245']['a'] | |
try: | |
who = rec['100']['a'] | |
except: | |
pass | |
n = db.insert('title', title=title, who=who) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment