#
# f1.close()
#

f2 = open("../data/subreddit_popularity_wayback.txt", "w")

num_submissions = rdb.num_wayback_submissions()

data = {}

counter = 0
num_not_belonging = 0

start = time.time()

for submission in rdb.wayback_submission_list():
    try:
        name = rdb.submission_belongs_to(submission).get("subreddit_name")
    except AttributeError:
        print submission
        num_not_belonging += 1
        continue

    try:
        data[name] += 1
    except KeyError:
        data[name] = 1

    counter += 1
    if counter % 100000 == 0:
        print "Running for:", (time.time() - start) / 60.0, "minutes"