def test_tweet_usermention(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.usermention.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.usermention.csv') json2csv_entities(self.infile, outfn, ['id', 'text'], 'user_mentions', ['id', 'screen_name'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_tweet_place_boundingbox(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.placeboundingbox.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.placeboundingbox.csv') json2csv_entities(self.infile, outfn, ['id', 'name'], 'place.bounding_box', ['coordinates'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_tweet_url(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.url.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.url.csv') json2csv_entities(self.infile, outfn, ['id'], 'urls', ['url', 'expanded_url'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_tweet_hashtag(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.hashtag.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.hashtag.csv') json2csv_entities(self.infile, outfn, ['id', 'text'], 'hashtags', ['text'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_userurl(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.userurl.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.userurl.csv') json2csv_entities(self.infile, outfn, ['id', 'screen_name'], 'user.urls', ['url', 'expanded_url'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_retweet_original_tweet(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.retweet.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.retweet.csv') json2csv_entities(self.infile, outfn, ['id'], 'retweeted_status', ['created_at', 'favorite_count', 'id', 'in_reply_to_status_id', 'in_reply_to_user_id', 'retweet_count', 'text', 'truncated', 'user.id'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_tweet_place_boundingbox(self): ref_fn = os.path.join( self.subdir, 'tweets.20150430-223406.placeboundingbox.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join( tempdir, 'tweets.20150430-223406.placeboundingbox.csv') json2csv_entities(self.infile, outfn, ['id', 'name'], 'place.bounding_box', ['coordinates'], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
def test_retweet_original_tweet(self): ref_fn = os.path.join(self.subdir, 'tweets.20150430-223406.retweet.csv.ref') with TemporaryDirectory() as tempdir: outfn = os.path.join(tempdir, 'tweets.20150430-223406.retweet.csv') json2csv_entities( self.infile, outfn, ['id'], 'retweeted_status', [ 'created_at', 'favorite_count', 'id', 'in_reply_to_status_id', 'in_reply_to_user_id', 'retweet_count', 'text', 'truncated', 'user.id' ], gzip_compress=False) self.assertTrue(are_files_identical(outfn, ref_fn), msg=self.msg)
from twython import Twython import csv import json from nltk.twitter import Query, Streamer, Twitter, TweetViewer, TweetWriter, credsfromfile from nltk.twitter.util import json2csv from nltk.twitter.util import json2csv_entities with open('C:/Users/Admin/data/mydir/aapl.json') as fp: json2csv_entities(fp, 'tweets.csv', ['id', 'text'], 'place', ['name', 'country'])