-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.py
31 lines (26 loc) · 938 Bytes
/
twitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#neccessary imports
import tweepy
from decouple import config
import pandas as pd
import csv
import re
import string
import preprocessor as p
#Twitter APIs
consumer_key = config('consumer_key')
consumer_secret = config('consumer_secret')
access_key= config('access_key')
access_secret = config('access_secret')
#Auth through APIs
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)
csvFile = open('scraped_data.csv', 'w')
csvWriter = csv.writer(csvFile)
search_words = "violence" # enter your words
new_search = search_words
#Scraped data from twitter to CSV(Tweet, username)
for tweet in tweepy.Cursor(api.search,q=new_search,count=100,
lang="en",
since_id=0).items():
csvWriter.writerow([tweet.text.encode('utf-8'),tweet.user.screen_name.encode('utf-8')])