예제 #1
0
def main():
    parser = get_parser()
    args = parser.parse_args()

    if args.doc:
        print __doc__
        sys.exit()

    g = geosearchclass.GeoSearchClass()

    if args.params:
        print 'Using parameters from ' + str(args.params)
        # turn parameter file into dictionary
        g.set_params_from_file(args.params)
        
    if args.address:
        print "Finding geocoordates for address:\n{}".format(args.address)
        coords = geo_converter.get_geocoords_from_address(args.address)
        if coords:
            g.latitude = coords[0]
            print "Found this latitude:"
            print g.latitude
            g.longitude = coords[1]
            print "Found this longitude:"
            print g.longitude
        else:
            print "Failed to find coordinates. Exiting."
            sys.exit()

    if args.input:
        text = utils.load_file(args.input)
        tokens = utils.tokenize_normal_words(text)
        for_poem = utils.filter_words(tokens)
    else:
        for_poem = get_default_words()

    if args.markov:
        if args.input:
            raise StandardError("Can only input a single text file. \
use --markov <your_text_file.txt>")
        else:
            text = utils.load_file(args.markov)
            # ngram = ngrams.make_ngram(text, 2)
            ngram = ngrams.make_bigram_trigram_dictionary(text)
            formatted_poem = create_poem(g, for_poem, ngram)
    else:
        formatted_poem = create_poem(g, for_poem)

    if args.output:
        print '\nwriting formatted poem to ' + str(args.output)
        output_file = args.output
    else:
        print "\nwriting formatted poem to poem.txt"
        output_file = "poem.txt"

    utils.save_file(output_file, formatted_poem)
예제 #2
0
def main():
    parser = get_parser()
    args = parser.parse_args()
    # print args
    # print args.help

    if args.doc:
        print __doc__
        import sys
        sys.exit(0)

    if args.number:
        number = int(args.number)
    else:
        number = 30

    g = geosearchclass.GeoSearchClass()

    if args.filename:
        print 'Using parameters from ' + str(args.filename)
        g.set_params_from_file(args.filename)
    else:
        print "Using search values from params.txt"
        g.set_params_from_file('params.txt')

    if args.address:
        print "Finding geocoordates for address:\n{}".format(args.address)
        coords = geo_converter.get_geocoords_from_address(args.address)
        if coords:
            g.latitude = coords[0]
            print "Found this latitude:"
            print g.latitude
            g.longitude = coords[1]
            print "Found this longitude:"
            print g.longitude
        else:
            print "Failed to find coordinates. Exiting."
            sys.exit()

    if args.stream:
        print "using streaming queue"
        q = Queue.Queue()
        bounding_box = geo_converter.get_bounding_box_from(g)
        search_terms = geo_converter.get_search_terms_from(g)
        print "bounding_box = {}".format(bounding_box)
        print "search_terms = {}".format(search_terms)
        global stream
        fn = 'tweets.json'
        stream = streamer.start_stream(q, bounding_box, fn, search_terms)
        updating_stream_plot(q, number)
    else:
        print "using REST API updating plot"
        updating_plot(g, number, True)  # set grow flag to True
예제 #3
0
def main():
    parser = get_parser()
    args = parser.parse_args()
    # print args
    # print args.help

    if args.doc:
        print __doc__
        import sys
        sys.exit(0)

    if args.number:
        number = int(args.number)
    else:
        number = 30

    g = geosearchclass.GeoSearchClass()

    if args.filename:
        print 'Using parameters from ' + str(args.filename)
        g.set_params_from_file(args.filename)
    else:
        print "Using search values from params.txt"
        g.set_params_from_file('params.txt')

    if args.address:
        print "Finding geocoordates for address:\n{}".format(args.address)
        coords = geo_converter.get_geocoords_from_address(args.address)
        if coords:
            g.latitude = coords[0]
            print "Found this latitude:"
            print g.latitude
            g.longitude = coords[1]
            print "Found this longitude:"
            print g.longitude
        else:
            print "Failed to find coordinates. Exiting."
            sys.exit()

    if args.stream:
        print "using streaming queue"
        q = Queue.Queue()
        bounding_box = geo_converter.get_bounding_box_from(g)
        search_terms = geo_converter.get_search_terms_from(g)
        print "bounding_box = {}".format(bounding_box)
        print "search_terms = {}".format(search_terms)
        global stream
        fn = 'tweets.json'
        stream = streamer.start_stream(q, bounding_box, fn, search_terms)
        updating_stream_plot(q, number)
    else:
        print "using REST API updating plot"
        updating_plot(g, number, True)  # set grow flag to True
예제 #4
0
def main():
    parser = get_parser()
    args = parser.parse_args()

    if args.doc:
        print __doc__
        sys.exit()

    g = geosearchclass.GeoSearchClass()

    if args.params_file:
        print 'Using parameters from ' + str(args.filename)
        # turn parameter file into dictionary
        g.set_params_from_file(args.filename)

    if args.address:
        print "Finding geocoordates for address:\n{}".format(args.address)
        coords = geo_converter.get_geocoords_from_address(args.address)
        if coords:
            g.latitude = coords[0]
            print "Found this latitude:"
            print g.latitude
            g.longitude = coords[1]
            print "Found this longitude:"
            print g.longitude
        else:
            print "Failed to find coordinates. Exiting."
            sys.exit()

    formatted_poem = create_poem(for_poem, g)
    
    if args.output:
        print '\nwriting formatted poem to ' + str(args.output)
        output_file = args.output
    else:
        print "\nwriting formatted poem to output.txt"
        output_file = "output.txt"

    fileSystemEncoding = sys.getfilesystemencoding()
    OUTPUT_FILE = os.path.expanduser(u'./' + output_file)
    with codecs.open(OUTPUT_FILE,
                     encoding=fileSystemEncoding,
                     mode="w") as f:
        f.write(formatted_poem)
예제 #5
0
def main():
    parser = get_parser()
    args = parser.parse_args()

    if args.doc:
        print __doc__
        import sys
        sys.exit(0)

    # pass in an API to GeoSearchClass to get full access for posting
    (api, __) = utils.get_credentials('consumerkeyandsecret', False)
    g = geosearchclass.GeoSearchClass('params.txt', None, api)

    if args.filename:
        print 'Using parameters from ' + str(args.filename)
        g.set_params_from_file(args.filename)
    else:
        print "Using search values from params.txt"
        g.set_params_from_file('params.txt')

    if args.output:
        fn = str(args.output)
    else:
        fn = 'tweets.json'
    print 'Output file: ' + fn

    if args.address:
        print "Finding geocoordates for address:\n{}".format(args.address)
        coords = geo_converter.get_geocoords_from_address(args.address)
        if coords:
            g.latitude = coords[0]
            g.longitude = coords[1]
        else:
            print "Failed to find coordinates"
            sys.exit()

    verify(g, fn)
예제 #6
0
def main():
    parser = get_parser()
    args = parser.parse_args()

    if args.doc:
        print __doc__
        import sys
        sys.exit(0)

    # pass in an API to GeoSearchClass to get full access for posting
    (api, __) = utils.get_credentials('consumerkeyandsecret', False)
    g = geosearchclass.GeoSearchClass('params.txt', None, api)

    if args.filename:
        print 'Using parameters from ' + str(args.filename)
        g.set_params_from_file(args.filename)
    else:
        print "Using search values from params.txt"
        g.set_params_from_file('params.txt')

    if args.output:
        fn = str(args.output)
    else:
        fn = 'tweets.json'
    print 'Output file: ' + fn

    if args.address:
        print "Finding geocoordates for address:\n{}".format(args.address)
        coords = geo_converter.get_geocoords_from_address(args.address)
        if coords:
            g.latitude = coords[0]
            g.longitude = coords[1]
        else:
            print "Failed to find coordinates"
            sys.exit()

    verify(g, fn)