-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.api.py
36 lines (25 loc) · 959 Bytes
/
twitter.api.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
32
33
34
35
import tweepy as tw
import os
import redis as rd
from dotenv import load_dotenv, find_dotenv
BASEDIR = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(BASEDIR, '.env'))
consumer_key = os.getenv("CONSUMER_KEY")
consumer_secret = os.getenv("CONSUMER_SECRET")
access_token = os.getenv("ACCESS_TOKEN")
access_token_secret = os.getenv("ACCESS_TOKEN_SECRET")
redis_db = rd.StrictRedis(host="localhost", port=6379, db=0)
auth = tw.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth)
search_words = "#felizsabado"
date_since = "2019-02-23"
public_tweets = api.home_timeline()
trending_topic = tw.Cursor(api.search,q=search_words, lang="es", since=date_since).items(5)
for tweet in trending_topic:
tw_new_key = tweet.user.id
tw_dict = {}
tw_dict[tweet.text] = tw_new_key
redis_db.zadd("tweets", tw_dict)
print tweet.user.id
#redis_db.set("app-twitter",tweet.text)