public
Last active

*reddi.py*: Browse reddit from the command line (you'll have to change the location of your python *reddit*: Bindings to use reddipy from within the acme text editor from plan9ports (Plan 9 from User Space) reddit assumes reddi.py is in the same folder. Change it to suit your tastes. To read a little more about the shell reddit script that drives acme, please read this post I wrote: http://www.mostlymaths.net/2013/03/extensibility-programming-acme-text-editor.html

  • Download Gist
reddi.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python
 
import urllib,json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument( 'subreddit', nargs=1,help="Subreddit to browse, f.e. programming")
args= parser.parse_args()
subreddit = args.subreddit[0]
a = urllib.urlopen('http://www.reddit.com/r/'+str(subreddit)+'/.json')
try:
k = json.load(a)
j=k['data']
except KeyError:
print "Problem reading reddit data. Please, try again in a few seconds"
exit()
storieslist = j['children']
counter=0
for x in storieslist[0:9]:
counter=counter+1
title = x['data']['title']
URL = x['data']['url']
shortened = urllib.urlopen("http://is.gd/api.php?longurl="+URL).read()
votes = x['data']['score']
longer="..." if len(URL)>35 else "\t"
print str(counter)+"\t"+str(votes)+"\t"+title.encode("utf-8", "ignore")[0:35]+"..."
print "\t\t"+URL.encode("utf-8", "ignore")[0:35]+longer+ "\t" + shortened
reddit
Shell
1 2 3 4 5 6 7 8
#!/bin/zsh
./reddi.py $1 | 9p write acme/new/body
last=$(9p ls acme | sort -g | tail -n 1)
echo "name http://reddit.com/r/$1" | 9p write acme/$last/ctl
echo -n "clean" | 9p write acme/$last/ctl
echo -n "0,0" | 9p write acme/$last/addr
echo -n "dot=addr" | 9p write acme/$last/ctl
echo -n "show" | 9p write acme/$last/ctl

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.