Added functions from Social Media Poster Shared Functions file so SharedFunctions.ahk can be replaced by this submodule

main
Yuriy 2 years ago
parent b21b92da87
commit ad4565bdc7

3
.gitmodules vendored

@ -0,0 +1,3 @@
[submodule "Lib/Freedomain-Posters-Shared-Functions"]
path = Lib/Freedomain-Posters-Shared-Functions
url = https://git.freedomainplaylists.com/yuriy/Freedomain-Posters-Shared-Functions.git

@ -0,0 +1 @@
Subproject commit 694c440a6a89b0b84fee0c49370d95150667c7a9

@ -15,6 +15,7 @@ global CurrentTabURL
; #Include %A_ScriptDir%\RunCMD.ahk ; #Include %A_ScriptDir%\RunCMD.ahk
; @todo: add error checks for all winhttp requests.
DevModeMsgBox(Message){ DevModeMsgBox(Message){
@ -26,7 +27,7 @@ DevModeMsgBox(Message){
} }
CheckForUpdates(){ CheckForUpdates(GitReleasesAPIURL){
; msgbox, checking for updates ; msgbox, checking for updates
Message = Checking For Updates Message = Checking For Updates
SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile") SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile")
@ -39,10 +40,10 @@ CheckForUpdates(){
UpdateVersionNumber := parsed.1.name UpdateVersionNumber := parsed.1.name
if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){ if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){
ToolTip ToolTip
return return
} }
else, { else, {
UpdateAvailable := 1 UpdateAvailable := 1
; msgbox, update found! ; msgbox, update found!
Message = Program Update Found Message = Program Update Found
@ -148,24 +149,24 @@ TakeScreenshotOfPage(SaveFilepath := ""){
; 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
; Take a screenshot of the page and save it. ; Take a screenshot of the page and save it.
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory ; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
savepath = %SaveFilepath%\%TodayDate%.jpg savepath = %SaveFilepath%\%TodayDate%.jpg
; Msgbox % "savepath: " savepath ; Msgbox % "savepath: " savepath
try driver.TakeScreenshot().SaveAs(savepath) try driver.TakeScreenshot().SaveAs(savepath)
; ScreenshotsTaken := 1 ; ScreenshotsTaken := 1
} }
@ -174,6 +175,7 @@ TakeScreenshotOfPage(SaveFilepath := ""){
; -------------------------------TooltipThis------------------------------- ; -------------------------------TooltipThis-------------------------------
TooltipThis(String){ TooltipThis(String){
; msgbox
; Xposition := StrLen(String) ; Xposition := StrLen(String)
StringFirstLine := StrSplit(String, "`n") StringFirstLine := StrSplit(String, "`n")
StringFirstLine := StringFirstLine[1] StringFirstLine := StringFirstLine[1]
@ -922,173 +924,175 @@ if(TotalTabsFound = 1){
; / END OF FUNC ; / END OF FUNC
} }
InputFilePathIntoOpenWindow(Filepath){ /*
; Msgbox % "Filepath: " Filepath */
Message = Waiting for "Open" window to appear to input filepath into InputFilePathIntoOpenWindow(Filepath){
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") ; Msgbox % "Filepath: " Filepath
; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0 Message = Waiting for "Open" window to appear to input filepath into
; WinWait, Open SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
WinWait,Open,,5 ; Wait for 10 seconds for window ; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0
if(ErrorLevel) ; WinWait, Open
{ WinWait,Open,,5 ; Wait for 10 seconds for window
; msgbox, failed to find window. if(ErrorLevel)
Return "Failed" {
} ; msgbox, failed to find window.
WinActivate, Open Return "Failed"
sleep, 1000 }
ControlSetText, Edit1, %Filepath%, Open WinActivate, Open
sleep, 1000 sleep, 1000
ControlSend, Edit1, {Enter}, Open ControlSetText, Edit1, %Filepath%, Open
sleep, 1000 sleep, 1000
ControlSend, Edit1, {Enter}, Open
; Do an extra check in case the Open window is still open. sleep, 1000
OpenWindowExist := WinExist("Open")
if(OpenWindowExist) ; Do an extra check in case the Open window is still open.
ControlSend, Edit1, {Enter}, Open OpenWindowExist := WinExist("Open")
ToolTip, if(OpenWindowExist)
} ControlSend, Edit1, {Enter}, Open
ToolTip,
}
CheckCurrentTabForCurrentSite(){ CheckCurrentTabForCurrentSite(){
try CurrentTabURL := driver.url try CurrentTabURL := driver.url
if(!InStr(CurrentTabURL, CurrentSite)){ if(!InStr(CurrentTabURL, CurrentSite)){
Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on. Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
return "Failed" return "Failed"
} }
; msgbox % InStr(CurrentTabURL,CurrentSite) ; msgbox % InStr(CurrentTabURL,CurrentSite)
} }
; -------------------------------NavigateFromBaseURLTo------------------------------- ; -------------------------------NavigateFromBaseURLTo-------------------------------
NavigateFromBaseURLTo(URL){ NavigateFromBaseURLTo(URL, Title:="REmoveMe"){
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() ; store all open tabs to memory for later usage CreateArrayOfTabs() ; store all open tabs to memory for later usage
} }
if(ReuseTabs){ ; pull out base of URL and check if it's within the array of tabs 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 base url is not in tab array, create new tab and push url to array ; if base url is not in tab array, create new tab and push url to array
if(!HasSubstringVal(DriverURLArray, URLBase)) if(!HasSubstringVal(DriverURLArray, URLBase))
{ {
try CurrentTabTitle := driver.window.title try CurrentTabTitle := driver.window.title
; if currently in new tab navigate to the site in the current tab ; if currently in new tab navigate to the site in the current tab
if(CurrentTabTitle = "New Tab"){ if(CurrentTabTitle = "New Tab"){
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 try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
catch e { catch e {
; msgbox, error caught. trying something ; msgbox, error caught. trying something
try driver.switchToalert().accept() try driver.switchToalert().accept()
try driver.Get(URL) ;Open selected URL try driver.Get(URL) ;Open selected URL
catch e { catch e {
Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed" Return "Failed"
}
}
return
}
else, {
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
; sleep, 2000
} }
}
return
}
else, {
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
; sleep, 2000
}
} }
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()
; loop through tabs to find matching tab ; loop through tabs to find matching tab
loop % NumberOfTabLoops { loop % NumberOfTabLoops {
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 try CurrentTabURL := driver.Url
; DevModeMsgBox(CurrentTabURL) ; DevModeMsgBox(CurrentTabURL)
; DevModeMsgBox(CurrentTabTitle) ; DevModeMsgBox(CurrentTabTitle)
; caused by tab being manually closed. Not sure if this is the only cause though. ; caused by tab being manually closed. Not sure if this is the only cause though.
if(CurrentTabTitle = "") { if(CurrentTabTitle = "") {
Message = CurrentTabTitle: %CurrentTabTitle% Message = CurrentTabTitle: %CurrentTabTitle%
; DevModeMsgBox(Message) ; DevModeMsgBox(Message)
Message = CurrenttabURL: %CurrentTabURL% Message = CurrenttabURL: %CurrentTabURL%
; DevModeMsgBox(Message) ; DevModeMsgBox(Message)
; try driver.SwitchToNextWindow ; try driver.SwitchToNextWindow
Continue Continue
} }
if(InStr(CurrentTabURL, URLBase)){ if(InStr(CurrentTabURL, URLBase)){
Message = CurrentTabURL is %CurrentTabURL% and it contains %URLBase% Message = CurrentTabURL is %CurrentTabURL% and it contains %URLBase%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase% ; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
TabFoundSuccessfully := 1 TabFoundSuccessfully := 1
; message = %CurrentTabTitle%: %PageTitle% ; message = %CurrentTabTitle%: %PageTitle%
; DevModeMsgBox(message) ; DevModeMsgBox(message)
; msgbox %CurrentTabURL% = %URL% ; msgbox %CurrentTabURL% = %URL%
Break Break
} }
} }
; if failed to switch to tab and a new tab was not created, then chrome failed to switch to the tab ; if failed to switch to tab and a new tab was not created, then chrome failed to switch to the tab
; this happens sometimes. most likely to a chromedriver bug or maybe tab being offloaded? ; this happens sometimes. most likely to a chromedriver bug or maybe tab being offloaded?
if(!TabFoundSuccessfully AND !NewTabCreated){ if(!TabFoundSuccessfully AND !NewTabCreated){
; @todo : not sure how to best solve this problem currently. It doesn't happen very often. ; @todo : not sure how to best solve this problem currently. It doesn't happen very often.
; last time it happened was when there were only 2 chrome tabs open, gab + subscribestar. chrome was stuck on subscribestar page and wouldn't nextwindow() to gab ; last time it happened was when there were only 2 chrome tabs open, gab + subscribestar. chrome was stuck on subscribestar page and wouldn't nextwindow() to gab
} }
; Message = TabFoundSuccessfully: %TabFoundSuccessfully% ; Message = TabFoundSuccessfully: %TabFoundSuccessfully%
; DevModeMsgBox(Message) ; DevModeMsgBox(Message)
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page 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-------------------------------
@ -1165,19 +1169,19 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
try Driver.Start() try Driver.Start()
catch e { catch e {
ShowSeleniumErrorMsgbox() ShowSeleniumErrorMsgbox()
} }
return Driver return Driver
} }
; -------------------------------/SChrome_Get------------------------------- ; -------------------------------/SChrome_Get-------------------------------
ShowSeleniumErrorMsgbox(){ ShowSeleniumErrorMsgbox(){
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
Chromeversion := RunCMD(GetChromeVersionCommand) Chromeversion := RunCMD(GetChromeVersionCommand)
ChromeVersion := StrReplace(ChromeVersion, "`n", "") ChromeVersion := StrReplace(ChromeVersion, "`n", "")
Message = Failed to connect to Chrome Message = Failed to connect to Chrome
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
/* /*
; check for alert popup ; check for alert popup

Loading…
Cancel
Save