Ejemplo n.º 1
0
            writer.writerow(n.to_row())


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Data Extractor for Watson Disaster App")
    keyword, locations = Environment.get_runtime_parameters()

    parser.add_argument("path", type=str, help="file path to write")
    parser.add_argument("-kw", type=str, help="keyword to search the tweets")
    parser.add_argument("-loc", type=str, help="locations to search the tweets")
    parser.add_argument("-batchsize", type=int, default=10, help="batch size to write the file")

    args = parser.parse_args()

    keyword = args.kw if args.kw else keyword
    locations = args.loc if args.loc else locations

    create = True
    notifications = []
    print("Search tweets by {0} @ {1}".format(keyword, locations))
    for n in twitter.get_tweets(keyword, locations):
        notifications.append(n)
        if len(notifications) > args.batchsize:
            write(args.path, notifications, create)
            create = False
            notifications = []
        try:
            print(str(n))
        except Exception as ex:
            pass
Ejemplo n.º 2
0
 def test_get_tweets(self):
     for t in twitter.get_tweets("coffee", "-122.39,47.51,-122.28,47.73"):
         self.assertTrue(t.message)
         print(t)
Ejemplo n.º 3
0

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Data Extractor for Watson Disaster App")
    keyword, locations = Environment.get_runtime_parameters()

    parser.add_argument("-kw", type=str, help="keyword to search the tweets")
    parser.add_argument("-loc", type=str, help="locations to search the tweets")
    parser.add_argument("-path", type=str, help="file path to read")
    parser.add_argument("-delimiter", type=str, default=",", help="file delimiter")
    parser.add_argument("--header", action="store_true", help="use header as column definition")
    parser.add_argument("--save", action="store_true", help="don't post to the kintone")

    args = parser.parse_args()

    keyword = args.kw if args.kw else keyword
    locations = args.loc if args.loc else locations

    generator = None
    if args.path:
        print("Read content from {0}".format(args.path))
        generator = file_api.read(args.path, delimiter=args.delimiter, use_header=args.header)
    else:
        print("Search tweets by {0} @ {1}".format(keyword, locations))
        generator = twitter.get_tweets(keyword, locations)

    for n in generator:
        if n.evaluate() and args.save:
            kintone.post(n)
        print(str(n))