import tweepy
import json
import sqlite3
import re 
from collections import defaultdict
from itertools import groupby
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
from textblob import TextBlob
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
import requests
from wordcloud import WordCloud
import os
import csv
import codecs

#SearchAPI

# with open("twitter_credentials.json", "r") as file: 
# creds = json.load(file)


consumer_key = '' # put your own key and other values
consumer_secret = ''

access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)


# auth = tweepy.OAuthHandler(creds['CONSUMER_KEY'], creds['CONSUMER_SECRET'])
# auth.set_access_token(creds['ACCESS_TOKEN'], creds['ACCESS_SECRET'])


# Create the api to connect to twitter with your creadentials
api = tweepy.API(auth, wait_on_rate_limit=True)
term = '@atsipras OR @kmitsotakis OR @FofiGennimata OR @akyrwnoume'
# Get the full list of followers of a particular user
list_of_tweets=[]

tweetString = ''
tweet_text = ''
list_of_tweets = tweepy.Cursor(api.search, q=term, lang='en').items(300)

with codecs.open('tweets_'+term+'.csv', 'w', 'utf8')as f:
    for tweet in list_of_tweets:
        
        
        #get in a string the list of hashtags used by each tweet
        hashtag_list=[]
        for hashtag_entity in tweet.entities['hashtags']:
            
            hashtag_list.append('#'+hashtag_entity['text'])
        #save the hashtag list to a string
        hashtags_str = "-".join(x for x in hashtag_list)
        #remove line feed characters from tweet
        tweet_text = tweet.text.replace("\r", "")
        tweet_text = tweet_text.replace("\n", "")
        tweet_text = tweet_text.replace(",", "")
        tweet_text = tweet_text.replace("\"", "'")
        tweet_text = re.sub(r"http\S+", "", tweet_text)
        tweet_text = re.sub(r"RT @\S+ ", "", tweet_text)

        #remove special characters and lowercase
        tweet_text = re.sub('[-!@#$:).;,?&]', " ", tweet_text)
        tweet_text = tweet_text.replace(' ', ' ')
        tweet_text = tweet_text.lower()
        f.write("%d, %s, %s, %s, @%s, \"%s\", %s, %s, %s, %s, %s \n" % (tweet.id, tweet.id_str,tweet.user.location,
        tweet.user.profile_background_color,tweet.retweet_count, 
        tweet.user.screen_name,tweet.created_at,tweet.user.created_at,tweet_text, hashtags_str,tweet.favorite_count))



c72694c1330550c3410dfa215746b92d5d113615
<mask token>

<mask token>
auth.set_access_token(access_token, access_token_secret)
<mask token>
with codecs.open('tweets_' + term + '.csv', 'w', 'utf8') as f:
    for tweet in list_of_tweets:
        hashtag_list = []
        for hashtag_entity in tweet.entities['hashtags']:
            hashtag_list.append('#' + hashtag_entity['text'])
        hashtags_str = '-'.join(x for x in hashtag_list)
        tweet_text = tweet.text.replace('\r', '')
        tweet_text = tweet_text.replace('\n', '')
        tweet_text = tweet_text.replace(',', '')
        tweet_text = tweet_text.replace('"', "'")
        tweet_text = re.sub('http\\S+', '', tweet_text)
        tweet_text = re.sub('RT @\\S+ ', '', tweet_text)
        tweet_text = re.sub('[-!@#$:).;,?&]', ' ', tweet_text)
        tweet_text = tweet_text.replace(' ', ' ')
        tweet_text = tweet_text.lower()
        f.write('%d, %s, %s, %s, @%s, "%s", %s, %s, %s, %s, %s \n' % (tweet
            .id, tweet.id_str, tweet.user.location, tweet.user.
            profile_background_color, tweet.retweet_count, tweet.user.
            screen_name, tweet.created_at, tweet.user.created_at,
            tweet_text, hashtags_str, tweet.favorite_count))

<mask token>
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
term = '@atsipras OR @kmitsotakis OR @FofiGennimata OR @akyrwnoume'
list_of_tweets = []
tweetString = ''
tweet_text = ''
list_of_tweets = tweepy.Cursor(api.search, q=term, lang='en').items(300)
with codecs.open('tweets_' + term + '.csv', 'w', 'utf8') as f:
    for tweet in list_of_tweets:
        hashtag_list = []
        for hashtag_entity in tweet.entities['hashtags']:
            hashtag_list.append('#' + hashtag_entity['text'])
        hashtags_str = '-'.join(x for x in hashtag_list)
        tweet_text = tweet.text.replace('\r', '')
        tweet_text = tweet_text.replace('\n', '')
        tweet_text = tweet_text.replace(',', '')
        tweet_text = tweet_text.replace('"', "'")
        tweet_text = re.sub('http\\S+', '', tweet_text)
        tweet_text = re.sub('RT @\\S+ ', '', tweet_text)
        tweet_text = re.sub('[-!@#$:).;,?&]', ' ', tweet_text)
        tweet_text = tweet_text.replace(' ', ' ')
        tweet_text = tweet_text.lower()
        f.write('%d, %s, %s, %s, @%s, "%s", %s, %s, %s, %s, %s \n' % (tweet
            .id, tweet.id_str, tweet.user.location, tweet.user.
            profile_background_color, tweet.retweet_count, tweet.user.
            screen_name, tweet.created_at, tweet.user.created_at,
            tweet_text, hashtags_str, tweet.favorite_count))

import tweepy
import json
import sqlite3
import re
from collections import defaultdict
from itertools import groupby
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
from textblob import TextBlob
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
import requests
from wordcloud import WordCloud
import os
import csv
import codecs
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
term = '@atsipras OR @kmitsotakis OR @FofiGennimata OR @akyrwnoume'
list_of_tweets = []
tweetString = ''
tweet_text = ''
list_of_tweets = tweepy.Cursor(api.search, q=term, lang='en').items(300)
with codecs.open('tweets_' + term + '.csv', 'w', 'utf8') as f:
    for tweet in list_of_tweets:
        hashtag_list = []
        for hashtag_entity in tweet.entities['hashtags']:
            hashtag_list.append('#' + hashtag_entity['text'])
        hashtags_str = '-'.join(x for x in hashtag_list)
        tweet_text = tweet.text.replace('\r', '')
        tweet_text = tweet_text.replace('\n', '')
        tweet_text = tweet_text.replace(',', '')
        tweet_text = tweet_text.replace('"', "'")
        tweet_text = re.sub('http\\S+', '', tweet_text)
        tweet_text = re.sub('RT @\\S+ ', '', tweet_text)
        tweet_text = re.sub('[-!@#$:).;,?&]', ' ', tweet_text)
        tweet_text = tweet_text.replace(' ', ' ')
        tweet_text = tweet_text.lower()
        f.write('%d, %s, %s, %s, @%s, "%s", %s, %s, %s, %s, %s \n' % (tweet
            .id, tweet.id_str, tweet.user.location, tweet.user.
            profile_background_color, tweet.retweet_count, tweet.user.
            screen_name, tweet.created_at, tweet.user.created_at,
            tweet_text, hashtags_str, tweet.favorite_count))

import tweepy
import json
import sqlite3
import re 
from collections import defaultdict
from itertools import groupby
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
from textblob import TextBlob
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
import requests
from wordcloud import WordCloud
import os
import csv
import codecs

#SearchAPI

# with open("twitter_credentials.json", "r") as file: 
# creds = json.load(file)


consumer_key = '' # put your own key and other values
consumer_secret = ''

access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)


# auth = tweepy.OAuthHandler(creds['CONSUMER_KEY'], creds['CONSUMER_SECRET'])
# auth.set_access_token(creds['ACCESS_TOKEN'], creds['ACCESS_SECRET'])


# Create the api to connect to twitter with your creadentials
api = tweepy.API(auth, wait_on_rate_limit=True)
term = '@atsipras OR @kmitsotakis OR @FofiGennimata OR @akyrwnoume'
# Get the full list of followers of a particular user
list_of_tweets=[]

tweetString = ''
tweet_text = ''
list_of_tweets = tweepy.Cursor(api.search, q=term, lang='en').items(300)

with codecs.open('tweets_'+term+'.csv', 'w', 'utf8')as f:
    for tweet in list_of_tweets:
        
        
        #get in a string the list of hashtags used by each tweet
        hashtag_list=[]
        for hashtag_entity in tweet.entities['hashtags']:
            
            hashtag_list.append('#'+hashtag_entity['text'])
        #save the hashtag list to a string
        hashtags_str = "-".join(x for x in hashtag_list)
        #remove line feed characters from tweet
        tweet_text = tweet.text.replace("\r", "")
        tweet_text = tweet_text.replace("\n", "")
        tweet_text = tweet_text.replace(",", "")
        tweet_text = tweet_text.replace("\"", "'")
        tweet_text = re.sub(r"http\S+", "", tweet_text)
        tweet_text = re.sub(r"RT @\S+ ", "", tweet_text)

        #remove special characters and lowercase
        tweet_text = re.sub('[-!@#$:).;,?&]', " ", tweet_text)
        tweet_text = tweet_text.replace(' ', ' ')
        tweet_text = tweet_text.lower()
        f.write("%d, %s, %s, %s, @%s, \"%s\", %s, %s, %s, %s, %s \n" % (tweet.id, tweet.id_str,tweet.user.location,
        tweet.user.profile_background_color,tweet.retweet_count, 
        tweet.user.screen_name,tweet.created_at,tweet.user.created_at,tweet_text, hashtags_str,tweet.favorite_count))


