ahk read .txt or .doc file from google drive Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

ahk read .txt or .doc file from google drive

01 Jan 2018, 20:17

I was wondering to upload a script on gDrive and upload a .txt or similar file beside it where only version number would be written inside and retrieve the data so i could make an update script functionality.

Any way its possible with gDrive?
I found this out and use it to update AHK itself:

Code: Select all

Source=http://ahkscript.org/download/1.1/version.txt
DownloadLinkA=http://ahkscript.org/download/
DownloadLinkB=http://ahkscript.org/download/ahk-install.exe

hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")		;-Create the Object
ComObjError(false)
hObject.Open("GET",Source)								;-Open communication
hObject.Send()											;-Send the "get" request
Available_Version:=hObject.ResponseText					;-Set the "b" variable to the response

if (Available_Version>Installed_Version)
	msgbox, 4100,,New version available.`nOpen AHK download page?
	IfMsgBox, Yes
	{
		Run, DownloadLinkA
		Run, DownloadLinkB
	}
I want to do something similar but with gDrive and if i could actualy make AHK download the new files rather than to open it.
It shold download anything within the new version folder and replace itself and than reload itself.
Is that possible?

I uploaded a .txt file with 1.0.0.0 parameter for testing.
Heres the link i want to make it work with.
https://drive.google.com/file/d/1UEgD4F ... Lt9oM/view
I simply rewrote it to

Code: Select all

Source=https://drive.google.com/file/d/1UEgD4FOZnz7croXTNprAuGbzL4ZLt9oM/view

hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")		;-Create the Object
ComObjError(false)
hObject.Open("GET",Source)								;-Open communication
hObject.Send()											;-Send the "get" request
Available_Version:=hObject.ResponseText					;-Set the "b" variable to the response

msgbox, %Available_Version%
but it retrieved a holly **** ton of data i have no clue what to do with. xD
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ahk read .txt or .doc file from google drive  Topic is solved

01 Jan 2018, 21:42

Hi, theimmersion,

Code: Select all

Source=https://drive.google.com/file/d/1UEgD4FOZnz7croXTNprAuGbzL4ZLt9oM/view

id := RegExReplace(Source, "https://.*?\.google\.com/file/d/(.*?)(/.*|$)", "$1")
Source := "https://drive.google.com/uc?export=download&confirm=no_antivirus&id=" . id

hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")      ;-Create the Object
ComObjError(false)
hObject.Open("GET",Source)                        ;-Open communication
hObject.Send()                                 ;-Send the "get" request
Available_Version:=hObject.ResponseText               ;-Set the "b" variable to the response

msgbox, %Available_Version%
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: ahk read .txt or .doc file from google drive

15 Jan 2018, 20:52

I am so sorry for late reply. Works like a charm. THANKS YOU!
Now to study the difference. Btw, may i ask how You guys know that stuff? From school? If not, how do You figure stuff like that out, in case i ever need it for a different site or to read some other stuff off from a site? Simply awing.
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ahk read .txt or .doc file from google drive

16 Jan 2018, 12:46

theimmersion wrote:how You guys know that stuff? From school?
No, I just googled "google drive direct link". :)
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: ahk read .txt or .doc file from google drive

16 Jan 2018, 20:13

Never knew there were different possibilites for gDrive links. That sure explained a lot of things and gives me lots of new possibilities.
BTW, rather than tell me that (copy file id to direct link), apparently it was easier for you to just make a regexreplace. My hat off to you, sir. xD
RegEx is horrid for me so thanks! Sure will come in handy.
Spark
Posts: 79
Joined: 04 Jan 2017, 02:22

Re: ahk read .txt or .doc file from google drive

17 Jan 2018, 20:51

this is that i'm looking for :thumbup:

how about dropbox?
is it possible?

source : https://www.dropbox.com/s/kvqvec1pnx2gn ... r.txt?dl=0
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ahk read .txt or .doc file from google drive

18 Jan 2018, 07:57

For Dropbox you need to replace "dl=0" with "dl=1".

Code: Select all

shareLink := "https://www.dropbox.com/s/kvqvec1pnx2gnhs/AppVer.txt?dl=0"
downloadLink := RegExReplace(shareLink, "dl=\K0", "1")
oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1") 
oWhr.Open("GET", downloadLink)
oWhr.Send()
MsgBox, % oWhr.ResponseText
Spark
Posts: 79
Joined: 04 Jan 2017, 02:22

Re: ahk read .txt or .doc file from google drive

18 Jan 2018, 22:08

@teadrinker
works like a charm, Thanks.. :bravo:
maybe I need a lot to learn about RegEx
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: ahk read .txt or .doc file from google drive

21 Jan 2018, 07:42

Btw, you dont need regex exclusively.
i changed it like this for gDrive:

Code: Select all

BaseGoogleDriveLink=https://drive.google.com/uc?export=download&confirm=no_antivirus&id=
VersionLink=%BaseGoogleDriveLink%*The ID of the .txt file*
ReleaseDate=%BaseGoogleDriveLink%*Some other .txt file*
I dont use DropBox, thought it was awesome but its restrictions are bothersome so im boycotting it.
I use it to share my scripts with friends and drop box gets its n*** twisted over a few too many downloads. xD
In any case, You would have to check but this might work?
You could do:

Code: Select all

BaseDropBoxLink=https://www.dropbox.com/s/XXXXXXXXXXX/AppVer.txt?dl=1
StringReplace, Document1, BaseDropBoxLink, XXXXXXXXXXX, kvqvec1pnx2gnhs, All
StringReplace, Document2, BaseDropBoxLink, XXXXXXXXXXX, Some other ID, All
;etc...
or

Code: Select all

BaseDropBoxLinkA=https://www.dropbox.com/s/
BaseDropBoxLinkB=/AppVer.txt?dl=1

Document1=%BaseDropBoxLinkA%kvqvec1pnx2gnhs%BaseDropBoxLinkB%
Document2=%BaseDropBoxLinkA%Some other ID%BaseDropBoxLinkB%
;etc...
What ever looks better in code or is faster, although i dont think any of them much matters for performance but the first one
(StringReplace) looks better and much cleaner and more straight forward.
That is sometimes very important because making a script, working for 5 years as intended and than all of a sudden You want to upgrade it or do what ever to it and than see the crazy stuff You did while You had no clue how to comment right, tag, wrong indentations, keep code clean etc... Pain in the a** to figure out what the h*** does what. But theres a charm to it. Im like: awwwww look at wut i did, a dum-dum. xD
Obviously gDrive is the winner here because the ID is the last entry. xD

StringReplace is much more efficient than RegExReplace. RegExReplace is good for more complicated search and replace.
These are strait forward tho and would be just a waste of CPU cycles. ;)

BTW, it would be good if we could somehow compare if we are reading the right document. My link got changed and its not a big problem but it shows some huge html with errors and such and makes my close button go off screen it, probably to the floor. Is there a way to compare if for instance the read document is from a .txt file? I think the error would be some html or other site based document telling me that the link/file doesnt exist anymore or wrong address blah blah blah.
Spark
Posts: 79
Joined: 04 Jan 2017, 02:22

Re: ahk read .txt or .doc file from google drive

21 Jan 2018, 21:56

@theimmersion :

Code: Select all

BaseGoogleDriveLink=https://drive.google.com/uc?export=download&confirm=no_antivirus&id=
VersionLink=%BaseGoogleDriveLink%*The ID of the .txt file*
ReleaseDate=%BaseGoogleDriveLink%*Some other .txt file*

Code: Select all

BaseDropBoxLink=https://www.dropbox.com/s/XXXXXXXXXXX/AppVer.txt?dl=1
StringReplace, Document1, BaseDropBoxLink, XXXXXXXXXXX, kvqvec1pnx2gnhs, All
StringReplace, Document2, BaseDropBoxLink, XXXXXXXXXXX, Some other ID, All
;etc...

Code: Select all

BaseDropBoxLinkA=https://www.dropbox.com/s/
BaseDropBoxLinkB=/AppVer.txt?dl=1

Document1=%BaseDropBoxLinkA%kvqvec1pnx2gnhs%BaseDropBoxLinkB%
Document2=%BaseDropBoxLinkA%Some other ID%BaseDropBoxLinkB%
;etc...
all your code is working correctly and it's easy to understand, GREAT THANKS
about the code is more faster or not, I still do not know, as long as that code can achieve my goal I'm satisfied with that
That is sometimes very important because making a script, working for 5 years as intended and than all of a sudden You want to upgrade it or do what ever to it and than see the crazy stuff You did while You had no clue how to comment right, tag, wrong indentations, keep code clean etc... Pain in the a** to figure out what the h*** does what. But theres a charm to it. Im like: awwwww look at wut i did, a dum-dum. xD
yeah i agree with that
I dont use DropBox, thought it was awesome but its restrictions are bothersome so im boycotting it.
I use it to share my scripts with friends and drop box gets its n*** twisted over a few too many downloads. xD

Obviously gDrive is the winner here because the ID is the last entry. xD
I'm used to using DropBox rather than gDrive (because it's just for personal use only), for gDrive maybe i will consider it if i want to share my script with my friends (*.exe file)
many thanks for your suggestion :thumbup:

sorry for my bad english XD

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dunnerca, Google [Bot] and 213 guests