?

Log in

No account? Create an account
Hello, I need to do a few bash/gawk scripts to have some basic… - LiveJournal Client Discussions — LiveJournal [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[Nov. 2nd, 2006|07:27 am]
LiveJournal Client Discussions

lj_clients

[mikhailian]
Hello, I need to do a few bash/gawk scripts to have some basic automation for day-to-day tasks. Some of them require a login.

Is there a way to have a simple authentication, without having to mimic the behavior of the browser?
linkReply

Comments:
[User Picture]From: tymofiy
2006-11-02 03:59 pm (UTC)

Python one

import xmlrpclib, md5

server = xmlrpclib.Server("http://www.livejournal.com/interface/xmlrpc:80")

username = 'test'
hpassword = md5.md5('test').hexdigest()
howmany = 2

#that the magic on that grabs 'howmany' posts into plain python variable
result = server.LJ.XMLRPC.getevents({'username': username, 'hpassword': hpassword, 'ver': '1','lineendings': '0x0A', "selecttype": "lastn", "itemid": -1, "howmany": howmany })

#print the last subject
print result['events'][0]['subject']

hope that helps. if you want to - have a look at my python LJ client, http://clear.com.ua/en/projects/python/zapys
(Reply) (Parent) (Thread)
[User Picture]From: vanbeast
2006-11-02 04:21 pm (UTC)

Re: Python one

Thanks for proving my point :) Don't claim it's doable in one line when it takes 7.

Yes, I know you could compress the variable assignments in-line, but if it's at the cost of readability, there's not much value in it.

My point was that there's no reason to be down on the guy who wants to do stuff in bash just because it's easier in your pet language. My pet language is Ruby, where it's certainly at least as easy as what you just posted... but I'm not trying to convert the guy.
(Reply) (Parent) (Thread)
[User Picture]From: tymofiy
2006-11-02 04:29 pm (UTC)

Re: Python one

well, did you expect

import LJ
LJ.get_my_last_post_automagically_guessing password() ?

joking. My point was not to say "you're dumb, cause you do not use ..." but a hint that bash is not the best tool for the task. Because in my experience everyone who knows shell scripting knows at least one language of the mentioned triad.
(Reply) (Parent) (Thread)
[User Picture]From: vanbeast
2006-11-02 04:46 pm (UTC)

Re: Python one

Well, in some languages (*ahem* ruby, perl.. where there are LJ libraries) you can do that... sorta ;)

I apologize, your previous comment read (to me) like the "you're dumb" option and I jumped to conclusions. Sorry about that.

I know quite a few people who can scrape by in bash but don't know other languages, so while I agree with you that it would be easier elsewhere, it's interesting to see what people can do in *sh.
(Reply) (Parent) (Thread)
[User Picture]From: tymofiy
2006-11-02 04:35 pm (UTC)

One-liner

I tried, I really tried... Just can't resist the temptation to post that "one-liner"...

print xmlrpclib.Server("http://www.livejournal.com/interface/xmlrpc:80").LJ.XMLRPC.getevents({'username': 'myusername', 'hpassword': md5.md5('mypasswd').hexdigest(), 'ver': '1','lineendings': '0x0A', "selecttype": "lastn", "itemid": -1, "howmany": 1 })['events'][0]['subject']

but you got to have really big screen to avoid line wraps
(Reply) (Parent) (Thread)
[User Picture]From: vanbeast
2006-11-02 04:43 pm (UTC)

Re: One-liner

AWESOME :D

I come from perl, so I know that style. I love it.
(Reply) (Parent) (Thread)
[User Picture]From: ralesk
2006-11-02 06:57 pm (UTC)

Re: One-liner

Hahaha, yes! That tickled the Perlist in me too :D

(Reply) (Parent) (Thread)