expanded function

main
Yuriy 5 months ago
commit 43dd2c3f28

@ -21,6 +21,9 @@ global InstalledChromeVersion
; Chrome Related Functions ; Chrome Related Functions
;------------------------------------------------ ;------------------------------------------------
DownloadLatestChromium(){ DownloadLatestChromium(){
Message = Checking Variables for Downloading Newest Chrome
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(ChromeFilepath = "") if(ChromeFilepath = "")
ChromeFilepath := GetInstalledChromeFilepath() ChromeFilepath := GetInstalledChromeFilepath()
@ -90,9 +93,9 @@ DownloadLatestChromium(){
; close any open instances of Chromium ; close any open instances of Chromium
SetTitleMatchMode, 2 ; substring ; SetTitleMatchMode, 2 ; substring
/*
if(WinExist(" - Chromium")){ if(WinExist(" - Chromium")){
Message = Trying to close any open Chromium Windows Message = Trying to close any open Chromium Windows
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
@ -111,19 +114,64 @@ DownloadLatestChromium(){
MsgBox 0x10,, %Message% MsgBox 0x10,, %Message%
return return
} }
*/
; make sure all instances of chrome are closed
Loop, {
ChromeOpen := WinExist("ahk_exe chrome.exe")
if(ChromeOpen) {
Message = Chrome is Open. Asking user to close instances before continuing.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
MsgBox 0x41, Chrome is Open, Please close all instances of Chrome and then click OK to continue with replacing Chrome with the newest version.
IfMsgBox OK, {
} Else IfMsgBox Cancel, {
return
}
}
else,
break
}
; msgbox
; make sure all instances of chromedriver.exe are closed
Message = Checking and killing any instances of the chromedriver.exe process
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Loop, 5 {
Process, Exist, chromedriver.exe
ChromedriverExists := ErrorLevel
if(ChromedriverExists){
Message = Chromedriver Exists on check number %A_Index%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
Process, Close, chromedriver.exe
sleep, 5000 ; wait 5 seconds before checking again
}
else,
break
Message = Chrome Update Failed. Unable to kill background chromedriver.exe process
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
return
}
FileGetTime, ChromeDriverExeOldCreationTime, %ChromeDriverProgramFilesExeFilepath%, C FileGetTime, ChromeDriverExeOldCreationTime, %ChromeDriverProgramFilesExeFilepath%, C
Message = Downloading Chromedriver v%ChromeStableLatestVersion% to:`n%ChromeDriverDownloadZipFilepath% Message = Downloading Chromedriver v%ChromeStableLatestVersion% `nFrom: %chromedriverDLURL64%`nTo: %ChromeDriverDownloadZipFilepath%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
UrlDownloadToFile, %chromedriverDLURL64%, %ChromeDriverDownloadZipFilepath% UrlDownloadToFile, %chromedriverDLURL64%, %ChromeDriverDownloadZipFilepath%
Message = Downloading Chromium v%ChromeStableLatestVersion% to:`n%ChromeDownloadZipFilepath% Message = Downloading Chromium v%ChromeStableLatestVersion% `nfrom: %chromeDLURL64% to:`n%ChromeDownloadZipFilepath%`n(This might take 1-2 minutes)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
UrlDownloadToFile, %chromeDLURL64%, %ChromeDownloadZipFilepath% UrlDownloadToFile, %chromeDLURL64%, %ChromeDownloadZipFilepath%
@ -132,6 +180,8 @@ DownloadLatestChromium(){
Message = Deleting Old Chromium Directory Message = Deleting Old Chromium Directory
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
FileRemoveDir, %ChromeExtractedDirectory%, 1 FileRemoveDir, %ChromeExtractedDirectory%, 1
if(FileExist(ChromeExtractedDirectory)){ if(FileExist(ChromeExtractedDirectory)){
Message = Failed to delete the old Chromium. `nPlease manually delete the following directory and then run the Chrome Update again.`n`n %ChromeExtractedDirectory% Message = Failed to delete the old Chromium. `nPlease manually delete the following directory and then run the Chrome Update again.`n`n %ChromeExtractedDirectory%

@ -425,3 +425,210 @@ HasSubstringVal(haystack, needle)
; -------------------------------Functions-------------------------------
OnMsgBoxConfirmChromiumOverwrite() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Cancel
ControlSetText Button2, Yes
}
}
; https://www.autohotkey.com/docs/v2/Functions.htm#Variadic
Join(sep, params*) {
For index, param in params
str .= param . sep
return SubStr(str, 1, -StrLen(sep))
}
LogErrorToTextFile(Error){
/* if(LogErrorsToTextFile != 1)
Return
*/
ErrorLoggingFile := VideoFolderDir . "\" . "ErrorLogging.txt"
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
text =
(
---------------%TodayDate%---------------
%CurrentSite%: %Error%
)
if(LogErrorsToMsgbox)
Msgbox % "Text: " Text
FileAppend, %Text%, %ErrorLoggingFile%
} ; End of Function
/*
*/
AddToTotalVideosUploadedCount(){
; IniRead, TotalVideosUploaded, %SettingsIniFilepath%, General, TotalVideosUploaded, %A_Space%
TotalVideosUploaded += 1
; IniWrite, %TotalVideosUploaded%, %SettingsIniFilepath%, General, TotalVideosUploaded
}
OnMsgBoxPodcastFinish() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
WinMove,, 0
}
}
OnMsgBoxSocialMediaPoster() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Yes
ControlSetText Button2, Not Now
}
}
Check_For_Stuck_Video_Upload(Index_Number, Upload_Status){
if(A_index = 1){ ; Create a blank array
ProgressStatusArray := []
Return
}
Message = Upload Status: %Upload_Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
; if we reached the last loop number:
if(A_index = %Number_of_loops_to_Check_Upload_status%){
Message = Upload Most Likely Failed: Video Hasn't Finished Uploading after 1 hour.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return "Failed"
}
; If progress is still the same after a ten minute interval then error out
if(HasVal(Array_Index_Num_of_Upload_StatusChecks, A_index)){ ; if current index is in Array of index numbers to check status during
; Send a notification message of upload status
Message = Upload Status: %Upload_Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; if current upload_status is in the array of values that are updated every 10 mins
if(HasVal(ProgressStatusArray, Upload_Status)){
Message = Upload Failed (E#4508)`nUpload Stuck at same point for 10 minutes. Stuck Status: %ProgressStatus%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return "Failed"
}
ProgressStatusArray.Push(Upload_Status) ; append current status to array
}
} ; end of func
/*
*/
; Find the longest word in a string of words
FindLongestWordInString(m, calloutNumber, pos, haystack, pattern){
Global wordLength, longestWord
len := StrLen(m)
If ( len > wordLength )
{
wordLength := len
longestWord := m
; MsgBox, %m%
}
}
/*
*/
; Split a long string into multiple pieces based on the string lengtht you want and return an array with all strings
SplitStringWithSentences(text, maxChunkSize) {
sentences := StrSplit(text, "\. ") ; split at period with space after it
currentChunk := ""
chunks := []
Loop, % sentences.Length()
{
sentence := sentences[A_Index]
CurrentChunkAndSentence := currentChunk . sentence
; Msgbox % "CurrentChunkAndSentence: " CurrentChunkAndSentence
; msgbox % StrLen(CurrentChunkAndSentence)
if (StrLen(CurrentChunkAndSentence) <= maxChunkSize)
{
currentChunk .= sentence . "\. "
}
else
{
chunks.Push(currentChunk)
currentChunk := sentence . "\. "
}
}
if (currentChunk != "")
chunks.Push(currentChunk)
return chunks
}
CreateErrorLoggingFiles(Directory := ""){
FormatTime, TodayDate, YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
ErrorLoggingDirectory := Directory
if(ErrorLoggingDirectory = ""){
ErrorLoggingDirectory := A_ScriptDir . "\Lib\ErrorLogging"
; If directory for error logging doesn't exist, create it
if(!FileExist(ErrorLoggingDirectory))
FileCreateDir, %ErrorLoggingDirectory%
ErrorLoggingDirectory := ErrorLoggingDirectory . "\" . TodayDate . "_" . ScriptAbbreviatedName
}
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
FileCreateDir, %ErrorLoggingDirectory%
; Create variables with filepaths that content will be saved to.
global ErrorLoggingFilePath := ErrorLoggingDirectory . "\" . "ErrorLogging.txt"
global StatusFileFilePath := ErrorLoggingDirectory . "\" . "PostStatus.ini"
global PostTitleFilePath := ErrorLoggingDirectory . "\" . "PostTitle.txt"
global PostBodyFilePath := ErrorLoggingDirectory . "\" . "PostBody.txt"
global PostTagsFilePath := ErrorLoggingDirectory . "\" . "PostTags.txt"
PostStatusesFilepath := ErrorLoggingDirectory . "\" . "Status.ini"
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
Return
}
; if passed argument is .exe file, then script has just been updated and we need to delete the old .exe file
CheckIfUpdateInstalled(PassedInArgument :=""){
if(InStr(PassedInArgument,".exe")){
FileDelete, %PassedInArgument%
if(ErrorLevel){ ; most likely because the old version hasn't finished exiting yet
Message = Failed to Delete Old .exe file after Updating
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
}
}
}

@ -0,0 +1,50 @@
; Iterate over Locals posts on the home page until found post with title
; ------------------------------------------------
GrabLocalsPostURLUsingTitle(PostTitle){
Loop, 10 {
Message = Checking Post %A_index% on page for Post Titled`n%PostTitle%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
ToolTip, %A_Index%
; first two items can be skipped.
; new Post box and Create other forms of posts box
if(A_index < 3)
Continue
; Xpath for each post box on the main page
Xpath = //body/div/div/div/div/div/div[1]/div[%A_Index%]
try ElementInnerText := driver.findelementbyxpath(Xpath).Attribute("innerText") ;XPATH Inner Text
Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
if(InStr(ElementInnerText, PostTitle)){
Message = Found Post Title in Element Number: %A_index%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Pull Out the Post URL from the OuterHTML using RegEx
regexMatch := RegExMatch(ElementOuterHTML, "data-post-url=""([^""]+)""", match)
if (regexMatch)
{
PostURL := match1
Message = URL Pulled out from OuterHTML: %PostURL%
Return PostURL
}
else {
Message = Failed to Pull out URL from OuterHTML
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return "Failed"
}
}
}
Message = Failed to find New Post in the first 10 posts
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return "Failed"
}

@ -1,158 +0,0 @@
; -------------------------------Functions-------------------------------
OnMsgBoxConfirmChromiumOverwrite() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Cancel
ControlSetText Button2, Yes
}
}
; https://www.autohotkey.com/docs/v2/Functions.htm#Variadic
Join(sep, params*) {
For index, param in params
str .= param . sep
return SubStr(str, 1, -StrLen(sep))
}
LogErrorToTextFile(Error){
/* if(LogErrorsToTextFile != 1)
Return
*/
ErrorLoggingFile := VideoFolderDir . "\" . "ErrorLogging.txt"
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
text =
(
---------------%TodayDate%---------------
%CurrentSite%: %Error%
)
if(LogErrorsToMsgbox)
Msgbox % "Text: " Text
FileAppend, %Text%, %ErrorLoggingFile%
} ; End of Function
/*
*/
AddToTotalVideosUploadedCount(){
; IniRead, TotalVideosUploaded, %SettingsIniFilepath%, General, TotalVideosUploaded, %A_Space%
TotalVideosUploaded += 1
; IniWrite, %TotalVideosUploaded%, %SettingsIniFilepath%, General, TotalVideosUploaded
}
OnMsgBoxPodcastFinish() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
WinMove,, 0
}
}
OnMsgBoxSocialMediaPoster() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Yes
ControlSetText Button2, Not Now
}
}
Check_For_Stuck_Video_Upload(Index_Number, Upload_Status){
if(A_index = 1){ ; Create a blank array
ProgressStatusArray := []
Return
}
Message = Upload Status: %Upload_Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
; if we reached the last loop number:
if(A_index = %Number_of_loops_to_Check_Upload_status%){
Message = Upload Most Likely Failed: Video Hasn't Finished Uploading after 1 hour.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return "Failed"
}
; If progress is still the same after a ten minute interval then error out
if(HasVal(Array_Index_Num_of_Upload_StatusChecks, A_index)){ ; if current index is in Array of index numbers to check status during
; Send a notification message of upload status
Message = Upload Status: %Upload_Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; if current upload_status is in the array of values that are updated every 10 mins
if(HasVal(ProgressStatusArray, Upload_Status)){
Message = Upload Failed (E#4508)`nUpload Stuck at same point for 10 minutes. Stuck Status: %ProgressStatus%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return "Failed"
}
ProgressStatusArray.Push(Upload_Status) ; append current status to array
}
} ; end of func
/*
*/
; Find the longest word in a string of words
FindLongestWordInString(m, calloutNumber, pos, haystack, pattern){
Global wordLength, longestWord
len := StrLen(m)
If ( len > wordLength )
{
wordLength := len
longestWord := m
; MsgBox, %m%
}
}
/*
*/
; Split a long string into multiple pieces based on the string lengtht you want and return an array with all strings
SplitStringWithSentences(text, maxChunkSize) {
sentences := StrSplit(text, "\. ") ; split at period with space after it
currentChunk := ""
chunks := []
Loop, % sentences.Length()
{
sentence := sentences[A_Index]
CurrentChunkAndSentence := currentChunk . sentence
; Msgbox % "CurrentChunkAndSentence: " CurrentChunkAndSentence
; msgbox % StrLen(CurrentChunkAndSentence)
if (StrLen(CurrentChunkAndSentence) <= maxChunkSize)
{
currentChunk .= sentence . "\. "
}
else
{
chunks.Push(currentChunk)
currentChunk := sentence . "\. "
}
}
if (currentChunk != "")
chunks.Push(currentChunk)
return chunks
}

@ -832,6 +832,38 @@ SaveDriverURLOFErrorPage(){ ; save the url of the result page. That way if a tab
} }
GetHTMLValueFromXpathOuterHTML(XPATH, HTMLElementName){
Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; try Clipboard := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; Try MsgBox,,Element OuterHTML: `n, % driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; Match string between quotes following the HTMLELEMENTNAME
RegexStatement = %HTMLElementName%="([^"]+)"
; regexMatch := RegExMatch(ElementOuterHTML, "value=""([^""]+)""", match)
regexMatch := RegExMatch(ElementOuterHTML, RegexStatement, match)
if (regexMatch)
{
ElementValue := match1
; Msgbox % "PostURL: " PostURL
; Message = URL Pulled out from OuterHTML: %PostURL%
Return ElementValue
}
else {
Message = Failed to Pull out value from OuterHTML
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
}
;---\Selenium--- ;---\Selenium---
;------------------------------------------------ ;------------------------------------------------

Loading…
Cancel
Save