Exemplo n.º 1
0
Arquivo: index.py Projeto: jarek/pb
    isCGI = 'GATEWAY_INTERFACE' in os.environ

    if not isCGI:
        print 'this script is designed to be used over the web'
        #exit(1)

    print 'Content-Type: text/html\n'

    args = cgi.FieldStorage()
    #args = []

    comics = pbcore.get_comics_from_file('2013-08-29--11-41-pst-polandball comic archive-30 percent done.csv').values()

    if not ('country' in args or 'topic' in args):
        # print list of most common countries; and most common subjects
        countries = pbcore.count_tags(comics, pbcore.COUNTRIES_ROW_NAME)
        print_collection(countries, pbcore.COUNTRIES_ROW_NAME)

        topics = pbcore.count_tags(comics, pbcore.TOPICS_ROW_NAME)
        print_collection(topics, pbcore.TOPICS_ROW_NAME)

    elif 'country' in args:
        # search for tag, print comics
        country_comics = pbcore.find_comics_by_tag(comics, \
                pbcore.COUNTRIES_ROW_NAME, args['country'].value.decode('utf8'))

        for comic in country_comics:
            print '%s %s' % (comic['id'], comic['title'].decode('utf-8'))

    elif 'topic' in args:
        # search for tag, print comics