Temporarily removed auto-updater functionality until i can reprogram it to pull from gitea, Small error checks for multiple sites, Added ability to activate Parler tab by clicking on Parler button on Post Complete Window

main
Yuriy 2 years ago
parent e87e7e7b63
commit b5f51ca937

@ -79,9 +79,6 @@ Changelog := StrReplace(changelog, "`n", "--")
; @todo: Add tags support on all sites that support it - ask stef is useful ; @todo: Add tags support on all sites that support it - ask stef is useful
; @todo: save post tags and title to teh same file as ini file instead of two files ; @todo: save post tags and title to teh same file as ini file instead of two files
; @todo: Add workaround for all chrome tabs not being counted properly by selenium, using array?
; @todo: add support for scheduled posts.
; Misc info ; Misc info
;------------------------------------------------ ;------------------------------------------------
; Parler has a 1k char limit ; Parler has a 1k char limit
@ -224,9 +221,9 @@ IniWrite, %ScriptVersion%, %SettingsIniFilepath%, %ScriptSettingsSection%, Scrip
; Download Program Updater ; Download Program Updater
if(!FileExist(FreedomainProgramUpdaterFilepath)){ if(!FileExist(FreedomainProgramUpdaterFilepath)){
TooltipThis("Downloading Program Updater") ; TooltipThis("Downloading Program Updater")
UrlDownloadToFile, %FreedomainProgramUpdaterURL%, %FreedomainProgramUpdaterFilepath% ; UrlDownloadToFile, %FreedomainProgramUpdaterURL%, %FreedomainProgramUpdaterFilepath%
ToolTip ; ToolTip
} }
@ -891,10 +888,15 @@ SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,Disc
ScriptRunTime := round(((A_TickCount - StartTime) / 1000), 2) ScriptRunTime := round(((A_TickCount - StartTime) / 1000), 2)
; DevModeMsgBox(URLOfLastErrorPage)
if(URLOfLastErrorPage != ""){ if(URLOfLastErrorPage != ""){
Message = Activating Tab of last failed post. Message = Activating Tab of last failed post.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip") SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
; DevModeMsgBox("pause")
; message = URLOfLastErrorPage: %URLOfLastErrorPage%
; DevModeMsgBox(URLOfLastErrorPage)
FindAndActivateTab(URLOfLastErrorPage) FindAndActivateTab(URLOfLastErrorPage)
} }
@ -976,7 +978,7 @@ Gui, Font, s%GUINormalFontSize%
Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Flote Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Flote
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Flote% Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Flote%
Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Parler Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% gActivateParlerTab Center, Parler
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Parler% Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Parler%
Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Steemit Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Steemit
@ -1021,6 +1023,13 @@ AddToTotalRunTime()
Return Return
ActivateParlerTab:
DevModeMsgBox("activating")
DevModeMsgBox(ParlerTabURL)
FindAndActivateTab(ParlerTabURL)
Return
SendErrorLoggingThroughTelegram: SendErrorLoggingThroughTelegram:
Message = Uploading Errorlog to FDRBotTesting Telegram Server. Message = Uploading Errorlog to FDRBotTesting Telegram Server.
@ -1188,7 +1197,7 @@ if(ImageAttachmentFilepath = "" AND Status){ ; upload a temporary file and then
} }
; driver.FindElementByXPath(Xpath).click() ; driver.FindElementByXPath(Xpath).click()
/*
Xpath = //span[normalize-space()="What's on your mind, Stefan?"] Xpath = //span[normalize-space()="What's on your mind, Stefan?"]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
@ -1205,7 +1214,7 @@ if(ImageAttachmentFilepath = "" AND Status){ ; upload a temporary file and then
Return Return
} }
} }
*/
} }
if(ImageAttachmentFilepath != "") { ; otherwise send image straight to upload input box. The post box will open up automatically if(ImageAttachmentFilepath != "") { ; otherwise send image straight to upload input box. The post box will open up automatically
Message = Attaching Image Message = Attaching Image
@ -1319,9 +1328,11 @@ if(Status){
; Check login status by checking the header of the page for "Feed" text ; Check login status by checking the header of the page for "Feed" text
js = return document.querySelector(".header__contain").innerText js = return document.querySelector(".header__contain").innerText
try status := driver.executeScript(js) try status := driver.executeScript(js)
if(InStr(!status, "Feed")){ if(!InStr(status, "Feed")){
; SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") ; SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
; ParlerTabURL :=
try ParlerTabURL := driver.URL
SaveDriverURLOFErrorPage() SaveDriverURLOFErrorPage()
Return Return
} }
@ -1587,6 +1598,7 @@ if(InStr(CurrentTabURL, "/login")){
} }
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber) DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
SplitCharNumber := SplitCharNumber + 1 SplitCharNumber := SplitCharNumber + 1
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber) DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
@ -1674,7 +1686,7 @@ if(InStr(CurrentTabURL, "/login")){
Status := NavigateFromBaseURLTo(SubscribeStarProfileURL) Status := NavigateFromBaseURLTo(SubscribeStarProfileURL)
if(Status){ if(Status){
Message = Failed to Navigate to Feed URL Message = Failed to Navigate to SubScribeStar Page
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
} }
@ -2230,7 +2242,7 @@ if(InStr(CurrentTabURL, "/login")){
sleep, 2000 sleep, 2000
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Inputting Post Content`nMight take 5-15 seconds to get input",PostType:="Tooltip,ErrorLoggingTextFile")
; Click the plus button to make the title box show up ; Click the plus button to make the title box show up
Xpath = //div[@class='m-composer__base m-composer__base--withPreview']//i[@class='material-icons ng-star-inserted'][normalize-space()='add_circle_outline'] Xpath = //div[@class='m-composer__base m-composer__base--withPreview']//i[@class='material-icons ng-star-inserted'][normalize-space()='add_circle_outline']

@ -153,11 +153,11 @@ UpdateScript(){
; sleep, 5000 ; sleep, 5000
if(SaveFilepath = ""){ if(SaveFilepath = ""){
SaveFilepath := ErrorLoggingDirectory SaveFilepath := ErrorLoggingDirectory
} }
; if(!FileExist(SaveFilepath)) ; if(!FileExist(SaveFilepath))
FileCreateDir, %SaveFilepath% FileCreateDir, %SaveFilepath%
/* if(!TakeScreenshotsOfErrors) /* if(!TakeScreenshotsOfErrors)
Return Return
@ -947,127 +947,141 @@ if(TotalTabsFound = 1){
} }
; -------------------------------NavigateFromBaseURLTo------------------------------- ; -------------------------------NavigateFromBaseURLTo-------------------------------
NavigateFromBaseURLTo(URL,PageTitle := "New Tab"){ NavigateFromBaseURLTo(URL){
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
Status := CheckSeleniumDriver() Status := CheckSeleniumDriver()
if(Status) if(Status)
Return "Failed" Return "Failed"
CreateArrayOfTabs() CreateArrayOfTabs() ; store all open tabs to memory for later usage
} }
if(ReuseTabs){ if(ReuseTabs){ ; pull out base of URL and check if it's within the array of tabs
URLBase := StrReplace(URL,"https://","") URLBase := StrReplace(URL,"https://","")
URLBase := StrSplit(URLBase, "/") URLBase := StrSplit(URLBase, "/")
URLBase := URLBase[1] URLBase := URLBase[1]
URLBase := StrReplace(URLBase, "www.","") URLBase := StrReplace(URLBase, "www.","")
} }
if(!HasSubstringVal(DriverURLArray, URLBase)) ; returns position of value in array if(!HasSubstringVal(DriverURLArray, URLBase)) ; if base url is not in tab array, create new tab and push url to array
{ {
try, run "%ChromeFilepath%" "%URL%" try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1 NewTabCreated := 1
sleep, 1000 sleep, 2000
} }
; msgbox, ; msgbox,
Message = Finding Tab Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
TabFoundSuccessfully := TabFoundSuccessfully :=
NumberOfTabLoops := DriverURLArray.Length() NumberOfTabLoops := DriverURLArray.Length()
; NumberOfTabLoops := Driver.Windows.Count + 2 ; NumberOfTabLoops := Driver.Windows.Count + 2
loop % NumberOfTabLoops { ; loop through tabs to find matching tab loop % NumberOfTabLoops { ; loop through tabs to find matching tab
try driver.SwitchToNextWindow() try driver.SwitchToNextWindow()
; sleep, 1000 ; sleep, 1000
; msgbox, looping through tabs ; msgbox, looping through tabs
try CurrentTabTitle := driver.window.title try CurrentTabTitle := driver.window.title
try CurrentTabURL := driver.Url
if(CurrentTabTitle = PageTitle OR InStr(CurrentTabURL, URLBase)){ ; caused by tab being manually closed. Not sure if this is the only cause though.
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase% if(CurrentTabTitle = "") {
TabFoundSuccessfully := 1 Message = CurrentTabTitle: %CurrentTabTitle%
; msgbox %CurrentTabTitle% = %PageTitle% DevModeMsgBox(Message)
; msgbox %CurrentTabURL% = %URL%
Break Message = CurrenttabURL: %CurrentTabURL%
} DevModeMsgBox(Message)
; try driver.SwitchToNextWindow
Continue
} }
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, URLBase)){
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
TabFoundSuccessfully := 1
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
Break
}
}
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
try driver.Get(URL) ;Open selected URL
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
catch e {
; msgbox, error caught. trying something
try driver.switchToalert().accept()
try driver.Get(URL) ;Open selected URL try driver.Get(URL) ;Open selected URL
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
catch e { catch e {
; msgbox, error caught. trying something Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes
try driver.switchToalert().accept() SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
try driver.Get(URL) ;Open selected URL Return "Failed"
catch e {
Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
} }
} }
; msgbox, no error caught }
; } ; msgbox, no error caught
; }
Return Return
} }
; End of Function ; End of Function
; -------------------------------/NavigateFromBaseURL------------------------------- ; -------------------------------/NavigateFromBaseURL-------------------------------
SaveDriverURL(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together SaveDriverURL(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together
try LastWebsitePostURL := driver.URL try LastWebsitePostURL := driver.URL
} }
; -------------------------------SChrome_Get------------------------------- ; -------------------------------SChrome_Get-------------------------------
SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1") IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1")
if WinExist("ahk_exe Chrome.exe"){ if WinExist("ahk_exe Chrome.exe"){
WinGet, pid, PID, ahk_exe chrome.exe WinGet, pid, PID, ahk_exe chrome.exe
for item in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" pid "'"){ for item in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" pid "'"){
if RegExMatch(item.CommandLine, "i)--remote-debugging-port=\K\d+", port){ if RegExMatch(item.CommandLine, "i)--remote-debugging-port=\K\d+", port){
break break
}
} }
}
if (Port=""){ if (Port=""){
MsgBox, 36, ,Chrome Needs to be started in debugging mode in order for Autohotkey to connect to it.`nIs it ok to restart Chrome in debugmode to enable a connection? MsgBox, 36, ,Chrome Needs to be started in debugging mode in order for Autohotkey to connect to it.`nIs it ok to restart Chrome in debugmode to enable a connection?
IfMsgBox, Yes IfMsgBox, Yes
{ {
Message = Restarting Chrome in Debug Mode Message = Restarting Chrome in Debug Mode
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
While(WinExist("ahk_exe chrome.exe")) { While(WinExist("ahk_exe chrome.exe")) {
WinClose, ahk_exe chrome.exe WinClose, ahk_exe chrome.exe
}
Process, WaitClose, chrome.exe
}
Else{
Msgbox, 4096, Error, Cannot connect to Chrome profile if it is Not running in debug mode. Script Terminating
ExitApp
; @todo: Make this error out to the script result screen
} }
Process, WaitClose, chrome.exe
}
Else{
Msgbox, 4096, Error, Cannot connect to Chrome profile if it is Not running in debug mode. Script Terminating
ExitApp
; @todo: Make this error out to the script result screen
} }
} }
}
; ; yuriy's settings ; ; yuriy's settings
; IniRead, ChromeFilepath, C:\Users\%A_username%\Documents\Autohotkey\Lib\ScriptSettings.ini, Selenium, %A_Computername%, %A_Space% ; IniRead, ChromeFilepath, C:\Users\%A_username%\Documents\Autohotkey\Lib\ScriptSettings.ini, Selenium, %A_Computername%, %A_Space%
; ; Establish Variable with Filepath to be used throughout the script ; ; Establish Variable with Filepath to be used throughout the script
; if(ChromeFilepath = ""){ ; if(ChromeFilepath = ""){
if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")){ if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
} }
else if (FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")){ else if (FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
} }
if(ChromeFilepath = ""){ if(ChromeFilepath = ""){
@ -1408,13 +1422,22 @@ SaveDriverURLOFErrorPage(){ ; save the url of the result page. That way if a tab
FindAndActivateTab(TabURL){ FindAndActivateTab(TabURL){
DevModeMsgBox(TabURL)
Loop, { Loop, {
if(A_index = 30) if(A_index = 30)
break break
try CurrentTabTitle := driver.window.title try CurrentTabTitle := driver.window.title
if(CurrentTabTitle = "") ; caused by tab being manually closed. Not sure if this is the only cause though.
{
; DevModeMsgBox("currenttabtutle is blank")
try driver.SwitchToNextWindow
Continue
}
; DevModeMsgBox(CurrentTabTitle)
try CurrentTabURL := driver.Url try CurrentTabURL := driver.Url
DevModeMsgBox(CurrentTabURL)
if(CurrentTabURL = TabURL) if(CurrentTabURL = TabURL)
Break Break

Loading…
Cancel
Save