Get book data from Amazon server via ISBN number
Posted: Fri Feb 27, 2009 6:36 am
Code: Select all
;=============================================================================================================
; I needed to get book results from Amazon and with some help in an initial program from srod, Thorsten, ideas
; from an IRC book channel and sheer grunt, I cobbled the following up. Be warned that it may not suit you,
; be ugly as hell, bad coding etc but it does what i want and need so change it to suit yourself.
;
; 1. You need to get yourself a free security key from Amazon security services to make these REST requests.
; That is beyond the scope of this document to explain. (Code won't work without it!!)
;
; 2. I search only by ISBN numbers, that's all I wanted. Searching by strings gives farf more results than I
; wanted to deal with. ISBN searches are more accurate.
;
; 2. Get your your images you lazy sods!!
;
; 3. Do what you want with this, it's free. But don't complain to me about it if you don't like it, fix it!
;
;=============================================================================================================
; Initialise the network.
;=============================================================================================================
InitNetwork()
;============================================================================================================================
; Initialise the JPEG image decoder.
;============================================================================================================================
UseJPEGImageDecoder()
;=============================================================================================================
; Form designer created variables.
;=============================================================================================================
Enumeration 1
#Window_getbook
EndEnumeration
#WindowIndex = #PB_Compiler_EnumerationValue
Enumeration 1
#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_dewey
#Gadget_getbook_ldewey
#Gadget_getbook_lean
#Gadget_getbook_ean
#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_binding
#Gadget_getbook_lartist
#Gadget_getbook_artist
#Gadget_getbook_note
#Gadget_getbook_booklogo
#Gadget_getbook_fcover
#Gadget_getbook_cover
#Gadget_getbook_fmessages
#Gadget_getbook_messages
#Gadget_getbook_fcontrol
#Gadget_getbook_lgetisbn
#Gadget_getbook_getisbn
#Gadget_getbook_save
#Gadget_getbook_exit
EndEnumeration
#GadgetIndex = #PB_Compiler_EnumerationValue
Enumeration 1
#StatusBar_getbook
EndEnumeration
#StatusBarIndex = #PB_Compiler_EnumerationValue
#StatusBar_getbook_messages = 0
Enumeration 1
#Image_getbook_booklogo
#Image_getbook_cover
#Image_getbook_save
#Image_getbook_exit
EndEnumeration
#ImageIndex = #PB_Compiler_EnumerationValue
;=============================================================================================================
; Form designer created variables.
;=============================================================================================================
CatchImage(#Image_getbook_booklogo, ?_OPT_getbook_booklogo)
CatchImage(#Image_getbook_cover, ?_OPT_getbook_cover)
CatchImage(#Image_getbook_save, ?_OPT_getbook_save)
CatchImage(#Image_getbook_exit, ?_OPT_getbook_exit)
;=============================================================================================================
; Form designer created variables.;
;=============================================================================================================
DataSection
_OPT_getbook_booklogo : IncludeBinary "Images\book48x48.ico"
_OPT_getbook_cover : IncludeBinary "Images\nopicture2.jpg"
_OPT_getbook_save : IncludeBinary "Images\save32x32.ico"
_OPT_getbook_exit : IncludeBinary "Images\exit32x32.ico"
EndDataSection
;=============================================================================================================
; Form designer created windows code.
;=============================================================================================================
Procedure.l Window_getbook()
If OpenWindow(#Window_getbook, 47, 77, 800, 600, "Get book details from www.ifsdb.org", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
Frame3DGadget(#Gadget_getbook_fdetails, 0, 0, 505, 325, "")
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))
StringGadget(#Gadget_getbook_dewey, 105, 105, 105, 25, "")
SetGadgetFont(#Gadget_getbook_dewey, LoadFont(#Gadget_getbook_dewey, "Arial", 12, 0))
TextGadget(#Gadget_getbook_ldewey, 5, 110, 100, 20, "Dewey", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_ldewey, LoadFont(#Gadget_getbook_ldewey, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lean, 215, 110, 55, 20, "EAN", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lean, LoadFont(#Gadget_getbook_lean, "Arial", 12, 0))
StringGadget(#Gadget_getbook_ean, 270, 105, 225, 25, "")
SetGadgetFont(#Gadget_getbook_ean, LoadFont(#Gadget_getbook_ean, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lpublisher, 5, 140, 100, 20, "Publisher", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lpublisher, LoadFont(#Gadget_getbook_lpublisher, "Arial", 12, 0))
StringGadget(#Gadget_getbook_publisher, 105, 135, 390, 25, "")
SetGadgetFont(#Gadget_getbook_publisher, LoadFont(#Gadget_getbook_publisher, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lprice, 5, 170, 100, 20, "Price", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lprice, LoadFont(#Gadget_getbook_lprice, "Arial", 12, 0))
StringGadget(#Gadget_getbook_price, 105, 165, 75, 25, "")
SetGadgetFont(#Gadget_getbook_price, LoadFont(#Gadget_getbook_price, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lpages, 185, 170, 60, 20, "Pages", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lpages, LoadFont(#Gadget_getbook_lpages, "Arial", 12, 0))
StringGadget(#Gadget_getbook_pages, 245, 165, 75, 25, "")
SetGadgetFont(#Gadget_getbook_pages, LoadFont(#Gadget_getbook_pages, "Arial", 12, 0))
TextGadget(#Gadget_getbook_ltype, 325, 170, 55, 20, "Type", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_ltype, LoadFont(#Gadget_getbook_ltype, "Arial", 12, 0))
StringGadget(#Gadget_getbook_type, 380, 165, 115, 25, "")
SetGadgetFont(#Gadget_getbook_type, LoadFont(#Gadget_getbook_type, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lpicture, 5, 200, 100, 20, "Picture", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lpicture, LoadFont(#Gadget_getbook_lpicture, "Arial", 12, 0))
StringGadget(#Gadget_getbook_picture, 105, 195, 140, 25, "")
SetGadgetFont(#Gadget_getbook_picture, LoadFont(#Gadget_getbook_picture, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lbinding, 245, 200, 80, 20, "Binding", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lbinding, LoadFont(#Gadget_getbook_lbinding, "Arial", 12, 0))
StringGadget(#Gadget_getbook_binding, 325, 195, 170, 25, "")
SetGadgetFont(#Gadget_getbook_binding, LoadFont(#Gadget_getbook_binding, "Arial", 12, 0))
TextGadget(#Gadget_getbook_lartist, 5, 230, 100, 20, "Artist", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lartist, LoadFont(#Gadget_getbook_lartist, "Arial", 12, 0))
StringGadget(#Gadget_getbook_artist, 105, 225, 390, 25, "")
SetGadgetFont(#Gadget_getbook_artist, LoadFont(#Gadget_getbook_artist, "Arial", 12, 0))
EditorGadget(#Gadget_getbook_note, 105, 255, 390, 60)
ImageGadget(#Gadget_getbook_booklogo, 30, 265, 48, 48, ImageID(#Image_getbook_booklogo))
Frame3DGadget(#Gadget_getbook_fcover, 510, 0, 290, 325, "")
ImageGadget(#Gadget_getbook_cover, 515, 10, 277, 307, ImageID(#Image_getbook_cover), #PB_Image_Border)
ResizeGadget(#Gadget_getbook_cover, 515, 10, 277, 307)
ResizeImage(#Image_getbook_cover, 277, 307)
SetGadgetState(#Gadget_getbook_cover, ImageID(#Image_getbook_cover))
Frame3DGadget(#Gadget_getbook_fmessages, 0, 325, 800, 190, "")
ListIconGadget(#Gadget_getbook_messages, 5, 340, 790, 170, "Error messages", 786, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
SetGadgetFont(#Gadget_getbook_messages, LoadFont(#Gadget_getbook_messages, "Arial", 12, 0))
Frame3DGadget(#Gadget_getbook_fcontrol, 0, 515, 800, 65, "")
TextGadget(#Gadget_getbook_lgetisbn, 0, 550, 105, 18, "ISBN to find", #PB_Text_Center)
SetGadgetFont(#Gadget_getbook_lgetisbn, LoadFont(#Gadget_getbook_lgetisbn, "Arial", 12, 0))
StringGadget(#Gadget_getbook_getisbn, 105, 543, 599, 25, "")
SetGadgetFont(#Gadget_getbook_getisbn, LoadFont(#Gadget_getbook_getisbn, "Arial", 12, 0))
ButtonImageGadget(#Gadget_getbook_save, 711, 530, 40, 40, ImageID(#Image_getbook_save))
ButtonImageGadget(#Gadget_getbook_exit, 751, 530, 40, 40, ImageID(#Image_getbook_exit))
CreateStatusBar(#StatusBar_getbook, WindowID(#Window_getbook))
AddStatusBarField(800)
HideWindow(#Window_getbook, 0)
ProcedureReturn WindowID(#Window_getbook)
EndIf
EndProcedure
;============================================================================================================================
; Structures
;============================================================================================================================
Structure BookDetails
MainImage.s ;
Author.s ;
Binding.s ;
Dewey.s ;
EAN.s ;
Format.s ;
ISBN.s ;
Label.s ;
Language.s ;
Currency.s ;
Price.s ;
Manufacturer.s ;
Pages.s ;
ProductGroup.s ;
Published.s ;
Publisher.s ;
Studio.s ;
Title.s ;
Note.s ;
EndStructure
;============================================================================================================================
;
;============================================================================================================================
Structure ProgramData
CurDir.s ;
CacheFile.s ;
Pictures.s ;
QuitValue.i ;
Isbn.s ;
EndStructure
;============================================================================================================================
; My personal variables
;============================================================================================================================
Global Program.ProgramData, MySecureKey.s
;============================================================================================================================
; Put in your Amazon developer secure key, won't get results without it.
;============================================================================================================================
MySecureKey.s = "WhateverMyKeyIs"
;==============================================================================================================================
; Get current directory and store it for later
;==============================================================================================================================
Program\CurDir = GetCurrentDirectory()
;==============================================================================================================================
; Create local XML cache direcoty
;==============================================================================================================================
Program\CacheFile = Program\CurDir + "Cachedir\CacheFile.xml"
MakeSureDirectoryPathExists_(Program\CacheFile)
;==============================================================================================================================
; Create local picture directory
;==============================================================================================================================
Program\Pictures = Program\CurDir + "Pictures\"
MakeSureDirectoryPathExists_(Program\Pictures)
;============================================================================================================================
; My personal constants
;============================================================================================================================
Enumeration #GadgetIndex ; Use last gadget enumeration, continued from visual designer created form
#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 "Images\messages16x16.ico"
EndDataSection
;============================================================================================================================
; Procedural declarations
;============================================================================================================================
Declare GetFile(URL.s, LocalFile.s) ; Get a file downloaded from a http url and rename to a local file
Declare GetPage(URL.s, MySecureKey.s) ; Send the ISBN number to the IFSDB site and get back the xml data containing all the book info
Declare DecodeXML(*MainNode) ; Decode the XML data, grabbing only what you are interested in.
Declare CheckEnter() ; Check if the ENTER key was pressed in the ISBN box and go and get the xml file
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()
; Get the ISBN number after the user presses ENTER/RETURN
Program\Isbn = GetGadgetText(#Gadget_getbook_getisbn)
; Clear the field
SetGadgetText(#Gadget_getbook_getisbn, "")
; Let the user know what is going on
AddGadgetItem(#Gadget_getbook_messages, -1, "Attempting to fetch [" + Program\Isbn + "] details from Ifsdb.org")
; Send the ISBN number and get back the XML data
GetPage(Program\Isbn, MySecureKey.s)
; Open the cache file and parse only the bits that youw ant
FileId.i = LoadXML(#PB_Any, Program\CacheFile)
; Did we get a file handle?
If FileId.i
; Get the main node of the XML document
*MainNode = MainXMLNode(FileId.i)
; Parse the XML file
DecodeXML(*MainNode)
; See if a cover page was in the XML document and fetch it
CurrentImage.s = GetGadgetText(#Gadget_getbook_picture)
; Was there a referenced image?
If CurrentImage.s <> ""
; Give the new name of the picture as it will be in the local picture directory
NewName.s = Program\Pictures + GetGadgetText(#Gadget_getbook_title) + "." + GetExtensionPart(CurrentImage.s)
; Fetch the picture from the picture site
GetFile(CurrentImage.s, NewName.s)
; Did we get a picture file downloaded?
If FileSize(NewName.s) <> -1
; Attempt to laod the picture into the cover image gadget
If LoadImage(#Picture_getbook_temp, NewName.s) <> 0
; Resize the image to fit the cover image gadget
ResizeImage(#Picture_getbook_temp, 277, 307, #PB_Image_Smooth)
; Now set the resized image to the gadget
SetGadgetState(#Gadget_getbook_cover, ImageID(#Picture_getbook_temp))
; Let the user know what is going on
AddGadgetItem(#Gadget_getbook_messages, -1, "Managed to load image for [" + Program\Isbn + "]")
; Otherwise handle the error below
Else
; We could not load the retrieved image for display
AddGadgetItem(#Gadget_getbook_messages, -1, "Could not load the image for [" + Program\Isbn + "]")
; No more tests to make at this run level
EndIf
; We didn't get a cover page fetched back, handle the error below
Else
; Let the user know what the error was
AddGadgetItem(#Gadget_getbook_messages, -1, "Picture for [" + Program\Isbn + "] doesn't seem to exist" )
; No more tests to make at this run level
EndIf
; There was no image reference
Else
; Let the user know there was no image reference in the XML
AddGadgetItem(#Gadget_getbook_messages, -1, "There is no retrievable image for [" + Program\Isbn + "]")
; No more tests to make at this run level
EndIf
; There was no picture information retrieved from the XML file, handle the error below
Else
; Let the user know there was no picture information
AddGadgetItem(#Gadget_getbook_messages, -1, "Could not retrieve the information for [" + Program\Isbn + "]")
; No more tests to make at this run level
EndIf
; Just add a delimiting line between error message lots
AddGadgetItem(#Gadget_getbook_messages, -1, "----------------------------------------")
;
EndProcedure
;============================================================================================================================
; Decode the XML data, grabbing only what you are interested in.
;============================================================================================================================
Procedure DecodeXML(*MainNode)
; Check if this XML file request was a valid one
*Node = XMLNodeFromPath(*MainNode, "Items/Request/IsValid")
; If the request was valid, go and fetch the rest of the data
If GetXMLNodeText(*Node) = "True"
; Get the large image link
*Node = XMLNodeFromPath(*MainNode, "Items/Item/LargeImage/URL")
If *Node
SetGadgetText(#Gadget_getbook_picture, GetXMLNodeText(*Node))
EndIf
; Get the author
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Author")
If *Node
SetGadgetText(#Gadget_getbook_author, GetXMLNodeText(*Node))
EndIf
; Get the binding type
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Binding")
If *Node
SetGadgetText(#Gadget_getbook_binding, GetXMLNodeText(*Node))
EndIf
; Get the Dewey Decimal number
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/DeweyDecimalNumber")
If *Node
SetGadgetText(#Gadget_getbook_dewey, GetXMLNodeText(*Node))
EndIf
; Get the EAN number
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/EAN")
If *Node
SetGadgetText(#Gadget_getbook_ean, GetXMLNodeText(*Node))
EndIf
; Get the bok format
; *Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Format")
; If *Node
; SetGadgetText(GetXMLNodeText(*Node))
; EndIf
; Get the ISBN number
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/ISBN")
If *Node
SetGadgetText(#Gadget_getbook_isbn, GetXMLNodeText(*Node))
EndIf
; Get the Label
; *Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Label")
; If *Node
; SetGadgetText(GetXMLNodeText(*Node))
; EndIf
; Get the main language
; *Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Languages/Language/Name")
; If *Node
; SetGadgetText(GetXMLNodeText(*Node))
; EndIf
; Get the currency code (AUD,AUS,EUC,EURO)
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/ListPrice/CurrencyCode")
If *Node
Currency.s = GetXMLNodeText(*Node)
EndIf
; Get the formatted display price
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/ListPrice/FormattedPrice")
If *Node
SetGadgetText(#Gadget_getbook_price, GetXMLNodeText(*Node) + Currency)
EndIf
; Get the book manufacturer
; *Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Manufacturer")
; If *Node
; SetGadgetText(GetXMLNodeText(*Node))
; EndIf
; Get the number of pages
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/NumberOfPages")
If *Node
SetGadgetText(#Gadget_getbook_pages, GetXMLNodeText(*Node))
EndIf
; Get the product group (Book, Video, Magazine, Comic etc)
; *Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/ProductGroup")
; If *Node
; SetGadgetText(GetXMLNodeText(*Node))
; EndIf
; Get the publication date
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/PublicationDate")
If *Node
SetGadgetText(#Gadget_getbook_year, GetXMLNodeText(*Node))
EndIf
; Get the publisher
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Publisher")
If *Node
SetGadgetText(#Gadget_getbook_publisher, GetXMLNodeText(*Node))
EndIf
; Get the design studio
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Studio")
If *Node
SetGadgetText(#Gadget_getbook_artist, GetXMLNodeText(*Node))
EndIf
; Get the book title
*Node = XMLNodeFromPath(*MainNode, "Items/Item/ItemAttributes/Title")
If *Node
SetGadgetText(#Gadget_getbook_title, GetXMLNodeText(*Node))
EndIf
;
EndIf
;
EndProcedure
;============================================================================================================================
; Get a file downloaded from a http url and rename to a local file
;============================================================================================================================
Procedure GetFile(URL.s, LocalFile.s)
;
If ReceiveHTTPFile(URL.s, LocalFile.s)
;
AddGadgetItem(#Gadget_getbook_messages, -1, "Received " + URL.s)
;
Else
;
AddGadgetItem(#Gadget_getbook_messages, -1, "Could not receive " + URL.s)
;
EndIf
;
EndProcedure
;============================================================================================================================
; Send the ISBN number to the Amazon server and get back the xml data containing all the book info
;============================================================================================================================
Procedure GetPage(ISBN.s, MySecureKey.s)
; I've separated the various parts of the request so you can see them and rearrange them for other
; requests in your own programs.
URLString.s = "http://ecs.amazonaws.com/onca/xml?"
URLString.s + "Service=AWSECommerceService"
URLString.s + "&AWSAccessKeyId=" + MySecureKey.s ; Don't forget to get your own security key
URLString.s + "&Operation=ItemLookup"
URLString.s + "&IdType=ISBN"
URLString.s + "&SearchIndex=Books"
URLString.s + "&ItemId=" + ISBN.s
URLString.s + "&ResponseGroup=Images,ItemAttributes"
;
If ReceiveHTTPFile(URLString.s, Program\CacheFile)
;
AddGadgetItem(#Gadget_getbook_messages, -1, "Received " + Program\CacheFile)
;
Else
;
AddGadgetItem(#Gadget_getbook_messages, -1, "Could not receive " + Program\CacheFile)
;
EndIf
;
EndProcedure
;============================================================================================================================
; Append book data to book information file
;============================================================================================================================
Procedure SaveBookData()
; Grab the data, add your own delimiter. I prefer this one "|"
Title.s = GetGadgetText(#Gadget_getbook_title) + "|"
Author.s = GetGadgetText(#Gadget_getbook_author) + "|"
Year.s = GetGadgetText(#Gadget_getbook_year) + "|"
Isbn.s = GetGadgetText(#Gadget_getbook_isbn) + "|"
Dewey.s = GetGadgetText(#Gadget_getbook_dewey) + "|"
EAN.s = GetGadgetText(#Gadget_getbook_ean) + "|"
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.i = OpenFile(#PB_Any, Program\CurDir + "GetBookXmlData.txt")
;
If FileId.i <> 0
;
FileSeek(FileId.i, Lof(FileId.i))
;
WriteStringN(FileId.i, Title.s + Author.s + Year.s + Isbn.s + Dewey.s + EAN.s + Publisher.s + Price.s + Pages.s + Binding.s + Type.s + Image.s + Artist.s + Note.s)
;
CloseFile(FileId.i)
;
AddGadgetItem(#Gadget_getbook_messages, -1, "Saved " + Title.s + " data to disk")
;
Else
;
AddGadgetItem(#Gadget_getbook_messages, -1, "Could not save " + Title.s + " data to disk")
;
EndIf
;
EndProcedure
;============================================================================================================================
;
;============================================================================================================================
If Window_getbook()
; Add the ENTER/RETURN key shortcut to the window
AddKeyboardShortcut(#Window_getbook, #PB_Shortcut_Return, #Shortcut_getbook_enter)
; Add any statusbar images
StatusBarImage(#StatusBar_getbook, #StatusBar_getbook_messages, ImageID(#Image_getbook_messages))
; Set right margin on note box
SendMessage_(GadgetID(#Gadget_getbook_note), #EM_SETTARGETDEVICE, #Null, 0)
; Set focus to the ISBN search box
SetActiveGadget(#Gadget_getbook_getisbn)
; Set initial program quit value
Program\QuitValue = 0
; Check for window and gadgete events
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Window_getbook : Program\QuitValue = 1
EndSelect
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 : Program\QuitValue = 1
EndSelect
EndSelect
Until Program\QuitValue
CloseWindow(#Window_getbook)
EndIf
End