import json , urllib.request # Generates some fun ratings for TCSF001 - Python 3 is required page = json . loads ( urllib . request . urlopen ( 'http://api.reddit.com/r/tinycode/search?q=[TCSF001]&restrict_sr=true' ) . read () . decode ( 'utf-8' )) #page = json.loads(urllib.request.urlopen('http://pmdx.me/test.txt').read().decode('utf-8')) def show ( title , criteria ): posts = sorted ( page [ 'data' ][ 'children' ], key = criteria ) first = posts [ 0 ] if not str ( posts [ 0 ][ 'data' ][ 'created' ]) == '1429471144.0' else posts [ 1 ] # Ignore content post print ( ' %s : [ %s ](http://www.reddit.com %s )' % ( title , first [ 'data' ][ 'title' ], first [ 'data' ][ 'permalink' ])) show ( 'Highest Rated' , lambda post : - post [ 'data' ][ 'score' ]) show ( 'Lowest Rated' , lambda post : post [ 'data' ][ 'score' ]) show ( 'Most Controversial' , lambda post : post [ 'data' ][ 'ups' ] + post [ 'data' ][ 'downs' ]) show ( 'Newest' , lambda post : - post [ 'data' ][ 'created' ]) show ( 'Oldest' , lambda post : post [ 'data' ][ 'created' ]) show ( 'Most Comments' , lambda post : post [ 'data' ][ 'num_comments' ]) show ( 'Fewest Comments' , lambda post : - post [ 'data' ][ 'num_comments' ]) show ( 'Most Up Votes' , lambda post : post [ 'data' ][ 'ups' ]) show ( 'Most Down Votes' , lambda post : - post [ 'data' ][ 'downs' ])