Jump to content
Sign in to follow this  
sandanet

how to read file contents from google drive?

Recommended Posts

sandanet

Hi friends,,
I'd like to get your help on how to read file contents on google drive which i have a shared file on there
I tried to do this 

#include <INet.au3>
Local Const $ini = _INetGetSource("https://docs.google.com/document/d/1JV1s3IueHLW6jMlCV_FSd0D8CBS-IpkS5b81VpZCmkk/edit?usp=sharing")

Local $url1 = IniRead($ini, 'Server', 'name', "")
MsgBox($MB_SYSTEMMODAL, "the Server name is", $url1)

Local $url2 = IniRead($ini, 'Username', 'name', "")
MsgBox($MB_SYSTEMMODAL, "the username is", $url2)

Local $url3 = IniRead($ini, 'Pass', 'name', "")
MsgBox($MB_SYSTEMMODAL, "the password is", $url3)

but unfortunately I got no results

Share this post


Link to post
Share on other sites
mikell

There is certainly a more clever way to do this ... :unsure:

#include <INet.au3>

$ini = @scriptdir & "\temp.ini"

$initxt = _INetGetSource("https://docs.google.com/document/d/1JV1s3IueHLW6jMlCV_FSd0D8CBS-IpkS5b81VpZCmkk/edit?usp=sharing")
$initxt = StringRegExpReplace($initxt, '(?s).*?og:description" content="([^"]+).*', "$1")
$initxt = StringReplace($initxt, '&#39;', "'")
$initxt = StringReplace($initxt, ' ', @crlf)
FileWrite($ini, $initxt)

Local $url1 = IniRead($ini, 'Server', 'name', "")
MsgBox($MB_SYSTEMMODAL, "the Server name is", $url1)

Local $url2 = IniRead($ini, 'Username', 'name', "")
MsgBox($MB_SYSTEMMODAL, "the username is", $url2)

Local $url3 = IniRead($ini, 'Pass', 'name', "")
MsgBox($MB_SYSTEMMODAL, "the password is", $url3)

 

  • Like 1

Share this post


Link to post
Share on other sites
sandanet

Thank you Mr.mikell for your help, but is it possible to do it without write any file on the pc even without use delete file command?

Edited by sandanet

Share this post


Link to post
Share on other sites
mikell

It's up to you. If you want to use the Ini* functions then you have to create somewhere a temp ini file (and delete it later) because these funcs need an existing file to be read
If you want no file, then as _INetGetSource returns the whole source code of the page as a string, you must use String* functions. In this case you might have the uploaded text as simple as possible, to make the script easier
Just an example below
 

#include <Array.au3>

; uploaded text as it could be returned by Inet + the 1st StringRegExpReplace from the previous script
$string = "Servername=mywebsite.com" & @crlf & "Username=sandanet" & @crlf & "Pass=123"
Msgbox(0,"", $string)

Msgbox(0,"Servername", StringRegExpReplace($string, '(?s).*Servername=(\S*).*', "$1") )
Msgbox(0,"Username", StringRegExpReplace($string, '(?s).*Username=(\S*).*', "$1") )
Msgbox(0,"Pass", StringRegExpReplace($string, '(?s).*Pass=(\S*).*', "$1") )

$res = StringRegExp($string, '=(\S*)', 3)
_ArrayDisplay($res)


 

Edited by mikell
  • Like 1

Share this post


Link to post
Share on other sites
sandanet

ArrayDisplay function do the job but i think there should be a (for .. net) loop at the end in order to assign each number of row to a variable (&url1, &url2 and &url3) right ?

 

   

Edited by sandanet

Share this post


Link to post
Share on other sites
mikell

Right  :)
But please keep in mind that my example is nothing but an example, to show the concept. Depending on how the uploaded text is written/formatted, the way to extract the data (the regex pattern) may be slightly different

Share this post


Link to post
Share on other sites
sandanet

yes you are right, the way of written data in a txt file need to have rewrite the regex pattern in a proper way..  i agree with you. But your example really was very useful for me thank you alot :D 

Share this post


Link to post
Share on other sites
mikell

You're welcome, glad I could help  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×