From 1874689568732442487dd629cd6d8f5bdde5a3b7 Mon Sep 17 00:00:00 2001 From: Yuriy Date: Thu, 4 Jul 2024 00:18:26 -0400 Subject: [PATCH] added tumblr support, fixed Telegram Posting showing error when post succeeded, code cleanup --- Modules/Miscellaneous-Functions.ahk | 2 +- Modules/Post-To-Discord.ahk | 9 +- Modules/Post-To-Telegram.ahk | 9 +- Modules/Post-To-Tumblr.ahk | 146 ++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 Modules/Post-To-Tumblr.ahk diff --git a/Modules/Miscellaneous-Functions.ahk b/Modules/Miscellaneous-Functions.ahk index 30d6998..071f6f5 100644 --- a/Modules/Miscellaneous-Functions.ahk +++ b/Modules/Miscellaneous-Functions.ahk @@ -27,7 +27,7 @@ ReadWebsiteStatuses(){ ; IniRead, Flote, %StatusFileFilePath%, Status, Flote, %A_Space% IniRead, PocketNet, %StatusFileFilePath%, Status, PocketNet, %A_Space% ; IniRead, Pintrest, %StatusFileFilePath%, Status, Pintrest, %A_Space% - ; IniRead, Tumblr, %StatusFileFilePath%, Status, Tumblr, %A_Space% + IniRead, Tumblr, %StatusFileFilePath%, Status, Tumblr, %A_Space% } AddToTotalPostsPostedCount(){ diff --git a/Modules/Post-To-Discord.ahk b/Modules/Post-To-Discord.ahk index c6128e2..97c2f05 100644 --- a/Modules/Post-To-Discord.ahk +++ b/Modules/Post-To-Discord.ahk @@ -83,9 +83,12 @@ if(ImageAttachmentFilepath != ""){ if(!InStr(Status, "id")){ parsed := JSON.Load(Status) Error := parsed.content[1] - ; Msgbox % "error: " error - Message = Discord Post Failed due to API Issue. Error was saved to errorlog; please forward to Yuriy - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + + Message = Discord Post Failed due to API Issue. Please See ErrorLog for details + SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + + Message = Discord API Returned Data:`n %Error% + SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile") Return } } diff --git a/Modules/Post-To-Telegram.ahk b/Modules/Post-To-Telegram.ahk index 94bddda..792b328 100644 --- a/Modules/Post-To-Telegram.ahk +++ b/Modules/Post-To-Telegram.ahk @@ -88,9 +88,12 @@ TelegramBody := ASCIISTRReplace(PostBody) Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := Message ) } - if(Status){ - Message = Upload Failed due to API issue. Telegram API Returned Value:`n %Status% - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + if(instr(Status, "error_code")){ + Message = Upload Failed Due To API Issue. Please See Error Log For Details + SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + + Message = Telegram API Returned Data:`n %Status% + SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile") Return } diff --git a/Modules/Post-To-Tumblr.ahk b/Modules/Post-To-Tumblr.ahk new file mode 100644 index 0000000..e081819 --- /dev/null +++ b/Modules/Post-To-Tumblr.ahk @@ -0,0 +1,146 @@ + +; -------------------------------Minds------------------------------- +PostToTumblr: +CurrentSite := "Tumblr" +Message = Navigating to Post Creationg Page +SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + +URLAttempt := NavigateFromBaseURLTo("https://www.tumblr.com/") +if(URLAttempt = "Failed") +Return + +Status := CheckCurrentTabForCurrentSite() +if(Status){ + Return +} + +; Check Login Status +; ------------------------------------------------ +Message = Checking Login Status +SaveOrPostProgress(Message,PostType:="Tooltip") + +Xpath = (//button[normalize-space()='Photo'])[1] +try ElementInnerText := driver.findelementbyxpath(Xpath).Attribute("innerText") ;XPATH Inner Text +if(ElementInnerText != "Photo"){ + Message = Site is Logged out. Please log back in. + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return +} + +; Start Text Post +; ------------------------------------------------ +Message = Creating New Post +SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + +Xpath = (//button[normalize-space()='Text'])[1] +Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) +if(status){ + Message = Failed to Start Post. Check Login Status + SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return +} + + +Xpath = (//span[@data-rich-text-placeholder='Title'])[1] +Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitle, ClearElement:=0) +if(status){ + Message = Failed to Input Post Title + SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return +} + + +Xpath = (//span[@data-rich-text-placeholder='Go ahead, put anything.'])[1] +; newline is needed so the "attach image" to post option appears in the next line down +PostBodyWithNewLine = %PostBody%`n +Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=1000,StringTextContent:=PostBodyWithNewLine, ClearElement:=0) +if(status){ + Message = Failed To Input Post Body + SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return +} + +if(ImageAttachmentFilepath){ + + ; Click the Photo Icon on the next line down to attach an image + Xpath = (//button[@title='Add photo'])[1] + Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) + if(status){ + Message = Failed to Click Attach Image Button + SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return + } + + ; send image filepath to element to attach picture + Xpath = (//input[@role='button'])[1] + Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath, ClearElement:=0) + if(status){ + Message = Failed to Attach Image to Post + SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return + } + +} + + +if (ConfirmBeforeSubmit && ConfirmBeforeSubmitMsgboxFunc() != true) { + Message = User Selected STOP button when asked for confirmation. Cancelling Rest of Site Upload. + SaveOrPostProgress(Message:=Message, PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + return +} + + + +Xpath = (//span[normalize-space()='Post now'])[1] +Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) +if(status){ + Message = Failed to Click Post Now Button + SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return +} + + + + + +/*; start photo post button +Xpath = (//button[normalize-space()='Photo'])[1] +Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) +if(status){ + Message = Failed to Start Post + SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") +} + +if(ImageAttachmentFilepath){ + ; Attach Image + Xpath = (//input[@role='button'])[1] + Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath, ClearElement:=0) + if(status){ + Message = Failed to Attach Image + SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + } +} + +; input Text Post +Xpath = (//span[@data-rich-text-placeholder='Go ahead, put anything.'])[1] +Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=) + +*/ + + + + + + +IniWrite, Successful, %StatusFileFilePath%, Status, %CurrentSite% +AddToTotalPostsPostedCount() + +PauseBetweenPosts() +DevModeMsgBox("done!") + +Message = Post Publish Successful +SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + + +Return +; -------------------------------/Minds-------------------------------