Created
March 31, 2013 06:16
-
-
Save sl8r000/5279740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import twitter_grab | |
SCREEN_NAMES = [ | |
'GineokwKoenig', | |
'RealNichelle', | |
'TheRealNimoy', | |
'WilliamShatner', | |
'GeorgeTakei', | |
'levarburton', | |
'jonathansfrakes', | |
'BrentSpiner', | |
'SirPatStew', | |
'wilw' | |
] | |
NUM_TWEETS_PER_SCREEN_NAME = 110 | |
OUTPUT_FILENAME = '1100_tweets.txt' | |
def main(): | |
with open(OUTPUT_FILENAME, 'w') as output_file: | |
for screen_name in SCREEN_NAMES: | |
query = twitter_grab.QueryBuilder() | |
query.screen_name = screen_name | |
query.include_entities = True | |
query.count = NUM_TWEETS_PER_SCREEN_NAME | |
tweets = query.get_tweets() | |
for tweet in tweets: | |
record = twitter_grab.make_record_from_tweet(tweet) | |
sorted_record = sorted(record.items()) | |
record_string = ' '.join( | |
unicode(val).encode('ascii', 'ignore') | |
for key, val in sorted_record) | |
output_file.write(record_string + '\n') | |
print 'Finished with {0}'.format(screen_name) | |
with open(OUTPUT_FILENAME) as reopened_file: | |
ordered_records = reopened_file.readlines() | |
random.shuffle(ordered_records) | |
randomized_records = ordered_records | |
with open(OUTPUT_FILENAME, 'w') as final_write: | |
for record in randomized_records: | |
final_write.write(record) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment