begynt på funksjonen book_from_xml
This commit is contained in:
parent
4d7ff0d4c6
commit
d173b9396e
|
@ -1,13 +1,15 @@
|
|||
from web.library.models import *
|
||||
from xml.dom import minidom
|
||||
from PyZ3950 import zoom
|
||||
import readline
|
||||
|
||||
exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q']
|
||||
|
||||
class Bibsys():
|
||||
def __init__(self):
|
||||
self.conn = zoom.Connection ('z3950.bibsys.no', 2100)
|
||||
self.conn.databaseName = 'BIBSYS'
|
||||
self.conn.preferredRecordSyntax = 'XML'
|
||||
class ZLibrary():
|
||||
def __init__(self, host, port, dbname, syntax):
|
||||
self.conn = zoom.Connection(host, port)
|
||||
self.conn.databaseName = dbname
|
||||
self.conn.preferredRecordSyntax = syntax
|
||||
|
||||
def isbn_search(self, isbn):
|
||||
query = zoom.Query('CCL', 'ISBN='+isbn)
|
||||
|
@ -17,6 +19,17 @@ class Bibsys():
|
|||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
class Congress(ZLibrary):
|
||||
def __init__(self):
|
||||
ZLibrary.__init__(self, 'z3950.loc.gov', 7090, 'VOYAGER', 'USMARC')
|
||||
|
||||
class Bibsys(ZLibrary):
|
||||
def __init__(self):
|
||||
ZLibrary.__init__(self, 'z3950.bibsys.no', 2100, 'BIBSYS', 'XML')
|
||||
# self.conn = zoom.Connection ('z3950.bibsys.no', 2100)
|
||||
# self.conn.databaseName = 'BIBSYS'
|
||||
# self.conn.preferredRecordSyntax = 'XML'
|
||||
|
||||
#class Menu():
|
||||
|
||||
def get_book_loop():
|
||||
|
@ -27,8 +40,33 @@ def get_book_loop():
|
|||
break
|
||||
else:
|
||||
r = bib.isbn_search(input)
|
||||
if len(r) > 0:
|
||||
if len(r) == 1:
|
||||
print "Found one match"
|
||||
print r[0]
|
||||
book_from_xml(r[0])
|
||||
# document = minidom.parseString(str(r[0])[9:])
|
||||
# print document.getElementsByTagName('dc:title')[0].childNodes[0].data
|
||||
elif len(r) > 1:
|
||||
print "Found several matches"
|
||||
else:
|
||||
print "No results found"
|
||||
bib.close()
|
||||
|
||||
def book_from_xml(dc):
|
||||
b = Book()
|
||||
document = minidom.parseString(str(dc)[9:])
|
||||
titles = document.getElementsByTagName('dc:title')
|
||||
if titles.length == 1:
|
||||
title = ""
|
||||
for node in titles[0].childNodes:
|
||||
if node.nodeType == node.TEXT_NODE:
|
||||
title += " "+node.data
|
||||
title = title.strip().split('/')
|
||||
(title, authors) = (title[:-1],title[-1])
|
||||
authors = authors.split(',')
|
||||
print title, authors
|
||||
else:
|
||||
print "Several titles found, owshi"
|
||||
|
||||
|
||||
get_book_loop()
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
from web.library.models import *
|
||||
from django.contrib import admin
|
||||
|
||||
mod = [Category, BookSeries, ReferenceType, Reference, Book, AlternativeTitle, Copy, Person, Relation, BookPerson, Placement]
|
||||
|
||||
for model in mod:
|
||||
admin.site.register(model)
|
|
@ -1,5 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
book_fields = {'isbn' : 'ISBN', 'id' : 'Identifier', 'title' : 'Title',
|
||||
'subtitle' : 'Subtitle', 'category' : 'Category', 'publisher':'Publisher',
|
||||
'published_year':'Published year', 'edition' : 'Edition', 'num_pages' : 'Number of pages',
|
||||
'series' : 'Series', 'description' : 'Description'}
|
||||
|
||||
class Category(models.Model):
|
||||
id = models.CharField(max_length=255, primary_key=True)
|
||||
name = models.CharField(max_length=255)
|
||||
|
@ -8,6 +13,13 @@ class BookSeries(models.Model):
|
|||
id = models.CharField(max_length=20, primary_key=True)
|
||||
title = models.CharField(max_length=511)
|
||||
|
||||
class ReferenceType(models.Model):
|
||||
name = models.CharField(max_length=31)
|
||||
|
||||
class Reference(models.Model):
|
||||
reference_type = models.ForeignKey(ReferenceType)
|
||||
text = models.CharField(max_length=1023)
|
||||
|
||||
class Book(models.Model):
|
||||
isbn = models.CharField(max_length=13, primary_key=True)
|
||||
id = models.CharField(max_length=255, unique=True)
|
||||
|
@ -22,6 +34,11 @@ class Book(models.Model):
|
|||
description = models.CharField(max_length=1023, null=True, blank=True)
|
||||
picture = models.ImageField(upload_to='%Y/%m/%d/pictures', null=True, blank=True)
|
||||
thumbnail = models.ImageField(upload_to='%Y/%m/%d/thumbnails', null=True, blank=True)
|
||||
references = models.ManyToManyField(Reference, related_name='books')
|
||||
|
||||
def full_print(self):
|
||||
for field in book_fields.items():
|
||||
print '%15s: %-30s' % (field[1],eval('self.'+field[0]))
|
||||
|
||||
class AlternativeTitle(models.Model):
|
||||
book = models.ForeignKey(Book)
|
||||
|
@ -36,6 +53,7 @@ class Person(models.Model):
|
|||
id = models.CharField(max_length=255, primary_key=True)
|
||||
first_name = models.CharField(max_length=255)
|
||||
last_name = models.CharField(max_length=255)
|
||||
references = models.ManyToManyField(Reference, related_name='persons')
|
||||
|
||||
class Relation(models.Model):
|
||||
name = models.CharField(max_length=31)
|
||||
|
@ -45,13 +63,6 @@ class BookPerson(models.Model):
|
|||
person = models.ForeignKey(Person)
|
||||
relation = models.ForeignKey(Relation)
|
||||
|
||||
class ReferenceType(models.Model):
|
||||
name = models.CharField(max_length=31)
|
||||
|
||||
class Reference(models.Model):
|
||||
reference_type = models.ForeignKey(ReferenceType)
|
||||
text = models.CharField(max_length=1023)
|
||||
|
||||
class Placement(models.Model):
|
||||
category = models.ForeignKey(Category)
|
||||
shelf = models.CharField(max_length=10)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
# from django.contrib import admin
|
||||
# admin.autodiscover()
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Example:
|
||||
|
@ -13,5 +13,5 @@ urlpatterns = patterns('',
|
|||
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
|
||||
# Uncomment the next line to enable the admin:
|
||||
# (r'^admin/', include(admin.site.urls)),
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
|
Reference in New Issue