Free macro program to help automate recipe import

Everything else that doesn't fall into one of the other PB categories.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

Marc56us wrote:Hi Fangbeast,
The tool is still available, but unfortunately they have put their forum in read-only mode. The program is commercial, but not very expensive ($59), well documented and shareware 30 days (test it before).
:wink:
Don't think we will be spending money on anything except what resembles food this year (Spent enough on property repairs!!)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

NicTheQuick wrote:Qhat about my recipe merge program? Does it work? You did not anser my latest private message.
What private message??? My notifications say 0 messages when I logged in just now.

I also just physically checked and there were no private messages from you in there.
Amateur Radio, D-STAR/VK3HAF
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Free macro program to help automate recipe import

Post by NicTheQuick »

I sent a message to you with a source code that is capable of merging several recipes. There is a bug in purebasic which prevents a valid XML but it should be possible to make the XML valid again by hand. In your answer you did not say anything about that code. Did you try it?
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

NicTheQuick wrote:I sent a message to you with a source code that is capable of merging several recipes. There is a bug in purebasic which prevents a valid XML but it should be possible to make the XML valid again by hand. In your answer you did not say anything about that code. Did you try it?
I haven't received any message about any source code. I'm not that old that I'd forget!! (Even my wife says so)

When did you send it? Last message I had from anyone was on Tuesday, January 8'th from someone (Not you)
Amateur Radio, D-STAR/VK3HAF
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Free macro program to help automate recipe import

Post by NicTheQuick »

It was December 18th and you answered to it but without reacting to the source code. Here it is:
Morning,

I've created the tool to merge the recipe files with Purebasic. But there is a bug in the XML library I try to show to Fred but I was not able to construct an example without using your recipe files. Can I bundle them in a small package and send to Fred so he can take a look why the XMLExport function does its job wrong?

This is my code so far, but the Data.xml file inside the merged recipe file is not valid because there are some characters missing in the end of the file.

Code: Select all

EnableExplicit

UseZipPacker()

Structure Recipe
   file.s
   handle.i
   Map *files()
   content.i
EndStructure

Procedure openRecipe(file.s)
   Protected *recipe.Recipe = AllocateStructure(Recipe)
   Protected filename.s, *buffer, size.i
   
   If Not *recipe
      Debug "Could not allocate memory"
      ProcedureReturn #False
   EndIf

   With *recipe
      \handle = OpenPack(#PB_Any, file, #PB_PackerPlugin_Zip)
      \file = file
      
      If Not \handle
         Debug "Could not open zip"
         Goto error
      EndIf
      
      If Not ExaminePack(\handle)
         Debug "Could not examine zip"
         Goto error
      EndIf
         
      While NextPackEntry(\handle)
         filename = PackEntryName(\handle)
         size = PackEntrySize(\handle, #PB_Packer_UncompressedSize)

         If PackEntryType(\handle) = #PB_Packer_File
            *buffer = 0
            If size > 0
               *buffer = AllocateMemory(size)
               If Not *buffer
                  Debug "Could not allocate memory for " + filename
                  Goto error
               EndIf
               If size <> UncompressPackMemory(\handle, *buffer, size)
                  Debug "Could not unpack file: " + filename
                  Goto error
               EndIf
            EndIf
         Else
            *buffer = -1
         EndIf
         \files(filename) = *buffer
         
         If filename = "Data.xml"
            If size = 0 Or Not *buffer
               Debug filename + " is empty"
               Goto error
            EndIf
            \content = CatchXML(#PB_Any, *buffer, size)
         EndIf
      Wend
   
   EndWith
   
   ProcedureReturn *recipe
   
   error:
   FreeStructure(*recipe)
   If *buffer
      FreeMemory(*buffer)
   EndIf
   
   ProcedureReturn #False
EndProcedure

Procedure getNodeByTag(xmlNode.i)
   
EndProcedure

Procedure mergeRecipes(file.s, List *recipes.Recipe())
   Protected i.i, j.i, *hixz, *node, name.s, *recipesNode, *recipeNode, *sourceImageNode, *recipeImagesNode, *recipeImageNode
   Protected imageCounter.i = 0, oldImage.s, newImage.s
   
   ; Neuen ZIP-Container erstellen
   Protected *mZip = CreatePack(#PB_Any, file, #PB_PackerPlugin_Zip)
   
   ; Create new Data.xml
   Protected *mData = CreateXML(#PB_Any, #PB_UTF8)
   Protected *mHixz = CreateXMLNode(RootXMLNode(*mData), "hixz")
   SetXMLAttribute(*mHixz, "Source", "Merged Cookbook")
   SetXMLAttribute(*mHixz, "FileVersion", "1.0")
   SetXMLAttribute(*mHixz, "date", FormatDate("%yyyy-%mm-%ss", Date()))
   Protected *mCookbooks = CreateXMLNode(*mHixz, "Cookbooks")
   Protected *mCookbookChapters = CreateXMLNode(*mHixz, "CookbookChapters")
   Protected *mRecipes = CreateXMLNode(*mHixz, "Recipes")

   ; Create new Manifest.xml
   Protected *mManifest = CreateXML(#PB_Any, #PB_UTF8)
   Protected *mFdxm = CreateXMLNode(RootXMLNode(*mManifest), "fdxm")
   SetXMLAttribute(*mFdxm, "Source", "Merged Cookbook")
   SetXMLAttribute(*mFdxm, "FileVersion", "1.0")
   SetXMLAttribute(*mFdxm, "date", FormatDate("%yyyy-%mm-%ss", Date()))
   Protected *mFiles = CreateXMLNode(*mFdxm, "Files")
   Protected *mFile
   
   ForEach *recipes()
      With *recipes()
         *recipesNode = XMLNodeFromPath(RootXMLNode(\content), "/hixz/Recipes")
         
         If Not *recipesNode
            Debug \file + ": <recipes> not found."
            Continue
         EndIf
         
         For i = 1 To XMLChildCount(*recipesNode)
            *recipeNode = ChildXMLNode(*recipesNode, i)
            
            *sourceImageNode = XMLNodeFromPath(*recipeNode, "SourceImage")
            If *sourceImageNode
               oldImage = GetXMLAttribute(*sourceImageNode, "FileName")
               newImage = "image" + imageCounter + "." + GetExtensionPart(oldImage)
               imageCounter + 1
               
               If FindMapElement(\files(), "Images/" + oldImage)
                  \files("Images/" + newImage) = \files("Images/" + oldImage)
                  DeleteMapElement(\files(), "Images/" + oldImage)
               EndIf
               
               SetXMLAttribute(*sourceImageNode, "FileName", newImage)
               
               *mFile = CreateXMLNode(*mFiles, "File")
               SetXMLAttribute(*mFile, "FileName", newImage)
               SetXMLAttribute(*mFile, "OriginalFileName", GetXMLAttribute(*sourceImageNode, "OriginalFileName"))
               
               AddPackMemory(*mZip, \files("Images/" + newImage), MemorySize(\files("Images/" + newImage)), "Images/" + newImage)
            EndIf

            *recipeImagesNode = XMLNodeFromPath(*recipeNode, "RecipeImages")
            If *recipeImagesNode
               For j = 1 To XMLChildCount(*recipeImagesNode)
                  *recipeImageNode = ChildXMLNode(*recipeImagesNode, j)
                  
                  oldImage = GetXMLAttribute(*recipeImageNode, "FileName")
                  newImage = "image" + imageCounter + "." + GetExtensionPart(oldImage)
                  imageCounter + 1
                  
                  If FindMapElement(\files(), "Images/" + oldImage)
                     \files("Images/" + newImage) = \files("Images/" + oldImage)
                     DeleteMapElement(\files(), "Images/" + oldImage)
                  EndIf
                  
                  SetXMLAttribute(*recipeImageNode, "FileName", newImage)
                  
                  *mFile = CreateXMLNode(*mFiles, "File")
                  SetXMLAttribute(*mFile, "FileName", newImage)
                  SetXMLAttribute(*mFile, "OriginalFileName", GetXMLAttribute(*recipeImageNode, "OriginalFileName"))
                  
                  AddPackMemory(*mZip, \files("Images/" + newImage), MemorySize(\files("Images/" + newImage)), "Images/" + newImage)
               Next
            EndIf
            
            CopyXMLNode(*recipeNode, *mRecipes)
         Next
      EndWith
   Next
   
   Protected size.i, *buffer
   
   ;FormatXML(*mData, #PB_XML_ReduceSpace | #PB_XML_CutSpace | #PB_XML_ReduceNewline | #PB_XML_CutNewline | #PB_XML_LinuxNewline)
   size = ExportXMLSize(*mData, #PB_XML_NoDeclaration)
   Debug size
   *buffer = AllocateMemory(size)
   If ExportXML(*mData, *buffer, size, #PB_XML_NoDeclaration)
      Debug PeekS(*buffer, size, #PB_UTF8)
      AddPackMemory(*mZip, *buffer, size, "Data.xml")
      FreeMemory(*buffer)
   EndIf
   
   size = ExportXMLSize(*mManifest)
   *buffer = AllocateMemory(size)
   If ExportXML(*mManifest, *buffer, size)
      AddPackMemory(*mZip, *buffer, size, "Manifest.xml")
      FreeMemory(*buffer)
   EndIf

   
   ClosePack(*mZip)
   
EndProcedure

NewList *recipes.Recipe()

; This directory should only contain the fdxz files
Define dir.s = "/home/nicolas/tmp/purebasic/Recipes/"

; This is the new merged recipes file
Define target.s = "/home/nicolas/tmp/purebasic/Recipes/merged.zip"

; First read all recipes into Memory
If ExamineDirectory(0, dir, "*.fdxz")
   While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
         If AddElement(*recipes())
            *recipes() = openRecipe(dir + DirectoryEntryName(0))
         EndIf
      EndIf
   Wend
EndIf

mergeRecipes(target, *recipes())
And this is the related bug report: viewtopic.php?f=23&t=71938
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

NicTheQuick, oh dear, I honestly don't remember seeing that in a private message. Wonder how that got past me???

Would have tried it immediately if I had seen it.

Must be ghosts in the PB form (Or as srod would say, goats ate my brain)

But if the characters are invalid, what good is it testing the code? (Honest question). I wouldn't even know how to fix that.
Amateur Radio, D-STAR/VK3HAF
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Free macro program to help automate recipe import

Post by NicTheQuick »

Maybe I can fix the code with a workaround mentioned in the bug report I linked in my previous post. Unfortunality the bug got not fixed with the latest PB version.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

NicTheQuick wrote:Maybe I can fix the code with a workaround mentioned in the bug report I linked in my previous post. Unfortunality the bug got not fixed with the latest PB version.
Wait a short while. It hit 41 degrees yesterday and we could barely function. We just got back from shopping and it's already 28 and the weather bureau cannot seem to get it right. I need to say away from this hot room.
Amateur Radio, D-STAR/VK3HAF
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: Free macro program to help automate recipe import

Post by C87 »

:o Wow, 10,000 recipes!....I probably may use two or three a week and often one I've used before.
It would take me 600 years to try them all...........are any of them life extending? :D
If it's falling over......just remember the computer is never wrong!
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

C87 wrote::o Wow, 10,000 recipes!....I probably may use two or three a week and often one I've used before.
It would take me 600 years to try them all...........are any of them life extending? :D
I actually have over 600,000 but 10,000 of those happen to be Living Cookbook fdxz:)

As far as life extending, I have it on good authority that if you cook every one of my 600,000 recipes, you will have gotten your exercise and thus extended your life:):)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Free macro program to help automate recipe import

Post by Fangbeast »

More and more recipes every day bit it hit 36 today and it is supposed to hit over 40 by Friday. I really can't think in this heat.
Amateur Radio, D-STAR/VK3HAF
Post Reply