Created
July 19, 2016 21:14
-
-
Save shatteringlass/7379aeed42df1ff598378f1f46741ed5 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 tweepy | |
from tweepy import OAuthHandler | |
import re | |
consumer_key = 'CONSUMER_KEY' | |
consumer_secret = 'CONSUMER_SECRET' | |
access_token = 'ACCESS_TOKEN' | |
access_secret = 'ACCESS_SECRET' | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_secret) | |
api = tweepy.API(auth) | |
regexp = re.compile(r'guast[a|e|i|o]') | |
def findWholeWord(r,w): | |
if r.search(w) is not None: | |
return True | |
else: | |
return False | |
username = 'infoatac' | |
tweet_cursor = tweepy.Cursor(api.user_timeline,id=username) | |
tweet_nr = 1000 | |
items = tweet_cursor.items(tweet_nr) | |
tweets = open('tweet.txt',"w") | |
matches = open('matches.txt',"w") | |
match_counter = 0 | |
counter = 0 | |
with open('tweet.txt','w') as tweets: | |
with open('matches.txt','w') as matches: | |
for item in items: | |
tweets.write("%s - %s\n" % (item.created_at, item.text)) | |
counter = counter + 1 | |
if findWholeWord(regexp,item.text): | |
matches.write("%s) %s - %s\n" % (match_counter, item.created_at, item.text)) | |
match_counter = match_counter+1 | |
matches.close() | |
tweets.close() | |
print(match_counter/counter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment