Get book data from IFSDB.ORG

Share your advanced PureBasic knowledge/code with the community.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Get book data from IFSDB.ORG

Post by Fangbeast »

Just revisiting some old code and cleaned it up a a bit. This code sends an ISBN book number to IFSDB.ORG and it returns an XML file with data and decodes it. The site is mainly for fiction/science fiction but it's useful to me.

Type in the ISBN number and hit ENTER. If there is data, it will be displayed. If there is a linked cover page, it will be downloaded. You can save the book data cumulatively to a text file.

Code: Select all

;============================================================================================================================
; 
;============================================================================================================================

Enumeration 1
  #Window_getbook
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

;============================================================================================================================
; 
;============================================================================================================================

Enumeration 1
  #Gadget_getbook_pmain
  #Gadget_getbook_tdetails
  #Gadget_getbook_tpicture
  #Gadget_getbook_thistory
  #Gadget_getbook_fdetails
  #Gadget_getbook_ltitle
  #Gadget_getbook_title
  #Gadget_getbook_lauthor
  #Gadget_getbook_author
  #Gadget_getbook_lyear
  #Gadget_getbook_year
  #Gadget_getbook_lisbn
  #Gadget_getbook_isbn
  #Gadget_getbook_lpublisher
  #Gadget_getbook_publisher
  #Gadget_getbook_lprice
  #Gadget_getbook_price
  #Gadget_getbook_lpages
  #Gadget_getbook_pages
  #Gadget_getbook_ltype
  #Gadget_getbook_type
  #Gadget_getbook_lpicture
  #Gadget_getbook_picture
  #Gadget_getbook_lbinding
  #Gadget_getbook_fphoto
  #Gadget_getbook_lphoto
  #Gadget_getbook_photologo
  #Gadget_getbook_fhistory
  #Gadget_getbook_lhistory
  #Gadget_getbook_binding
  #Gadget_getbook_lgetisbn
  #Gadget_getbook_getisbn
  #Gadget_getbook_save
  #Gadget_getbook_exit
  #Gadget_getbook_lartist
  #Gadget_getbook_photo
  #Gadget_getbook_artist
  #Gadget_getbook_lnote
  #Gadget_getbook_note
  #Gadget_getbook_booklogo
  #Gadget_getbook_terrors
  #Gadget_getbook_ferrors
  #Gadget_getbook_lerrors
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

;============================================================================================================================
; 
;============================================================================================================================

Enumeration 1
  #StatusBar_getbook
EndEnumeration

#StatusBarIndex = #PB_Compiler_EnumerationValue
#StatusBar_getbook_messages = 0

;============================================================================================================================
; 
;============================================================================================================================

Enumeration 1
  #Image_getbook_tdetails
  #Image_getbook_tpicture
  #Image_getbook_thistory
  #Image_getbook_photologo
  #Image_getbook_save
  #Image_getbook_exit
  #Image_getbook_photo
  #Image_getbook_booklogo
  #Image_getbook_terrors
EndEnumeration

#ImageIndex = #PB_Compiler_EnumerationValue

;============================================================================================================================
; 
;============================================================================================================================

CatchImage(#Image_getbook_tdetails,   ?_PTK_getbook_tdetails)
CatchImage(#Image_getbook_tpicture,   ?_PTK_getbook_tpicture)
CatchImage(#Image_getbook_thistory,   ?_PTK_getbook_thistory)
CatchImage(#Image_getbook_photologo,  ?_PTK_getbook_photologo)
CatchImage(#Image_getbook_save,       ?_PTK_getbook_save)
CatchImage(#Image_getbook_exit,       ?_PTK_getbook_exit)
CatchImage(#Image_getbook_photo,      ?_PTK_getbook_photo)
CatchImage(#Image_getbook_booklogo,   ?_PTK_getbook_booklogo)
CatchImage(#Image_getbook_terrors,    ?_PTK_getbook_terrors)

;============================================================================================================================
; 
;============================================================================================================================

DataSection
  _PTK_getbook_tdetails : IncludeBinary "Images\messages16x16.ico"
  _PTK_getbook_tpicture : IncludeBinary "Images\camera16x16.ico"
  _PTK_getbook_thistory : IncludeBinary "Images\details.ico"
  _PTK_getbook_photologo: IncludeBinary "Images\camera48x48.ico"
  _PTK_getbook_save     : IncludeBinary "Images\save32x32.ico"
  _PTK_getbook_exit     : IncludeBinary "Images\exit32x32.ico"
  _PTK_getbook_photo    : IncludeBinary "Images\nopicture2.jpg"
  _PTK_getbook_booklogo : IncludeBinary "Images\book48x48.ico"
  _PTK_getbook_terrors  : IncludeBinary "Images\globe16x16.ico"
EndDataSection

;============================================================================================================================
; 
;============================================================================================================================

Procedure.l Window_getbook()
  If OpenWindow(#Window_getbook, 73, 81, 508, 560, "Get book details from www.ifsdb.org", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible)
    If CreateGadgetList(WindowID(#Window_getbook))
      PanelGadget(#Gadget_getbook_pmain, 0, 0, 510, 495)
      AddGadgetItem(#Gadget_getbook_pmain, -1, "Main book details", ImageID(#Image_getbook_tdetails))
      Frame3DGadget(#Gadget_getbook_fdetails, 0, 0, 505, 465, "")
      TextGadget(#Gadget_getbook_ltitle, 5, 20, 100, 20, "Title", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_ltitle, LoadFont(#Gadget_getbook_ltitle, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_title, 105, 15, 390, 25, "")
        SetGadgetFont(#Gadget_getbook_title, LoadFont(#Gadget_getbook_title, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lauthor, 5, 50, 100, 20, "Author", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lauthor, LoadFont(#Gadget_getbook_lauthor, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_author, 105, 45, 390, 25, "")
        SetGadgetFont(#Gadget_getbook_author, LoadFont(#Gadget_getbook_author, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lyear, 5, 80, 100, 20, "Year", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lyear, LoadFont(#Gadget_getbook_lyear, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_year, 105, 75, 105, 25, "")
        SetGadgetFont(#Gadget_getbook_year, LoadFont(#Gadget_getbook_year, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lisbn, 215, 80, 55, 20, "ISBN", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lisbn, LoadFont(#Gadget_getbook_lisbn, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_isbn, 270, 75, 225, 25, "")
        SetGadgetFont(#Gadget_getbook_isbn, LoadFont(#Gadget_getbook_isbn, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lpublisher, 5, 110, 100, 20, "Publisher", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lpublisher, LoadFont(#Gadget_getbook_lpublisher, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_publisher, 105, 105, 390, 25, "")
        SetGadgetFont(#Gadget_getbook_publisher, LoadFont(#Gadget_getbook_publisher, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lprice, 5, 140, 100, 20, "Price", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lprice, LoadFont(#Gadget_getbook_lprice, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_price, 105, 135, 75, 25, "")
        SetGadgetFont(#Gadget_getbook_price, LoadFont(#Gadget_getbook_price, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lpages, 185, 140, 60, 20, "Pages", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lpages, LoadFont(#Gadget_getbook_lpages, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_pages, 245, 135, 75, 25, "")
        SetGadgetFont(#Gadget_getbook_pages, LoadFont(#Gadget_getbook_pages, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_ltype, 325, 140, 55, 20, "Type", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_ltype, LoadFont(#Gadget_getbook_ltype, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_type, 380, 135, 115, 25, "")
        SetGadgetFont(#Gadget_getbook_type, LoadFont(#Gadget_getbook_type, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lpicture, 5, 170, 100, 20, "Picture", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lpicture, LoadFont(#Gadget_getbook_lpicture, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_picture, 105, 165, 140, 25, "")
        SetGadgetFont(#Gadget_getbook_picture, LoadFont(#Gadget_getbook_picture, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lbinding, 245, 170, 80, 20, "Binding", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lbinding, LoadFont(#Gadget_getbook_lbinding, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_binding, 325, 165, 170, 25, "")
        SetGadgetFont(#Gadget_getbook_binding, LoadFont(#Gadget_getbook_binding, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lartist, 5, 200, 100, 20, "Artist", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lartist, LoadFont(#Gadget_getbook_lartist, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_artist, 105, 195, 390, 25, "")
        SetGadgetFont(#Gadget_getbook_artist, LoadFont(#Gadget_getbook_artist, "Arial", 12, 0))
      TextGadget(#Gadget_getbook_lnote, 5, 230, 100, 20, "Note", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lnote, LoadFont(#Gadget_getbook_lnote, "Arial", 12, 0))
      EditorGadget(#Gadget_getbook_note, 105, 225, 390, 230)
        SetGadgetFont(#Gadget_getbook_note, LoadFont(#Gadget_getbook_lnote, "Arial", 12, 0))
      ImageGadget(#Gadget_getbook_booklogo, 30, 405, 48, 48, ImageID(#Image_getbook_booklogo))
      AddGadgetItem(#Gadget_getbook_pmain, -1, "Cover page", ImageID(#Image_getbook_tpicture))
      Frame3DGadget(#Gadget_getbook_fphoto, 0, 0, 505, 465, "")
      TextGadget(#Gadget_getbook_lphoto, 5, 15, 100, 20, "Cover", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lphoto, LoadFont(#Gadget_getbook_lphoto, "Arial", 12, 0))
      ImageGadget(#Gadget_getbook_photologo, 30, 415, 48, 48, ImageID(#Image_getbook_photologo))
      ImageGadget(#Gadget_getbook_photo, 105, 15, 391, 442, ImageID(#Image_getbook_photo))
      ResizeGadget(#Gadget_getbook_photo, 105, 15, 391, 442)
      ResizeImage(#Image_getbook_photo, 391, 442)
      SetGadgetState(#Gadget_getbook_photo, ImageID(#Image_getbook_photo))
      AddGadgetItem(#Gadget_getbook_pmain, -1, "Search history", ImageID(#Image_getbook_thistory))
      Frame3DGadget(#Gadget_getbook_fhistory, 0, 0, 505, 465, "")
      ListIconGadget(#Gadget_getbook_lhistory, 10, 15, 485, 440, "Title", 980, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
        SetGadgetFont(#Gadget_getbook_lhistory, LoadFont(#Gadget_getbook_lhistory, "Arial", 12, 0))
      AddGadgetItem(#Gadget_getbook_pmain, -1, "Retrieval errors", ImageID(#Image_getbook_terrors))
      Frame3DGadget(#Gadget_getbook_ferrors, 0, 0, 505, 465, "")
      ListIconGadget(#Gadget_getbook_lerrors, 10, 15, 485, 440, "Error messages", 980, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
        SetGadgetFont(#Gadget_getbook_lerrors, LoadFont(#Gadget_getbook_lerrors, "Arial", 12, 0))
      CloseGadgetList()
      TextGadget(#Gadget_getbook_lgetisbn, 0, 520, 105, 18, "ISBN to find", #PB_Text_Center)
        SetGadgetFont(#Gadget_getbook_lgetisbn, LoadFont(#Gadget_getbook_lgetisbn, "Arial", 12, 0))
      StringGadget(#Gadget_getbook_getisbn, 105, 513, 314, 25, "")
        SetGadgetFont(#Gadget_getbook_getisbn, LoadFont(#Gadget_getbook_getisbn, "Arial", 12, 0))
      ButtonImageGadget(#Gadget_getbook_save, 421, 500, 40, 40, ImageID(#Image_getbook_save))
      ButtonImageGadget(#Gadget_getbook_exit, 461, 500, 40, 40, ImageID(#Image_getbook_exit))
      CreateStatusBar(#StatusBar_getbook, WindowID(#Window_getbook))
        AddStatusBarField(750)
      HideWindow(#Window_getbook, 0)
      ProcedureReturn WindowID(#Window_getbook)
    EndIf
  EndIf
EndProcedure

;============================================================================================================================
; Structures
;============================================================================================================================
 
Structure bookdetails
  title.s
  author.s
  year.s
  isbn.s
  publisher.s
  price.s
  pages.s
  type.s
  picture.s
  binding.s
  artist.s
EndStructure
 
;============================================================================================================================
; 
;============================================================================================================================
 
Structure programdata
  curdir.s
  cachefile.s
  pictures.s
  quitvalue.l
  header.s
  isbn.s
EndStructure

;============================================================================================================================
; 
;============================================================================================================================
 
Global program.programdata

;============================================================================================================================
; This is the base URL for the IFSDB.ORG book repository. You add the book ISBN number to it
;============================================================================================================================

Program\Header = "http://www.isfdb.org/cgi-bin/rest/getpub.cgi?"

;==============================================================================================================================
; Get current directory and store it for later
;==============================================================================================================================
 
Program\CurDir = Space(512)                                          ; Give the variable enough space
 
If GetCurrentDirectory_(Len(program\curdir), @program\curdir) <> 0   ; Get the current directory
  If Right(program\curdir, 1) <> "\"                                 ; Each O/S does it differently so check for backspace
    program\curdir + "\"
  EndIf
EndIf

;==============================================================================================================================
; Create local cache direcoty
;==============================================================================================================================

Program\CacheFile = Program\CurDir + "Cachedir\CacheFile.xml"

MakeSureDirectoryPathExists_(Program\CacheFile)

;==============================================================================================================================
; Create local cache direcoty
;==============================================================================================================================

Program\Pictures  = Program\CurDir + "Pictures\"

MakeSureDirectoryPathExists_(Program\Pictures)

;============================================================================================================================
; my constants
;============================================================================================================================
 
Enumeration #GadgetIndex
  #Shortcut_getbook_enter
EndEnumeration

;============================================================================================================================
; List and status bar images
;============================================================================================================================
 
Enumeration #ImageIndex                                                   ; Use last image enumeration, continued from visual designer created form
  #Image_getbook_messages
  #Picture_getbook_temp
EndEnumeration

;============================================================================================================================
; Grab the images to memory for use
;============================================================================================================================

CatchImage(#Image_getbook_messages,    ?_PTK_getbook_messages)

;============================================================================================================================
; All processable data in the data section. Have to get your own images:)
;============================================================================================================================

DataSection
  _PTK_getbook_messages    : IncludeBinary "\Development\Resources\Images\messages16x16.ico"
EndDataSection

;============================================================================================================================
; 
;============================================================================================================================
 
Declare   GetFile(URL.s, LocalFile.s)
Declare   GetPage(URL.s)
Declare   DecodeXML(*CurrentNode, CurrentSublevel)
Declare   CheckEnter()
Declare   SaveBookData()                                                ; Append book data to book information file

;============================================================================================================================
; Check if the ENTER key was pressed in the ISBN box and go and get the xml file
;============================================================================================================================
 
Procedure CheckEnter()
  Program\Isbn = GetGadgetText(#Gadget_getbook_getisbn)
  SetGadgetText(#Gadget_getbook_getisbn, "")          ; Clear the field
  GetPage(Program\Header + Program\Isbn)              ; Send the ISBN number and get back the XML data
  FileId.l = LoadXML(#PB_Any, Program\CacheFile)      ; Open the cache file
  If FileId.l                                         ; Did we open it?
    *MainNode = MainXMLNode(FileId.l)                 ; Get the main node of the XML document
    DecodeXML(*MainNode, 0)                           ; Parse the XML file
    CurrentImage.s = GetGadgetText(#Gadget_getbook_picture)
    If CurrentImage.s <> ""
      GetFile(CurrentImage.s, Program\Pictures + GetFilePart(CurrentImage.s))
      If FileSize(Program\Pictures + GetFilePart(CurrentImage.s)) <> -1
        If LoadImage(#Picture_getbook_temp, Program\Pictures +  GetFilePart(CurrentImage.s)) <> 0
          ResizeImage(#Picture_getbook_temp, 391, 442, #PB_Image_Smooth)
          SetGadgetState(#Gadget_getbook_photo, ImageID(#Picture_getbook_temp))
          AddGadgetItem(#Gadget_getbook_lerrors, -1, "Retrieved image loaded for [" + Program\Isbn + "]")
        Else
          AddGadgetItem(#Gadget_getbook_lerrors, -1, "Could not load the image for [" + Program\Isbn + "]")
        EndIf
      Else
        AddGadgetItem(#Gadget_getbook_lerrors, -1, "Picture for [" + Program\Isbn + "] doesn't seem to exist" )
      EndIf
    Else
      AddGadgetItem(#Gadget_getbook_lerrors, -1, "There is no retrievable image for [" + Program\Isbn + "]")
    EndIf
  Else
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Could not retrieve the information for [" + Program\Isbn + "]")
  EndIf
EndProcedure
;============================================================================================================================
; Decode the XML data, recursing through each set of children returned
;============================================================================================================================

Procedure DecodeXML(*CurrentNode, CurrentSublevel)
  If XMLNodeType(*CurrentNode) = #PB_XML_Normal
    *ChildNode = ChildXMLNode(*CurrentNode)
    While *ChildNode <> 0
      nodename.s = GetXMLNodeName(*ChildNode)       ; Returns the tagname of the given XML node
      nodetext.s = GetXMLNodeText(*ChildNode)       ; Returns the text inside the given XML node.
      Select nodename.s
        Case "Records"
          If nodetext.s = "0"
            AddGadgetItem(#Gadget_getbook_lerrors, -1, "There were no records returned for [" + Program\Isbn + "]")
            ProcedureReturn
          EndIf
        Case "Title"      : SetGadgetText(#Gadget_getbook_title,      nodetext.s)
          AddGadgetItem(#Gadget_getbook_lhistory, -1, "Found book [" + GetGadgetText(#Gadget_getbook_title) + "]")
        Case "Author"     : SetGadgetText(#Gadget_getbook_author,     nodetext.s)
        Case "Year"       : SetGadgetText(#Gadget_getbook_year,       nodetext.s)
        Case "Isbn"       : SetGadgetText(#Gadget_getbook_isbn,       nodetext.s)
        Case "Publisher"  : SetGadgetText(#Gadget_getbook_publisher,  nodetext.s)
        Case "Price"      : SetGadgetText(#Gadget_getbook_price,      nodetext.s)
        Case "Pages"      : SetGadgetText(#Gadget_getbook_pages,      nodetext.s)
        Case "Binding"    : SetGadgetText(#Gadget_getbook_binding,    nodetext.s)
        Case "Type"       : SetGadgetText(#Gadget_getbook_type,       nodetext.s)
        Case "Image"      : SetGadgetText(#Gadget_getbook_picture,    nodetext.s)
        Case "Artist"     : SetGadgetText(#Gadget_getbook_artist,     nodetext.s)
        Case "Note"       : SetGadgetText(#Gadget_getbook_note,       nodetext.s)
        Default           : text.s = ""
      EndSelect
;       If nodetext.s <> ""
;         Debug nodetext.s
;       EndIf
      nodetext.s = ""
      DecodeXML(*ChildNode, CurrentSublevel + 1)
      *ChildNode = NextXMLNode(*ChildNode)
    Wend       
 EndIf
EndProcedure

;============================================================================================================================
; Get a file downloaded from a http url
;============================================================================================================================
 
Procedure GetFile(URL.s, LocalFile.s)
  If URLDownloadToFile_(0, URL.s, LocalFile.s, 0, 0) = 0
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Received " + URL.s)
  Else
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Could not receive " + URL.s)
  EndIf
EndProcedure

;============================================================================================================================
; Send the ISBN number to the IFSDB site and get back the xml data containing all the book info
;============================================================================================================================
 
Procedure GetPage(URL.s)
  If URLDownloadToFile_(0, URL.s, Program\CacheFile, 0, 0) = 0
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Received " + Program\CacheFile)
  Else
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Could not receive " + Program\CacheFile)
  EndIf
EndProcedure

;============================================================================================================================
; Append book data to book information file
;============================================================================================================================

Procedure SaveBookData()
  Title.s     = GetGadgetText(#Gadget_getbook_title)      + "|"
  Author.s    = GetGadgetText(#Gadget_getbook_author)     + "|"
  Year.s      = GetGadgetText(#Gadget_getbook_year)       + "|"
  Isbn.s      = GetGadgetText(#Gadget_getbook_isbn)       + "|"
  Publisher.s = GetGadgetText(#Gadget_getbook_publisher)  + "|"
  Price.s     = GetGadgetText(#Gadget_getbook_price)      + "|"
  Pages.s     = GetGadgetText(#Gadget_getbook_pages)      + "|"
  Binding.s   = GetGadgetText(#Gadget_getbook_binding)    + "|"
  Type.s      = GetGadgetText(#Gadget_getbook_type)       + "|"
  Image.s     = GetGadgetText(#Gadget_getbook_picture)    + "|"
  Artist.s    = GetGadgetText(#Gadget_getbook_artist)     + "|"
  Note.s      = GetGadgetText(#Gadget_getbook_note)
  FileId.l = OpenFile(#PB_Any, Program\CurDir + "GetBookXmlData.txt")
  If FileId.l <> 0
    FileSeek(FileId.l, Lof(FileId.l))
    WriteStringN(FileId.l, Title.s + Author.s + Year.s + Isbn.s + Publisher.s + Price.s + Pages.s + Binding.s + Type.s + Image.s + Artist.s + Note.s)
    CloseFile(FileId.l)
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Saved current book data to disk")
  Else
    AddGadgetItem(#Gadget_getbook_lerrors, -1, "Could not save book data to disk")
  EndIf
EndProcedure

;============================================================================================================================
; 
;============================================================================================================================

If Window_getbook()
  AddKeyboardShortcut(#Window_getbook, #PB_Shortcut_Return, #Shortcut_getbook_enter)
  StatusBarIcon(#StatusBar_getbook, #StatusBar_getbook_messages, ImageID(#Image_getbook_messages))
  SendMessage_(GadgetID(#Gadget_getbook_note), #EM_SETTARGETDEVICE, #Null, 0)           ; Set right margin on note box
  SetActiveGadget(#Gadget_getbook_getisbn)
  Program\QuitValue = 0
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        If EventWindow() = #Window_getbook
          Program\QuitValue = 1
        EndIf
      Case #PB_Event_Menu
        Select EventMenu()
          Case #Shortcut_getbook_enter      : CheckEnter()
        EndSelect
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Gadget_getbook_save         : SaveBookData()
          Case #Gadget_getbook_exit
        EndSelect
    EndSelect
  Until Program\QuitValue
  CloseWindow(#Window_getbook)
EndIf
End
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Get book data from IFSDB.ORG

Post by PB »

> This code sends an ISBN book number to IFSDB.ORG

Can anyone here access www.ifsdb.org in their browser? I can't, and I've
tried Firefox, IE, and Opera; all with initial empty caches. Maybe just me?
maw

Re: Get book data from IFSDB.ORG

Post by maw »

PB wrote:Can anyone here access www.ifsdb.org in their browser?
When using www.isfdb.org it works much better :lol:
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Nope, not working. :(

Edit. @maw, now it's working. :lol:
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Get book data from IFSDB.ORG

Post by PB »

> When using www.isfdb.org it works much better

Damn Fangles and his typos! :twisted:
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Bah!

Post by Fangbeast »

The comedians are in my posts again!!!

I needed the laugh though, precious little to laugh about lately.

And for lazy buggers who can't read free code, look for the base address inside the FREE code I put here!! Think of it as providing some work yourselves. :evil: :evil:

/me waits for srod to wade in and insult him again :evil: :evil:

/me waits for some lazy sod to whinge about missing graphics again :evil: :evil:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Bah!

Post by PB »

> look for the base address inside the FREE code I put here

Look for my foot in your ass. :twisted:

Seriously, I didn't bother looking in the code. Sorry mate.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Bah!

Post by Fangbeast »

Look for my foot in your ass. :twisted:
Now how are those short stumps that you call legs going to reach up to my 6 and a half foot ass???
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Bah!

Post by PB »

I have ways. :)
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Re: Bah!

Post by Derek »

Fangbeast wrote: ...my 6 and a half foot ass???
Is that the height or the size around it? :lol: :wink:
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Bah!

Post by Fangbeast »

Derek wrote:
Fangbeast wrote: ...my 6 and a half foot ass???
Is that the height or the size around it? :lol: :wink:
I'm glad you asked for clarification. It's definately the height!! (LOL!!!)

PB had better be scared, if he threatens me again, I will faint on him and at that height, my ass will kill anybody :evil: :evil: :evil:
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

ROFL :lol: :lol:
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Short version of IFSDB.ORG book query

Post by Fangbeast »

Just a short, condensed version of the query I use to get data back from ifsdb.org if anyone wants it. No error checking, do what youw ant to with it.

Code: Select all

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

Structure BookData
  Title.s
  Author.s
  Year.s
  Isbn.s
  Publisher.s
  Price.s
  Pages.s
  Binding.s
  Type.s
  Image.s
  Artist.s
  Note.s
EndStructure

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

Global Books.BookData

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

Procedure DecodeXML(*CurrentNode, CurrentSublevel)
  If XMLNodeType(*CurrentNode) = #PB_XML_Normal
    *ChildNode = ChildXMLNode(*CurrentNode)
    While *ChildNode <> 0
      nodename.s = GetXMLNodeName(*ChildNode)
      nodetext.s = GetXMLNodeText(*ChildNode)
      Select nodename.s
        Case "Records"
          If nodetext.s = "0"
            Debug "There were no records returned for [" + ISBNnumber.s + "]"
            End
          EndIf
        Case "Title"      : Books\Title     = nodetext.s
        Case "Author"     : Books\Author    = nodetext.s
        Case "Year"       : Books\Year      = nodetext.s
        Case "Isbn"       : Books\Isbn      = nodetext.s
        Case "Publisher"  : Books\Publisher = nodetext.s
        Case "Price"      : Books\Price     = nodetext.s
        Case "Pages"      : Books\Pages     = nodetext.s
        Case "Binding"    : Books\Binding   = nodetext.s
        Case "Type"       : Books\Type      = nodetext.s
        Case "Image"      : Books\Image     = nodetext.s
        Case "Artist"     : Books\Artist    = nodetext.s
        Case "Note"       : Books\Note      = nodetext.s
        Default           : nodetext.s = ""
      EndSelect
      nodetext.s = ""
      DecodeXML(*ChildNode, CurrentSublevel + 1)
      *ChildNode = NextXMLNode(*ChildNode)
    Wend       
  EndIf
EndProcedure

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

WebHeader.s   = "http://www.isfdb.org/cgi-bin/rest/getpub.cgi?"               ; IFSDB.org web search header
ISBNnumber.s  = "0552151769"                                                  ; Dan Brown's "Deception Point"
CacheDir.s    = "D:\CacheFile.xml"                                            ; Where to stick the cache file
PictureDir.s  = "D:\"                                                         ; Where to toss covers

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

URLDownloadToFile_(0, WebHeader.s + ISBNnumber.s, CacheDir.s, 0, 0);  = 0

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

FileId.l = LoadXML(#PB_Any, CacheDir.s)

;--------------------------------------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------------------------------------

If FileId.l
  *MainNode = MainXMLNode(FileId.l)
  DecodeXML(*MainNode, 0)
  Debug "Title    " + Books\Title
  Debug "Author   " + Books\Author
  Debug "Year     " + Books\Year
  Debug "Isbn     " + Books\Isbn
  Debug "Publisher" + Books\Publisher
  Debug "Price    " + Books\Price
  Debug "Pages    " + Books\Pages
  Debug "Binding  " + Books\Binding
  Debug "Type     " + Books\Type
  Debug "Image    " + Books\Image
  Debug "Artist   " + Books\Artist
  Debug "Note     " + Books\Note
  If Books\Image <> ""
    URLDownloadToFile_(0, Books\Image, PictureDir.s + GetFilePart(Books\Image), 0, 0); = 0
  EndIf
EndIf

End
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: Short version of IFSDB.ORG book query

Post by thanos »

@Fangbeast
Your code is great!
Thank you to share it.
Regards.

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
Post Reply