News for hackers. Stuff that matters.
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @04:21AM (#3399174)
Please feel free to leave me some harsh feedback!
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by zalew on Wednesday December 28, 2011 @06:19AM (#3399413)
why assume someone uses sudo and is in sudoers, or that sudo is even present?

also 'install feedparser' could be easily replaced by specifying a requirement for pip, or even runnning 'pip install feedparser' from the function if you really want to do it this way.

better package it properly, write a setup like this http://docs.python.org/distutils/setupscript.html and save a .sh wrapper script in /usr/local/bin, this way you can update the package without messing with setup.py every time.

some cosmetic/pythonic:

    if feedparser.parse(subreddit_url).has_key("bozo_exception"):
        return False
    return True
->

    return not feedparser.parse(subreddit_url).has_key("bozo_exception")


    for post in rss["items"]:
        print "%s%s\n%s%s\n%s" % (COLOR_RED, post["title"], COLOR_CYAN, post["link"], COLOR_OFF)

->

    print ["%s%s\n%s%s\n%s" % (COLOR_RED, post["title"], COLOR_CYAN, post["link"], COLOR_OFF) for post in rss['items']]
;)
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @06:40AM (#3399459)
I've included the cosmetic/pythonic changes and I'm going to take some time to read through the link you left me.

Do you have any recommendations for what I should use other than sudo? This was meant to work under Ubuntu (my OS), but I'd like to extend it so that it will work on any platform.

Thanks :)

Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @09:26AM (#3399811)
Update:

1) I've conformed setup.py to distutils, so it's a lot prettier now.

2) I tried using the print [this for this in that] style, but that didn't work out as planned. The actual list itself was printed and the colors didn't work.

3) I'm still using sudo to set the chmod and to move reddit.py to /usr/local/bin, what alternatives are there? On my system I can't do either without sudo.

Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by zalew on Wednesday December 28, 2011 @11:56AM (#3400385)
2. oh yeah, my bad.

3. frankly I don't know why you insist on copying this file with the installer. can't the user copy it themselves? if they want to use your app in shell terminal, it means they heavily use shell terminal, which means they know how to cp file /usr/local/bin or set a link. it's not a case of alternative to sudo, it's a matter of gaining permission to access write to /, Ubuntu (and some other) just has sudo set up out of the box, and a lot of Linux users do it anyway, but it's not required to use or even have sudo. you can also try to add an alias to ~/.bashrc, user has access to that file, but I doubt anyone will like you more for overriding their bashrc ;) (and it also assumes user uses bash, which also isn't required :))

Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @12:16PM (#3400468)
Would appending the scripts current location to PATH be a better idea?
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by ubertaco on Wednesday December 28, 2011 @01:04PM (#3400658)
For 3: Look into using Distribute ( http://packages.python.org/distribute/ ). It'll let you specify the "scripts" parameter to the setup() function, which handles placing executables in the OS's PATH.
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jaspersfather on Wednesday December 28, 2011 @06:04AM (#3399382)
Instead of

    if bla in [bla, blubb, bfoo]:
      return True
    return False
you can write:

    return bla in [bla, blubb, foo]
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @06:39AM (#3399455)
Done! Thanks :)
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by kracekumar on Wednesday December 28, 2011 @06:06AM (#3399388)
use argparse .
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @06:40AM (#3399460)
I'm reading through a bit of the Python docs right now, but after I finish I'll check out argparse.

Much appreciated. :)

Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by kracekumar on Wednesday December 28, 2011 @06:53AM (#3399489)
My pleasure. In case I have time I ll try forking it. :)
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @10:40AM (#3400064)
argparse is such a cool module! Whoever knew that command line arguments could be dealt with in a such a beautiful way?

I've integrated it into reddit.py and it made the `if __name__ == "__main__"` block look much more professional.

Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by brcrth on Wednesday December 28, 2011 @05:58AM (#3399366)
Why usr/bin instead of usr/local/bin?
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @06:34AM (#3399442)
What's the difference here? I would think /usr/bin would have the advantage of being available system-wide rather than on just one account, but I'm not terribly unix-smart.

Enlighten me?

Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by brcrth on Wednesday December 28, 2011 @07:04AM (#3399504)
Re:Show HN: reddit.py - View reddit's RSS feed from your ter... by jmau5 on Wednesday December 28, 2011 @08:24AM (#3399666)
That was incredibly eye opening, I never realized that where you placed something could actually be important.

Thanks for the link, have some karma! :)