From c869bb43c22865c0217165f4411cd46eec66f5ed Mon Sep 17 00:00:00 2001 From: yuriy Date: Mon, 3 Apr 2023 00:28:23 -0400 Subject: [PATCH] updated shared functions submodule and added Locals URL check and version bump --- Freedomain Social Media Poster.ahk | 135 ++++++++---------------- Lib/Freedomain-Posters-Shared-Functions | 2 +- 2 files changed, 44 insertions(+), 93 deletions(-) diff --git a/Freedomain Social Media Poster.ahk b/Freedomain Social Media Poster.ahk index 0eb7e4f..5235fed 100644 --- a/Freedomain Social Media Poster.ahk +++ b/Freedomain Social Media Poster.ahk @@ -40,7 +40,7 @@ global UpdateVersionNumber ScriptName = Freedomain Social Media Poster -ScriptVersion = 2.76 +ScriptVersion = 2.77 FullScriptName := ScriptName . " " . ScriptVersion ;---ToDo--- @@ -2378,6 +2378,7 @@ CurrentSite := "Locals" ; @todo: Add auto-login to locals SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + IniRead, LocalsURL, %SettingsIniFilepath%, %ScriptSettingsSection%, LocalsURL, %A_Space% if(LocalsURL = ""){ Message = Please add your Locals Profile URL to the settings.ini file under`n`n[General]`nLocalsURL= @@ -2385,8 +2386,18 @@ if(LocalsURL = ""){ Return } -; Message = LocalsURL from Ini File: %LocalsURL% -; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + +Message = LocalsURL from Ini File: %LocalsURL% +SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + +if(!InStr(LocalsURL, "/share/post")){ + LocalsURL = https://freedomain.locals.com/share/post + + Message = LocalsURL from ini file was incorrect. New URL set to %LocalsURL% and saved to settings.ini + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + + IniWrite, %LocalsURL%, %SettingsIniFilepath%, %ScriptSettingsSection%, LocalsURL +} ; LocalsURL := StrReplace(Localsurl, "/share/post", "") ; LocalsURL := Localsurl . "/login" @@ -2413,109 +2424,49 @@ if(InStr(CurrentTabURL, "/login") OR InStr(CurrentTabURL, "/register")){ Return } -; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") -; Xpath = //textarea[@id='body'] -; Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=2000) -; if(Status){ - ; Message = Trying to Log Back In - ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - - ; LocalsLoginURL := LocalsURL . "/login" - ; try driver.Get(LocalsLoginURL) ;Open selected URL - ; try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding - - ; sleep, 3000 - ; js = document.getElementsByName('submit')[0].click(); - ; try driver.executeScript(js) - ; ; DevModeMsgBox(js) - ; ; clipboard := js - - ; try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding - ; sleep, 5000 - ; ; try driver.Get(LocalsURL) ;Open selected URL - ; ; try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding - - ; Xpath = //textarea[@id='body'] - ; Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000) - ; { - ; Message = Post Failed: Check Login Status - ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") - ; Return - ; } - -/* Message = Post Failed: Check Login Status - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") - SaveDriverURLOFErrorPage() - Return - - Message = Page did not load after 30 seconds. Force stopping refresh and trying to continue - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - - send, {Escape} ; Temporary workaround, as Page seems to endlessly load for Stef - - Xpath = //textarea[@id='body'] - Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) - if(Status){ - SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") - - - Return - } - */ - ; } - Message = Inputting Post Content - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") +Message = Inputting Post Content +SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") - Xpath = //*[@id="body"] - try driver.FindElementByXPath(Xpath).click() - Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody) - if(Status){ - Message = Failed to input Title - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - SaveDriverURLOFErrorPage() - Return - } +Xpath = //*[@id="body"] +try driver.FindElementByXPath(Xpath).click() +Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody) +if(Status){ + Message = Failed to input Title + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + SaveDriverURLOFErrorPage() + Return +} - ; sleep, 1000 -/* Xpath = //textarea[@id='body'] - Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostBody) - if(Status){ - Message = Failed to Input Post Body - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - SaveDriverURLOFErrorPage() - Return - } - */ - if(ImageAttachmentFilepath != ""){ - ; Click the upload image button - SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile") +if(ImageAttachmentFilepath != ""){ + ; Click the upload image button + SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile") - Xpath = //input[@multiple='multiple'] - Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath) - if(Status){ - Message = Failed to Upload Image - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") - SaveDriverURLOFErrorPage() - Return - } - ; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath) - ; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath) + Xpath = //input[@multiple='multiple'] + Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath) + if(Status){ + Message = Failed to Upload Image + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + SaveDriverURLOFErrorPage() + Return + } + ; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath) + ; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath) - SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile") + SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile") - sleep, 10000 - } - Message = Submitting Post - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") + sleep, 10000 +} +Message = Submitting Post +SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") diff --git a/Lib/Freedomain-Posters-Shared-Functions b/Lib/Freedomain-Posters-Shared-Functions index 8a4c74f..3f559f2 160000 --- a/Lib/Freedomain-Posters-Shared-Functions +++ b/Lib/Freedomain-Posters-Shared-Functions @@ -1 +1 @@ -Subproject commit 8a4c74ffafc09cdc5c7eebca06e4e9da2a71e79c +Subproject commit 3f559f2f81da580263ffcc72795c30f8c89a1603