Twitter command-line utility update v.03
Twitter command-line utility update v.03
Version 0.3 of the Twitter command-line interface can be found here:
http://www.newlisp.org/syntax.cgi?code/twitter.txt . Try 'twitter search newlisp'.
ps: also linked from the Tips&Tricks page
http://www.newlisp.org/syntax.cgi?code/twitter.txt . Try 'twitter search newlisp'.
ps: also linked from the Tips&Tricks page
Lutz, is that you @newlisp?
Edit: No, I assume this is you, but are you on as newlisp as well? Greetings from @taoeffect! :-D
Edit: No, I assume this is you, but are you on as newlisp as well? Greetings from @taoeffect! :-D
Get your Objective newLISP groove on.
You'll give into it, sooner or later, everyone does. </cliche> :-DLutz wrote:(probably not used much).
Get your Objective newLISP groove on.
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Just wanted to mention that I deleted my Twitter account a few days ago. I did this because a couple of my entries were “disappeared,” and I had lost confidence in Twitter.
I mention this because I didn’t want those individuals whom I was following to think I simply stopped following them :-)
m i c h a e l
I mention this because I didn’t want those individuals whom I was following to think I simply stopped following them :-)
m i c h a e l
Re: Twitter command-line utility update v.03
Lutz,
Here's my take on the twitter.lsp (v0.3ax) which uses my linked? and command-line stuff. This way the script can be executed either by newlisp.exe on the commandline or after use of link.lsp.
Kind regards,
Bruce.
P.S. I'm not exactly sure where to post this.
Here's my take on the twitter.lsp (v0.3ax) which uses my linked? and command-line stuff. This way the script can be executed either by newlisp.exe on the commandline or after use of link.lsp.
Kind regards,
Bruce.
Code: Select all
#!/usr/bin/newlisp
; post, delete and see user and friends messages and followers on http://twitter.com
; February 12th, 2009, L.M.
; version 0.1
; version 0.2
; added twitter seach
; fields now separated by CR-LF
; records now separated by CR-LF CR-LF
; version 0.3
; eliminated spurious nil in search
; added xml option to search
; version 0.4ax
; better main-args handling. Now using linked? and command-line
; not very graceful about failures, e.g. search without search term
; when no parameters are given, show help text
(define (linked?) (not (starts-with (lower-case (main-args 0)) "newlisp")))
(setq command-line (if (linked?) (main-args) (rest (main-args))))
(setq helptext "EXAMPLES:
twitter userid:pass followers
twitter userid:pass followers xml
twitter userid:pass user
twitter userid:pass user 10
twitter userid:pass friends
twitter userid:pass friends 10
twitter userid:pass delete 1234567890
twitter userid:pass post \"this is a test\"
twitter search the-word-to-search
append \"xml\" to return results as XML"
)
(unless (>= (length command-line) 2)
(println helptext)
(exit)
)
; (println "foo")
(when (= (command-line 1) "search")
; this is a search, no user authentication is required
(setq xml (get-url (string "http://search.twitter.com/search.atom?q=" (command-line 2))))
(when (= (command-line -1) "xml")
(println xml)
(exit))
(xml-type-tags nil nil nil nil) ; no extra tags
(setq sxml (xml-parse xml 31)) ; turn on SXML options
(setq entry-index (ref-all '(entry *) sxml match))
(when (empty? entry-index)
(println "No entries found")
(exit))
(dolist (idx entry-index)
(setq entry (sxml idx))
(println (lookup 'published entry) "\r\n"
(lookup '(author name) entry ) "\r\n"
(lookup 'title entry) "\r\n\r\n"))
(exit))
(define (url-encode str)
(replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0))
; authorization user id and password
(setq user-pass (command-line 1))
(setq auth (append "Authorization: Basic " (base64-enc user-pass) "\r\n"))
(when (= (command-line 2) "followers")
(setq xml (get-url "http://twitter.com/statuses/followers.xml" 5000 auth))
(if (= (command-line -1) "xml")
(println xml)
(println (join (find-all "<screen_name>(.*)</screen_name>" xml $1) "\r\n") "\r\n"))
(exit))
(when (= (command-line 2) "user")
(if (> (length command-line) 3) (setq cnt (command-line 3)) (setq cnt "1"))
;(if-not cnt (setq cnt "1")) ; return only the last post by default
(setq url (append "http://twitter.com/statuses/user_timeline.xml?count=" cnt))
(setq xml (get-url url 5000 auth))
(if (= (command-line -1) "xml")
(println xml)
(begin
(xml-type-tags nil nil nil nil)
(setq sxml (xml-parse xml 31))
(setq sxml (2 (sxml 0)))
(dolist (post sxml)
(println (0 19 (post 1 1)) "\r\n" (post 2 1) "\r\n" (post 3 1) "\r\n\r\n"))
))
(exit))
(when (= (command-line 2) "friends")
(if (> (length command-line) 3) (setq cnt (command-line 3)) (setq cnt "1"))
;(if-not cnt (set 'cnt "1")) ; return only the last post by default
(setq url (append "http://twitter.com/statuses/friends_timeline.xml?count=" cnt))
(setq xml (get-url url 5000 auth))
(if (= (command-line -1) "xml")
(println xml)
(begin
(xml-type-tags nil nil nil nil)
(setq sxml (xml-parse xml 31))
(setq sxml (2 (sxml 0)))
(dolist (post sxml)
(println (0 19 (post 1 1)) "\r\n" (post 10 2 1) "\r\n" (post 3 1) "\r\n\r\n"))
))
(exit))
(when (= (command-line 2) "delete")
(setq url (string "http://twitter.com/statuses/destroy/" (command-line 3) ".xml"))
(setq xml (delete-url url 5000 auth))
(if (= (command-line -1) "xml")
(println xml)
(begin
(if (find "<text>(.*)</text>" xml 0)
(println "deleted: " $1))
(if (find "<error>(.*)</error>" xml 0)
(println "error: " $1))
))
(exit))
(when (= (command-line 2) "post")
(setq url (string "http://twitter.com/statuses/update.xml"))
(setq msg (join (3 command-line) " "))
(setq text (append "status=" (url-encode msg)))
(setq content-type "application/x-www-form-urlencoded")
(setq xml (post-url url text content-type 5000 auth))
(if (= (command-line -1) "xml")
(println xml)
(begin
(if (find "<text>(.*)</text>" xml 0)
(println "posted: " $1))
(if (find "<error>(.*)</error>" xml 0)
(println "error: " $1))
))
(exit))
(println "wrong command")
(println helptext)
(exit)
;eof
P.S. I'm not exactly sure where to post this.
On Unix OSs you could see "/usr/bin/newlisp" or similar in (args 0), so the following might be safer:
although most Unix folks wouldn't use link.lsp, because they would have to compile newLISP anyway, if not running Mac OX X or Ubuntu Linux.
Also, isn't there a way on Windows to combine source with a batch file? There is something here: http://www.newlisp.org/index.cgi?page=Code_Snippets but I am not sure if it still works. It might take care of the 'main-args' issue.
Code: Select all
(if (find "newlisp" (args 0) 1) ... )
Also, isn't there a way on Windows to combine source with a batch file? There is something here: http://www.newlisp.org/index.cgi?page=Code_Snippets but I am not sure if it still works. It might take care of the 'main-args' issue.
Command Line
What is the code to use a Windows OS Shell command to execute a script?
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Open Command Prompt, and type:
where script is the name of the script.
To see more options, type:
I've just found a Windows machine and tried this. Yay, my first time! :)
(The manual gets it spot on, too... :))
Code: Select all
newlisp "script"
To see more options, type:
Code: Select all
newlisp -h
(The manual gets it spot on, too... :))
Welcome to to dark side young Jedi...cormullion wrote: I've just found a Windows machine and tried this. Yay, my first time! :)
Link: Beginners Guides: WindowsXP Command Prompt
-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976
-- Let's Talk Lisp (c) 1976