Jump to content

Read file .txt from the Internet and assign the variable text from this file


Recommended Posts

Posted (edited)

Hello everyone!
Found a code on the forum:

(defun readwwwtxt ( / obj rtn )
        (if (setq obj (vlax-get-or-create-object "winhttp.winhttprequest.5.1"))
            (progn
                (setq rtn
                    (vl-catch-all-apply
                        (function
                            (lambda ( )
                                (vlax-invoke-method obj 'open "GET"
                                    (strcat 
                                        "http://www.theswamp.org/lilly.pond/public/GetFileFromURL.txt"
                                    )
                                    :vlax-false
                                )
                                (vlax-invoke-method obj 'send)
                                (vlax-get-property  obj 'responsebody)
                            )
                        )
                    )
                )
                (vlax-release-object obj)
                (if (vl-catch-all-error-p rtn)
                    (princ (vl-catch-all-error-message rtn))
                    (princ
                        (vl-list->string
                            (mapcar '(lambda ( x ) (lsh (lsh x 24) -24))
                                (vlax-safearray->list (vlax-variant-value rtn))
                            )
                        )
                    )
                )
            )
        )

    (princ)
)

This program reads the contents of a text file from the Internet and writes to the command line.

Specifically, in this case, it is written to the command line: Test file.

Please tell me how I can assign the result of the program to a variable?

Tried to do just:

(setq simple_variable (readwwwtxt))

But I did not work. 

Edited by dilan
Posted (edited)

hi,simply remove the last

 

(princ)

 

which suppressed the rtn value

Edited by hanhphuc
  • Thanks 1
Posted
54 minutes ago, hanhphuc said:

hi,simply remove the last

 


(princ)

 

which suppressed the rtn value

thank you

Posted (edited)

Here is the original code for my function:

http://www.theswamp.org/index.php?topic=46438.msg514570#msg514570

 

Here is another implementation of the method:

http://www.theswamp.org/index.php?topic=45220.msg504240#msg504240

 

And here is the likely source of where you found the code in your post:

http://www.theswamp.org/index.php?topic=45700.msg508403#msg508403

Edited by Lee Mac
  • Thanks 2
Posted
4 hours ago, Lee Mac said:

Here is the original code for my function:

http://www.theswamp.org/index.php?topic=46438.msg514570#msg514570

 

Thank you Lee! Do you know is it possible to access the HTML DOM ?

 

 

4 hours ago, Lee Mac said:

Here is another implementation of the method:

http://www.theswamp.org/index.php?topic=45220.msg504240#msg504240

 

And here is the likely source of where you found the code in your post:

http://www.theswamp.org/index.php?topic=45700.msg508403#msg508403

 

I've found these too, because OP didn't mentioned the source. 🕵️‍♂️

  • Thanks 1
Posted

One more question, how to check from lisp internet connection ?

Posted (edited)

 

7 hours ago, dilan said:

One more question, how to check from lisp internet connection ?

 

I learned a bit 'ipconfig' & 'ping' from telco technician during troubleshoot. eg: ping 192.168.0.1 etc..

my attempt not an elegant way, simply uses windows 'command' ping'ing  IP address merely checking for connection

 

 

Quote

ping /?

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-c compartment] [-p]
            [-4] [-6] target_name

 

i.e:  test count = 4

(defun c:ping (/ fn str ret i f )
  (alert
    (strcat "\nConnection is "
	    (if	(and (setq fn (strcat (getvar 'tempprefix) "ping.txt"))
		     (vl-cmdf "_.shell" (strcat "ping www. -n 4 > " fn))
		     (progn (alert "\nChecking internet.. \nOK to continue.") (findfile fn))
		     (setq f (open fn "r"))
		     (progn (while (setq str (read-line f))
			      (if (wcmatch str "*#%*")
				(setq ret str)
				) 
			      ) 
			    (if	f
			      (close f)
			      ) 
			    ret
			    )
		     (setq i (mapcar ''((a b) (+ a (vl-string-search b ret))) '(2 1) '("(" "%")))
		     (zerop (read (substr ret (car i) (apply '- (reverse i)))))
		     ) 
	      "OK!"
	      "failed!"
	      ) 
	    ) 
    ) 
  (princ)
  ) 

 

 

Edited by hanhphuc
sym f localized, ping /? info
Posted
12 hours ago, dilan said:

One more question, how to check from lisp internet connection ?

 

Just browse on google:  Is internet connection available

Although makes me thing if the readwwtxt returns nil,

wouldn't that mean that either the txt file cannont be accessed, or theres no internet connection?

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...