コード例 #1
0
import tweepy
import time
import json
import pymongo

# API connection
auth = tweepy.OAuthHandler('consumer_key', 'consumer_secret')
auth.set_access_token('access_token', 'access_token_secret')
api = tweepy.API(auth)
api.retry_count = 5
api.retry_delay = 5
api.timeout = 5
api.wait_on_rate_limit = True
api.wait_on_rate_limit_notify = True

class MyStreamListener(tweepy.StreamListener):

    def __init__(self, time_limit = ):
        self.start_time = time.time()
        self.limit = time_limit
        # database connection for deletion of all records before the new stream starts(optional)
        client = pymongo.MongoClient('mongodb://localhost/twitterdb')
        db = client.twitterdb
        db.tweets.delete_many({})
        super(MyStreamListener, self).__init__()

    def on_data(self, data):
        try:
            # checks if the time interval passed
            if (time.time() - self.start_time) < self.limit:
                client = pymongo.MongoClient('mongodb://localhost/twitterdb')
コード例 #2
0
import tweepy
import time
import random
#you need to enter your own credentials :)
auth = tweepy.OAuthHandler('*******************', '*************')
auth.set_access_token('*************', '****************************')

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

user = api.me()

search = '#rgpv_spreading_corona_virus'
nrTweet = 500

for tweet in tweepy.Cursor(api.search, search).items(nrTweet):
    try:
        print('Tweet Retweeted')
        tweet.retweet()
        n = random.randint(1, 4)
        time.sleep(n)
    except tweepy.TweepError as e:
        print(e.reason)
    except StopIteration:
        break
コード例 #3
0
import tweepy
import time

auth = tweepy.OAuthHandler('HclONosamerxnuJ5S8U88AOmK',
                           'OBpETBSdaEFD9PvVhYRfpZh40YkuPobT6u37qmVZKm3xwyd4Ln')
auth.set_access_token('1257312720040292360-nlvj31Ro8J6Xd0R8XbCUW5oCnBKBtt',
                      'BhHOMdy6itb67B85N4rJOAHQDN2Mk7vk03x5dXq1FP2rs')

api = tweepy.API(auth)

public_tweets = api.home_timeline()

""" for tweet in public_tweets:
    print(tweet.text)
user = api.me()
print(user.followers_count)
print(user)
print(user.screen_name)
 """
def limit_handler(cursor):
    try:
        while True:
            yield cursor.next()
    except tweepy.RateLimitError:
        time.sleep(1000)

       
#generous bot 
""" for follower in limit_handler(tweepy.Cursor(api.followers).items()):
    if follower.name == 'ajax':
        follower.follow()
import tweepy
import sys
from textblob import TextBlob
import matplotlib.pyplot as plt
import re
import pandas as pd
import numpy as np

#defining the keys ---from twitter api
Consumer_Key = "qhfac9zsMmUCa8GkMLOYM21hg"
Consumer_Secret = "PNgSjpiu4rEHO2FkIri4mseCksGvxGFFbb0LluwrBUOhvtsGiI"
Access_token = "472099927-B03YMYZ8R88OTnQGIxvEN45mfrg2rNaUJNzP222K"
Access_token_Secret = "oE8fAROsHENZzCNfozla6z6t6elgllhU0eeRBBLi2Iovq"

#creating the authentication
auth = tweepy.OAuthHandler(consumer_key=Consumer_Key,
                           consumer_secret=Consumer_Secret)
auth.set_access_token(Access_token, Access_token_Secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
#asking user to enter the keyword and number of tweets to be analysed.
search_word = input("Enter the Keyword/hashtag to be searched:")
num_of_tweets = int(input("Enter the Number of tweets to be analysed:"))

#tweets = api.user_timeline(search_word,num_of_tweets,language = "english")
#tweets = tweepy.Cursor(api.search , q=search_word , language ="English").items()num_of_tweets

tweets = tweepy.Cursor(api.search, q=search_word,
                       language="English").items(num_of_tweets)
for tweet in tweets:
    analysis = TextBlob(tweet.text)
    polarity = analysis.sentiment.polarity  #At line
    #Creating the Data Frame of Tweets
コード例 #5
0
ファイル: WojBot.py プロジェクト: jks3/reddit-bots
def statusFollower():
    while (True):
        try:
            myStream = tweepy.Stream(auth=api.auth, listener=myStreamListener, tweet_mode="extended")
            myStream.filter(follow=["50323173"])
        except:
            continue

reddit = praw.Reddit(client_id='OcnQUoR3Kamkhw',
                     client_secret='yEfb-X4NP4VdX-BQiZsD-8-A2jI',
                     user_agent='MaranHaGoanHaRav',
                     refresh_token = "56880923-ftskICk1yOn8wa-5W2iQei-mZrU")

print(reddit.user.me())

auth = tweepy.OAuthHandler("33nl5R0LUYyeUmIzyGKBRerET",
                           "WPF5NJIjPya0E4d3IX57bdo4zAb26Xt1AggsGhT1rvyfI5kbbA")
auth.set_access_token("615513817-VSgvKwpnMSmKEldVIcX4wWwkpsMsq6R41Nwuaaje",
                      "jbFnTbSMSt6ZYOVgoDd0nRcEd9nQc3k1ARcqMf29gXtQS")

api = tweepy.API(auth)

print(api.user_timeline(id = "wojespn", tweet_mode = "extended")[2].full_text)

print(type(api.user_timeline(id = "wojespn", tweet_mode = "extended")[2]))

myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener, tweet_mode = "extended")

statusFollower()
コード例 #6
0
def start():
    auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
    auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)
    api = tweepy.API(auth)
    stream = listen(api)
    stream._thread.join()
コード例 #7
0
 def setUp(self):
     auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
     auth.set_access_token(access_token, access_token_secret)
     self.client = tweepy.API(auth)
     self.dirname = os.path.dirname(__file__)
コード例 #8
0
 def DownloadData(self):
     consumerKey = '-----------------------------------------------------'
     consumerSecret = '--------------------------------------------------'
     accessToken = '-----------------------------------------------------'
     accessTokenSecret = '-----------------------------------------------'
     
     auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
     auth.set_access_token(accessToken, accessTokenSecret)
     api = tweepy.API(auth)
     auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
     auth.set_access_token(accessToken, accessTokenSecret)
     api = tweepy.API(auth)
     searchTerm = e1.get()
     NoOfTerms = int(e2.get())
     self.tweets = tweepy.Cursor(api.search, q=searchTerm, lang = "en").items(NoOfTerms)
     polarity = 0
     positive = 0
     stronglypositive = 0
     negative = 0
     stronglynegative = 0
     neutral = 0
     csvFile = open('results_neutral.csv', 'w')
     csvFile1 = open('results_pos.csv','w')
     csvFile2 = open('results_neg.csv','w')
     csvWriter = csv.writer(csvFile)
     csvWriter1 = csv.writer(csvFile1)
     csvWriter2 = csv.writer(csvFile2)
     for tweet in self.tweets:
         self.tweetText.append(self.cleanTweet(tweet.text).encode('utf-8'))
         analysis = TextBlob(tweet.text)
         polarity += analysis.sentiment.polarity  
         if (analysis.sentiment.polarity == 0):  
             neutral += 1
             csvWriter.writerow(self.tweetText)
         elif (analysis.sentiment.polarity > 0.0 and analysis.sentiment.polarity <= 0.6):
             positive += 1
             csvWriter1.writerow(self.tweetText)
         elif (analysis.sentiment.polarity > 0.6 and analysis.sentiment.polarity <= 1):
             stronglypositive += 1
             csvWriter1.writerow(self.tweetText)
         elif (analysis.sentiment.polarity > -0.6 and analysis.sentiment.polarity <= 0.00):
             negative += 1
             csvWriter2.writerow(self.tweetText)
         elif (analysis.sentiment.polarity > -1 and analysis.sentiment.polarity <= -0.6):
             stronglynegative += 1
             csvWriter2.writerow(self.tweetText)
             
     csvFile.close()
     csvFile1.close()
     csvFile2.close()
     csvFile = open('results123.csv', 'w')
     csvWriter = csv.writer(csvFile)
     for tweet in self.tweets:
         self.tweetText.append(self.cleanTweet(tweet.text).encode('utf-8'))
         analysis = TextBlob(tweet.text)
         polarity += analysis.sentiment.polarity  
         if (analysis.sentiment.polarity == 0):  
             neutral += 1
         elif (analysis.sentiment.polarity > 0.0 and analysis.sentiment.polarity <= 0.6):
             positive += 1
         elif (analysis.sentiment.polarity > 0.6 and analysis.sentiment.polarity <= 1):
             stronglypositive += 1
         elif (analysis.sentiment.polarity > -0.6 and analysis.sentiment.polarity <= 0.00):
             negative += 1
         elif (analysis.sentiment.polarity > -1 and analysis.sentiment.polarity <= -0.6):
             stronglynegative += 1
     csvWriter.writerow(self.tweetText)
     csvFile.close()
     positive = self.percentage(positive, NoOfTerms)
     stronglypositive = self.percentage(stronglypositive, NoOfTerms)
     negative = self.percentage(negative, NoOfTerms)
     stronglynegative = self.percentage(stronglynegative, NoOfTerms)
     neutral = self.percentage(neutral, NoOfTerms)
     polarity = polarity / NoOfTerms
     global res
     if (polarity == 0):
         res = "Neutral"
     elif (polarity > 0 and polarity <= 0.6):
         res = "Positive"
     elif (polarity > 0.6 and polarity <= 1):
         res = "Strongly Positive"
     elif (polarity > -0.6 and polarity <= 0):
         res = "Negative"
     elif (polarity > -1 and polarity <= -0.6):
         res = "Strongly Negative"
         
     self.plotPieChart(positive, stronglypositive, negative, stronglynegative, neutral, searchTerm, NoOfTerms)
     root = Tk()  
     root.title('general report')
     label = Label(root,text = "general result")
     label.grid(row = 0,column = 0)
     label1 = Label(root, text = res)
     label1.grid(row = 0,column = 3)
     label2 = Label(root,text = "percentages : ")
     label2.grid(row = 1,column= 2)
     label3 = Label(root,text = "extremely positive : ")
     label3.grid(row = 2, column = 0)
     label4 = Label(root,text = stronglypositive )
     label4.grid(row = 2, column = 3)
     label5 = Label(root,text = "positive : ")
     label5.grid(row = 3, column = 0)
     label6 = Label(root,text = positive)
     label6.grid(row = 3, column = 3)
     label7 = Label(root,text = "neutral : ")
     label7.grid(row = 4, column = 0)
     label8 = Label(root,text = neutral)
     label8.grid(row = 4, column = 3)
     label9 = Label(root,text = "negative : ")
     label9.grid(row = 5, column = 0)
     label10 = Label(root,text = negative)
     label10.grid(row = 5, column = 3)
     label11 = Label(root,text = "extremely negative : ")
     label11.grid(row = 6,column = 0)
     label12 = Label(root,text = stronglynegative)
     label12.grid(row = 6, column = 3)
     button = Button(root,text = "close",command = root.destroy)
     button.grid(row = 9,column = 1)
     button1 = Button(root,text = "neutral",command = sa.showneutral)
     button1.grid(row = 7,column =0)
     button2 = Button(root,text = "positive",command = sa.showpositive)
     button2.grid(row = 7, column= 1)
     button3 = Button(root,text = "negative",command = sa.shownegative)
     button3.grid(row = 7,column = 2)
     button4 = Button(root,text = "show piechart",command = sa.showchart)
     button4.grid(row=9,column = 0)
コード例 #9
0
    else:
        return True


class MyStreamListener(tweepy.StreamListener):
    def on_status(self, status):

        print(status)
        print(status.id)
        exit(1)


# Authenticate to Twitter
# api_keys = pd.read_csv('D:\\Repositories\\Trump-tweets-classifier\\keys.csv')
api_keys = pd.read_csv('keys.csv')
auth = tweepy.OAuthHandler(api_keys['api_key'].values[0],
                           api_keys['api_key_secret'].values[0])
auth.set_access_token(api_keys['access_token'].values[0],
                      api_keys['access_token_secret'].values[0])

# Create API object
api = tweepy.API(auth)

# Twitter ids
realDonaldTrump = "25073877"
realDonaldTrFan = "19570960"
RealDonalDrumpf = "1407822289"

# Start twitter stream
print('Starting stream listener at %s' %
      str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
myStreamListener = MyStreamListener()
コード例 #10
0
import os

import tweepy
from dotenv import load_dotenv
from flask import Flask, jsonify
from flask_cors import CORS

auth = tweepy.OAuthHandler(os.getenv("API_KEY"), os.getenv("API_SECRET"))
auth.set_access_token(os.getenv("TOKEN"), os.getenv("TOKEN_SECRET"))

API = tweepy.API(auth, parser=tweepy.parsers.JSONParser())

app = Flask(__name__)
CORS(app)


# http://docs.tweepy.org/en/latest/api.html#API.search_users
@app.route('/api/1.0/profiles/<string:query>/<int:per_page>/<int:page>',
           methods=['GET'])
def get_profiles(query='Test', per_page=20, page=1):
    try:
        profiles = API.search_users(query, per_page, page)
        return jsonify(profiles)
    except tweepy.TweepError:
        print('Ouch! I have to capture this')


# http://docs.tweepy.org/en/latest/api.html#API.create_block
@app.route('/api/1.0/profiles/block/<int:user_id>', methods=['POST'])
def block_user(user_id='Test'):
    try:
コード例 #11
0
import os
from twitter_credentials import twit_auth as credentials
import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
import json

auth = tweepy.OAuthHandler(credentials["consumer_key"],
                           credentials["consumer_secret"])
auth.set_access_token(credentials["access_token"],
                      credentials["access_token_secret"])

api = tweepy.API(auth)


class retweet_user_name_streamer(StreamListener):
    """
    Extension on Tweepy twitter streamer that stores retweet
    information about users and their connections to one another
    """
    def __init__(self, tweets_per_file=500, sep=";,."):
        """
        Twitter streamer that finds retweets and stores the username of both
        the retweeter and the original tweeter in a CSV file. Handles file
        management so the data is split across multiple CSV files.

        tweets_per_file: how many tweets to analyze and store per CSV
        sep: separator for CSV data, defaults to characters unlikely to be
        together in a twitter username
        """
        super().__init__()
コード例 #12
0
import tweepy
import time

auth = tweepy.OAuthHandler('I', '')

auth.set_access_token('', '')

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

user = api.me()

search = 'hello'
nrTweets = 10

for tweet in tweepy.Cursor(api.search, search).items(nrTweets):
    try:
        print('Liked tweet')
        tweet.favorite()
        time.sleep(10)
    except tweepy.TweepError as e:
        print(e.reason)
    except StopIteration:
        break
コード例 #13
0
ファイル: nixiko.py プロジェクト: kil9/nixikloud
 def get_twitter_auth(self):
     auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
     auth.set_access_token(TWITTER_ACCESS_KEY, TWITTER_ACCESS_SECRET)
     api = tweepy.API(auth, retry_count=3, retry_delay=5, wait_on_rate_limit=True)
     return api
コード例 #14
0
ファイル: crawler.py プロジェクト: lucycangarova/webler
 def create_API(self):
     # OAuth process, using the keys and tokens
     auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret)
     auth.set_access_token(self.access_token, self.access_secret)
     # create rest API
     self.api = tweepy.API(auth)
コード例 #15
0
def authorize_twitter():
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
    return auth
コード例 #16
0
load_dotenv()
APP_KEY = os.environ['API_KEY']
APP_SECRET = os.environ['API_SECRET_KEY']
ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET']

# change user-agent (just a precaution)
opener = urllib.request.build_opener()
opener.addheaders = [(
    'User-Agent',
    'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36'
)]
urllib.request.install_opener(opener)

# API connection
auth = tweepy.OAuthHandler(APP_KEY, APP_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)


def get_followers_count(screen_name):
    user = api.get_user(screen_name=screen_name, include_entities=False)
    followers_count = user.followers_count
    print('fetched followers count')
    return followers_count


def calculate_progress(followers, progress_mark):
    percentage = ((followers % progress_mark) / progress_mark) * 100
    angle = (360 * percentage) / 100
    print('completed calculations')
コード例 #17
0
import random
import tweepy, time

auth = tweepy.OAuthHandler("", "")
auth.set_access_token("", "")
api = tweepy.API(auth)
print(".")
print(".")
print("Welcome to my trivia/quiz thing!")
print("The User chooses their category of")
print("quiz from a list of three. The")
print("computer will keep track of score.")
print(".")
name = input("What is your name?")
score = 0
quiz = ""
done = False
if name.upper() == "CARL":
    print("No chumps allowed")
    done = True
else:
    print(".")
    print("1.Animals")
    print("2.Sports")
    print("3.Random")
    print("4.Quit")
    print("Pick 1,2,3, or 4")
    print(".")
    category = int(input("What category would you like to quiz?"))
while done == False:
    if category == 4:
コード例 #18
0
ファイル: bot.py プロジェクト: give-me-15-min/Twitter-Bot
import tweepy
import pprint
from datetime import datetime, timedelta
import key

# Twitterに接続&認証
auth = tweepy.OAuthHandler(key.consumer_key, key.consumer_secret)
auth.set_access_token(key.access_token_key, key.access_token_secret)
api = tweepy.API(auth)

query = ["to:akakou_py"]

# 検索
for status in api.search(q=query, lang='ja', result_type='recent'):
    print("-*-*-*-*-")
    print(f"name: {status.user.screen_name}\n")    # ユーザ名を表示
    print(f"text: {status.text}\n")         # ツイートの内容を表示
    
    tweet_day = status.created_at + timedelta(hours=9)
    
    today = datetime.today()
    a_hour_ago = today - timedelta(hours=1)
    print(f"time: {tweet_day}\n") # 時間を表示
    
    if tweet_day < a_hour_ago:
        print("message: pass")
        print("-*-*-*-*-\n\n")
        continue

    id = status._json['id']
    print(f"id: {id}\n")
コード例 #19
0
        return True


if(os.environ.get('CONSUMER_KEY')):
        CONSUMER_KEY=os.environ.get('CONSUMER_KEY')
else:
        print "Set CONSUMER_KEY as one of your environmental variables"

if(os.environ.get('CONSUMER_SECRET')):
        CONSUMER_SECRET=os.environ.get('CONSUMER_SECRET')
else:
        print "Set CONSUMER_SECRET as one of your environmental variables"


if(os.environ.get('ACCESS_TOKEN')):
        ACCESS_TOKEN=os.environ.get('ACCESS_TOKEN')
else:
        print "Set ACCESS_TOKEN as one of your environmental variables"

if(os.environ.get('ACCESS_TOKEN_SECRET')):
        ACCESS_TOKEN_SECRET=os.environ.get('ACCESS_TOKEN_SECRET')
else:
        print "Set ACCESS_TOKEN_SECRET as one of your environmental variables"

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)

twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(track=['happy','awesome','sweet','excited','haha','funny','cool','good','hilarious','lit','giddy','fantastic','cure','radiance','treatment','safe','wellbeing','upbeat','success','cheer','dear','impressive','recover','wonder','marry','bright','win','victory','champion','positive','better','enjoy',':D',':)','glad','ecstatic','delighted','joy','lively','blessed','merry','peppy','perky','gay','jolly','chipper','bliss','sad','cry','lost','death','hurt','pain','mess','miss','upset','cancer','disease','illness','failed','spasm','loss','grieve','sorry','weep','broke','mourn','divorce','tear','negative','dead',':(','bitter','despair','heartbroken','blue','gloomy','low','morbid','somber','reject','deject','trouble','alone','down','drepess','unhappy','stress','sorrow','pessimistic','weary','disappoint','distraught','angry','hate','frustrat','mad','piss','stupid','bad','evil','smh','jealous','failure','retard','bitch','wreck','resist','dumb','liar','lie','liar','toxic','scowl','brutal','sugarcoat','break','steal','wrong','screw','>:(','heated','furious','irritated','offend','outrage','resent','displease','fuming','raging','rage','provoke','wrath','infuriat','sulk','irate','uptight','antagonize','temper','love','kiss','hug','content','beautiful','cute','hot','gorgeous','fab','luv','humble','flower','rose','pink','best','xoxo','boyfriend','girlfriend','husband','wife','delicious','handsome','<3','affection','appreciate','devote','lust','respect','tender','carring','emotion','friendship','caring','passion','enchant','worship','praise','cherish','fond','ador','amore','infatuat','bae','fear','scar','blood','monster','afraid','terrif','earthquake','fire','terror','nervous','epdiemic','panic','phobia','histerical','paranoia','unease','danger','wicked','dread','crash','burn','torture','demon','invade','bomb','suffer','disaster','distress','numb','histeria','ominous','war','nuke'])
コード例 #20
0
import tweepy
import pandas as pd
from textblob import TextBlob
import re

from db_tech import storage, extracting_tweets
from config import Credentials, Settings
from data_analysis import clean_transform_data, plot_results, pnl_module, geo_distr_data


#Authentication
auth  = tweepy.OAuthHandler(Credentials.API_KEY, \
                            Credentials.API_SECRET_KEY)
auth.set_access_token(Credentials.ACCESS_TOKEN,  \
                      Credentials.ACCESS_TOKEN_SECRET)

#CREATE THE API OBJECT
api = tweepy.API(auth)

#CREATE DATABASE TABLES
#FIRST EXECUTE DB.PY

class MyStreamListener(tweepy.StreamListener):

    def on_status(self, status):
        
        # if status.retweeted:
        # # Avoid retweeted info, and only original tweets will 
        # # be received
        #     return True
コード例 #21
0
        # Send the request to Twitter
        api.destroy_status(tweet_id)
        # Wait for a random number of seconds
        time.sleep(random.randint(1, 5))


if __name__ == "__main__":

    with open('secretConfig.json') as json_file:
        data = json.load(json_file)
        my_consumer_key = data["twitter"]["CONSUMER_KEY"]
        my_consumer_secret = data["twitter"]["CONSUMER_SECRET"]
        my_access_token = data["twitter"]["ACCESS_TOKEN"]
        my_access_toke_secret = data["twitter"]["ACCESS_TOKEN_SECRET"]

    auth = tweepy.OAuthHandler(my_consumer_key, my_consumer_secret)
    auth.set_access_token(my_access_token, my_access_toke_secret)
    api = tweepy.API(auth)

    tweets = api.user_timeline(
        screen_name="beekeep86576354",
        # 200 is the maximum allowed count
        count=200,
        include_rts=False,
        # Necessary to keep full_text
        # otherwise only the first 140 words are extracted
        tweet_mode='extended')

    tweets_to_delete = []
    for info in tweets:
        if info.id <= 1391326707618037763:
コード例 #22
0
import tweepy
import requests
import sys
import random
import MyAPI
import traceback
import re
import pathlib

auth = tweepy.OAuthHandler(MyAPI.consumer_key_send, MyAPI.consumer_secret_send)
auth.set_access_token(MyAPI.access_token_send, MyAPI.access_secret_send)
api = tweepy.API(auth)

# def serch_level(text, LV_start, LV_end):
#     for i in range(int(LV_start * 10), int(LV_end * 10) + 1):
#         if (str(i / 10) in text):
#             return str(i / 10)
#         elif str(i / 10) in text:
#             return str(int(i / 10))
#     for i in range(int(LV_start), int(LV_end) + 1):
#         if ((str(i) + "+" in text) or (str(i) + "+" in text)) and (i != 14):
#             return (str(i) + "+")
#         elif str(i) in text:
#             return str(i)
#     return "ALL"


def find_level(tweet):
    unable_to_choice = [
        '10.1', '10.2', '10.4', '14.2', '14.3', '14.4', '14.5', '14.6', '14.7',
        '14.8', '14.9'
コード例 #23
0
ファイル: twitter.py プロジェクト: invegat/twitoff
"""Retrieve TWeets, embeddings, and persist in the database."""
import basilica
import tweepy
from decouple import config
from .models import DB, Tweet, User

TWITTER_AUTH = tweepy.OAuthHandler(config('TWITTER_CONSUMER_KEY'),
                                   config('TWITTER_CONSUMER_SECRET'))
TWITTER_AUTH.set_access_token(config('TWITTER_ACCESS_TOKEN'),
                              config('TWITTER_ACCESS_TOKEN_SECRET'))
TWITTER = tweepy.API(TWITTER_AUTH)

BASILICA = basilica.Connection(config('BASILICA_KEY'))


def add_twitter_user(name):
    try:
        twitter_user = TWITTER.get_user(name)
    except TweepError:
        return (f"user '{name}' not found", None)
    db_user = User.query.get(twitter_user.id)
    if db_user:
        return (f"user name '{name}' id {u[0]} is already in the database",
                None)
    tweets = twitter_user.timeline(count=200,
                                   exclude_replies=True,
                                   include_rts=False,
                                   tweet_mode='extended')
    db_user = User(id=twitter_user.id,
                   name=twitter_user.screen_name,
                   newest_tweet_id=(tweets[0].id if len(tweets) > 0 else None))
コード例 #24
0
except ImportError as _:
    import ConfigParser as configparser

import datetime
import tweepy

Config = configparser.ConfigParser()
Config
Config.read("settings.txt")

cKey = Config['auth']['consumer_key']
cSecret = Config['auth']['consumer_secret']
aKey = Config['auth']['token_key']
aSecret = Config['auth']['token_secret']

auth = tweepy.OAuthHandler(consumerKey, consumerSecret)

consumerKey = cKey
consumerSecret = cSecret
accessToken = aKey
accessTokenSecret = aSecret

auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth)

#tweet post test
tweet = str(datetime.datetime.now()) + " test post :)"
api.update_status(status=tweet)

print("Success")
print()
コード例 #25
0
ファイル: WojBot.py プロジェクト: jks3/reddit-bots
class MyStreamListener(tweepy.StreamListener):
    auth1 = tweepy.OAuthHandler("33nl5R0LUYyeUmIzyGKBRerET",
                               "WPF5NJIjPya0E4d3IX57bdo4zAb26Xt1AggsGhT1rvyfI5kbbA")
    auth1.set_access_token("615513817-VSgvKwpnMSmKEldVIcX4wWwkpsMsq6R41Nwuaaje",
                          "jbFnTbSMSt6ZYOVgoDd0nRcEd9nQc3k1ARcqMf29gXtQS")

    #api1 = tweepy.API(auth1)
    def on_status(self, status, api1=tweepy.API(auth1)):
        self.stream = Stream(auth=api1.auth, listener=self, tweet_mode='extended')

        fulltweet = ""

        try:
            fulltweet = status.extended_tweet['full_text']
        except:
            fulltweet = status.text



        if ((fulltweet.lower().find("@") == -1  or (fulltweet.lower().find("reporting with") >= 0
                                                    and fulltweet.lower().find("rt @") == -1
                                                    and fulltweet.lower().find("@wojespn") == -1))
                and len(fulltweet) >= 5 and fulltweet.lower().find("http") == -1):

            #try:
                #reddit.subreddit("nba").submit(
                 #   title="[Wojnarowski] "
                  #        + fulltweet
                   #       [0:fulltweet.lower().find("htt")],
                   # url="https://twitter.com/wojespn/status/"
                    #    + str(status.id), send_replies=False)
            #except:
             #   print(colored("nba", "blue"))
               # traceback.print_exc()

            print(colored(fulltweet, "green"))

            subreddit = set()

            subreddit.add("nba")

            # endIndex = getEndIndex(fulltweet, 0)

            for key in nameToSubreddit:
                if ((" " + key.lower() + " ") or (key.lower() + "' ") or (" " + key.lower() + "' ")) in fulltweet.lower():
                    subreddit.add(nameToSubreddit[key])

            for sub in subreddit:
                try:
                    reddit.subreddit(sub).submit(
                        title= "[Wojnarowski] "
                       + fulltweet,
                url="https://twitter.com/wojespn/status/"
                                                   + str(status.id), send_replies = False)
                except:
                    print(colored(sub, "blue"))
                    traceback.print_exc()
                    continue
        else:
            print(colored("Caught retweet! The text was: "
                  +  fulltweet, "red"))
コード例 #26
0
ファイル: main.py プロジェクト: chrisngyn/twitter-cli
import typer
import tweepy
from typing import List

creds = open("./auth.txt", "r")
twitter_credentials = creds.read().splitlines()

API_KEY = twitter_credentials[0]
API_SECRET_KEY = twitter_credentials[1]
ACCESS_TOKEN = twitter_credentials[2]
ACCESS_TOKEN_SECRET = twitter_credentials[3]

auth = tweepy.OAuthHandler(API_KEY, API_SECRET_KEY)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)


def main(tweet: List[str]):
    ret = ' '.join(tweet)
    typer.echo(ret)
    api.update_status(ret)


if __name__ == '__main__':
    typer.run(main)
コード例 #27
0
import tweepy
import json
import pandas
import credentials

consumer_key = credentials.consumer_key
consumer_secret = credentials.consumer_secret
access_token = credentials.access_token
access_token_secret = credentials.access_token_secret

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

api = tweepy.API(auth)

count_dict = {}

for i in range(1, 32):

    item = api.user_timeline(screen_name='@realdonaldtrump', count=100, page=i)
    for j in range(0, len(item)):
        created_at_raw = json.dumps(item[j]._json['created_at'])
        created_at_split = created_at_raw.split(" ")
        created_at_date = created_at_split[1] + "/" + created_at_split[2]

        if created_at_date in count_dict:
            count_dict[created_at_date] += 1
        else:
            count_dict[created_at_date] = 1

for key, value in count_dict.items():
コード例 #28
0
 def __init__(self):
     auth = tweepy.OAuthHandler(settings.consumer_key,
                                settings.consumer_secret)
     auth.set_access_token(settings.access_token,
                           settings.access_token_secret)
     self.api = tweepy.API(auth)
コード例 #29
0
ファイル: twitter.py プロジェクト: zunerabokhari/DS25-twitoff
"""Getting tweets and users from the Twitter DB"""
from os import getenv
import tweepy
import spacy
from .models import User, DB, Tweet

TWITTER_AUTH = tweepy.OAuthHandler(getenv("TWITTER_API_KEY"),
                                   getenv("TWITTER_API_KEY_SECRET"))
TWITTER = tweepy.API(TWITTER_AUTH)

# loads word2vect Model
nlp = spacy.load("my_model")


def vectorize_tweet(tweet_text):
    return nlp(tweet_text).vector


def add_or_update_user(username):
    """
    Gets twitter user and tweets from twitter DB
    Gets user by "username" parameter.
    """
    try:
        # gets back twitter user object
        twitter_user = TWITTER.get_user(username)
        # Either updates or adds user to our DB
        db_user = (User.query.get(twitter_user.id)) or User(id=twitter_user.id,
                                                            name=username)
        DB.session.add(db_user)  # Add user if don't exist
コード例 #30
0
ファイル: twitter.py プロジェクト: rassamyjs/Twitoff_DS20
"""Retrieve tweets and users then create embeddings and populate DB"""
from os import getenv
import tweepy
import spacy
from .models import DB, Tweet, User

TWITTER_API_KEY = getenv("TWITTER_API_KEY")
TWITTER_API_KEY_SECRET = getenv("TWITTER_API_KEY_SECRET")
TWITTER_AUTH = tweepy.OAuthHandler(TWITTER_API_KEY, TWITTER_API_KEY_SECRET)
TWITTER = tweepy.API(TWITTER_AUTH)

# nlp model
nlp = spacy.load('my_model')


def vectorize_tweet(tweet_text):
    return nlp(tweet_text).vector


def add_or_update_user(username):
    try:
        # grabs user from twitter DB
        twitter_user = TWITTER.get_user(username)
        # adds or updates user
        db_user = (User.query.get(twitter_user.id)) or User(
            id=twitter_user.id, name=username)
        DB.session.add(db_user)

        # grabs tweets from twitter_user
        tweets = twitter_user.timeline(
            count=200, exclude_replies=True, include_rts=False,