Ejemplo n.º 1
0
def get_presenters(year):
    '''Presenters is a dictionary with the hard coded award
    names as keys, and each entry a list of strings. Do NOT change the
    name of this function or what it returns.'''

    clean_path = 'data/clean_gg' + year + '.json'
    if not os.path.exists(clean_path):
        pre_ceremony()

    sorted_path = 'data/sorted_gg' + year + '.json'
    if not os.path.exists(sorted_path):
        sort_tweets.main(year, award_list)

    with open(sorted_path, 'r') as f:
        award_tweets = json.load(f)
    f.close()

    processed_path = 'results/partial_gg%s.json' % year
    if not os.path.exists(processed_path):
        process_tweets.main(year, award_tweets)

    with open(processed_path, 'r') as f:
        data = json.load(f)
    f.close()

    presenters = {}
    for award in data:
        if award == 'hosts':
            continue
        presenters[award] = data[award]['presenters']
    return presenters
Ejemplo n.º 2
0
def get_nominees(year, winner):
    '''Nominees is a dictionary with the hard coded award
    names as keys, and each entry a list of strings. Do NOT change
    the name of this function or what it returns.'''
    if os.path.exists('results/partial_gg%s.json' % year):
        with open('results/partial_gg%s.json' % year, 'r') as f:
            data = json.load(f)
        f.close()
    else:
        process_tweets.main(year, award_tweets, sw)

    person_nominees = query_nominees_rahul.main(year, OFFICIAL_AWARDS_1315)

    nominees = {}
    for award in OFFICIAL_AWARDS_1315:
        is_person = any([
            title in award for title in [
                'actor', 'actress', 'director', 'screenplay', 'original',
                'cecil'
            ]
        ])
        if is_person:
            nominees[award] = person_nominees[award]
        else:
            nominees[award] = data[award]['nominees']
        if winner not in nominees[award]:
            nominees[award].append(winner)
    return nominees
Ejemplo n.º 3
0
def main():
    '''This function calls your program. Typing "python gg_api.py"
    will run this function. Or, in the interpreter, import gg_api
    and then run gg_api.main(). This is the second thing the TA will
    run when grading. Do NOT change the name of this function or
    what it returns.'''

    year = sys.argv[1]
    print('Welcome to the %s Golden Globes!' % year)

    # hosts = get_hosts(year)
    # awards = get_awards(year)
    hosts = []
    awards = []

    sorted_path = 'data/sorted_gg%s.json' % year
    if os.path.exists(sorted_path):
        with open(sorted_path, 'r') as f:
            award_tweets = json.load(f)
        f.close()
    else:
        award_tweets = sort_tweets.main(year, OFFICIAL_AWARDS_1315)
        with open(sorted_path, 'w+') as f:
            json.dump(award_tweets, f)
        f.close()

    gg_sw = []
    sw = [
        'actor', 'actress', 'tv', 'television', 'series', 'film', 'comedy',
        'drama', 'director'
    ]

    process_tweets.main(year, award_tweets, sw)

    show = {'hosts': hosts, 'awards': awards}

    winners = get_winner(year)
    nominees = get_nominees(year)
    presenters = get_presenters(year)
    # print(nominees.keys())
    # print('-' * 40)
    for award in OFFICIAL_AWARDS_1315:
        # try:
        #     print(nominees[award])
        # except:
        #     print(award)
        #     continue
        show[award] = {
            'winner': winners[award],
            'nominees': nominees[award],
            'presenters': presenters[award]
        }

    with open('results/gg' + year + '.json', 'w+') as f:
        json.dump(show, f)
    f.close()
Ejemplo n.º 4
0
def main():
    '''This function calls your program. Typing "python gg_api.py"
    will run this function. Or, in the interpreter, import gg_api
    and then run gg_api.main(). This is the second thing the TA will
    run when grading. Do NOT change the name of this function or
    what it returns.'''

    if len(sys.argv) != 2:
        print('Invalid Year')
        return

    year = sys.argv[1]
    print('Welcome to the %s Golden Globes!' % year)
    if os.path.exists('results/gg' + year + '.json'):
        return

    award_list = OFFICIAL_AWARDS_1315 if year in ['2013', '2015'
                                                  ] else OFFICIAL_AWARDS_1819

    best_dressed = query_best_dressed.main(year)

    hosts = get_hosts(year)
    awards = get_awards(year)

    sorted_path = 'data/sorted_gg' + year + '.json'
    if not os.path.exists(sorted_path):
        sort_tweets.main(year, award_list)

    with open(sorted_path, 'r') as f:
        award_tweets = json.load(f)
    f.close()

    processed_path = 'results/partial_gg' + year + '.json'
    if not os.path.exists(processed_path):
        process_tweets.main(year, award_tweets, sw)

    show = {'hosts': hosts, 'awards': awards, 'best_dressed': best_dressed}

    winners = get_winner(year)
    nominees = get_nominees(year)
    presenters = get_presenters(year)

    for award in award_list:
        show[award] = {
            'winner': winners[award],
            'nominees': nominees[award],
            'presenters': presenters[award]
        }

    with open('results/gg' + year + '.json', 'w+') as f:
        json.dump(show, f)
    f.close()
Ejemplo n.º 5
0
def get_presenters(year):
    '''Presenters is a dictionary with the hard coded award
    names as keys, and each entry a list of strings. Do NOT change the
    name of this function or what it returns.'''
    if os.path.exists('results/partial_gg%s.json' % year):
        with open('results/partial_gg%s.json' % year, 'r') as f:
            data = json.load(f)
        f.close()
    else:
        process_tweets.main(year, award_tweets, sw)

    presenters = {}
    for award in data:
        if award == 'hosts':
            continue
        presenters[award] = data[award]['presenters']
    return presenters
Ejemplo n.º 6
0
def get_nominees(year):
    '''Nominees is a dictionary with the hard coded award
    names as keys, and each entry a list of strings. Do NOT change
    the name of this function or what it returns.'''

    award_list = OFFICIAL_AWARDS_1315 if year in ['2013', '2015'
                                                  ] else OFFICIAL_AWARDS_1819

    clean_path = 'data/clean_gg' + year + '.json'
    if not os.path.exists(clean_path):
        pre_ceremony()

    sorted_path = 'data/sorted_gg' + year + '.json'
    if not os.path.exists(sorted_path):
        sort_tweets.main(year, award_list)

    with open(sorted_path, 'r') as f:
        award_tweets = json.load(f)
    f.close()

    processed_path = 'results/partial_gg%s.json' % year
    if not os.path.exists(processed_path):
        process_tweets.main(year, award_tweets)

    with open(processed_path, 'r') as f:
        data = json.load(f)
    f.close()

    person_nominees = query_nominees_rahul.main(year)

    nominees = {}
    for award in award_list:
        is_person = any([
            title in award for title in [
                'actor', 'actress', 'director', 'screenplay', 'original',
                'cecil'
            ]
        ])
        if is_person:
            nominees[award] = person_nominees[award]
        else:
            nominees[award] = data[award]['nominees']
    return nominees