- Portals
- The Current Year
- ED in the News
- Admins
- Help ED Rebuild
- Archive
- ED Bookmarklet
- Donate Bitcoin
Contact an admin on Discord or EDF if you want an account. Also fuck bots.
User:Doxcat/resolve isbn
From Encyclopedia Dramatica
Jump to navigationJump to search
if u happen to have a barcode scanner, u can use it to scan barcodes, rite?
well this script will resolve an ISBN into something less... number string-y change the key if u have a problem with it or whatever
sauwse:
import urllib2
import urllib
from xml.dom import minidom
from string import strip
import locale
class Main:
key = "QT43XILR"
def __main__(self):
while True:
input = raw_input("ISBN: ")
success = self.handle(input)
if success is None:
print "Not found: "+input
continue
else:
print input+" found. Data follows.\n"
for k,v in success.iteritems():
print k,":",v
def handle(self,input):
req = urllib2.Request("http://isbndb.com/api/books.xml?access_key="+self.key+"&index1=isbn&value1="+input);
f = urllib2.urlopen(req);
xml = f.read().replace('\n','')
data = minidom.parseString(xml)
BookList = data.getElementsByTagName("BookList")[0]
if BookList.attributes["total_results"].value == u'0':
return None
Title = data.getElementsByTagName("Title")[0].firstChild.data
if data.getElementsByTagName("TitleLong")[0].firstChild is None:
LongTitle=""
else:
LongTitle=data.getElementsByTagName("TitleLong")[0].firstChild.data;
if data.getElementsByTagName("AuthorText") == [] or data.getElementsByTagName("AuthorText")[0].firstChild is None:
Author=""
else:
Author = data.getElementsByTagName("AuthorText")[0].firstChild.data
if data.getElementsByTagName("PublisherText")[0].firstChild is None:
Publisher=""
else:
Publisher = data.getElementsByTagName("PublisherText")[0].firstChild.data
return {"Author":Author,"Title":Title,"LongTitle":LongTitle,"Publisher":Publisher};
return True;
if __name__ == "__main__":
main = Main();
main.__main__();