Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@anands
Created November 30, 2015 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anands/7c03a05ebff477a0fa7f to your computer and use it in GitHub Desktop.
Save anands/7c03a05ebff477a0fa7f to your computer and use it in GitHub Desktop.
from reddit import *
import json
# Load the data:
posts = False
with open("data.json") as file:
posts = json.load(file)
# Out JSON variable:
outJson = []
# Iterate and claculate the hot score:
for children in posts:
for post in children:
downs = post["data"]["downs"]
ups = post["data"]["ups"]
title = post["data"]["title"]
created = datetime.fromtimestamp(int(post["data"]["created"]))
hotScore = hot(ups, downs, created)
out = {}
out["title"] = title
out["hotScore"] = hotScore
outJson.append(out)
# Sort based on hotScore
def sortScore(json):
try:
return int(json['hotScore'])
except KeyError:
return 0
outJson.sort(key=sortScore, reverse=True)
# Print JSON of top 25 posts:
print json.dumps(outJson[0:25])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment