-
-
Save anands/7c03a05ebff477a0fa7f to your computer and use it in GitHub Desktop.
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
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