import json
import os
from collections import defaultdict

directory = 'repos_info'
license_dict = defaultdict(int)

def filename2repo(filename):
    """
    Given a filename, returns the (owner, reponame) tuple
    """
    pass



for filename in os.listdir(directory):
    with open(directory + "/" + filename) as json_file:
        repodata = json.load(json_file)
        if repodata['data']['license']:
            license = repodata['data']['license']['key']
            print(filename, license, repodata['data']['license']['spdx_id'])
            license_dict[license] += 1
        else:
            print(filename, "Other")
            license_dict["Other"] += 1

print()
print(sorted(license_dict.items(), key=lambda x:x[1], reverse=True))
