Last active
July 7, 2019 11:22
-
-
Save rberenguel/5130837 to your computer and use it in GitHub Desktop.
*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 drive…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment