- 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: Difference between revisions
Jump to navigation
Jump to search
imported>Doxcat Created page with "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..." |
imported>Doxcat Created page with "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..." |
(5 intermediate revisions by the same user not shown) | |
(No difference)
|
Latest revision as of 17:14, 19 December 2012
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__();