Skip to content

Commit

Permalink
Fix authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
oraclown committed Oct 12, 2022
1 parent 82fd3a5 commit 3ca9966
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
certifi==2022.9.24
charset-normalizer==2.1.1
idna==3.4
oauthlib==3.2.1
python-dotenv==0.21.0
requests==2.28.1
requests-oauthlib==1.3.1
tweepy==4.10.1
urllib3==1.26.12
28 changes: 21 additions & 7 deletions scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,37 @@
import tweepy
import time
import os
from dotenv import load_dotenv
import sys

auth = tweepy.OAuth1UserHandler(
consumer_key = os.getenv('TWITTER_CONSUMER_KEY'),
consumer_secret = os.getenv('TWITTER_CONSUMER_SECRET'),
access_token = os.getenv('TWITTER_ACCESS_TOKEN'),
access_token_secret = os.getenv('TWITTER_ACCESS_TOKEN_SECRET')
load_dotenv()

auth = tweepy.OAuthHandler(
consumer_key = os.getenv('TWITTER_API_KEY'),
consumer_secret = os.getenv('TWITTER_API_SECRET'),
)
auth.set_access_token(
os.getenv('TWITTER_ACCESS_TOKEN'),
os.getenv('TWITTER_ACCESS_TOKEN_SECRET')
)

api = tweepy.API(auth)

try:
api.verify_credentials()
print("Authentication OK")
except Exception as e:
print(f"Error during authentication: {e}")
sys.exit(1)

faucet_user = api.get_user('trbfaucet')

yesterday_timestamp = int(time.time()) - 86400
# get mentions since yesterday
mentions = api.mentions_timeline(since_id=yesterday_timestamp)
mentions = faucet_user.mentions_timeline(since_id=yesterday_timestamp)

# filter out invalid mentions
valid_mentions = []
for mention in mentions:
pass
print("Mention from @{}: {}".format(mention.user.screen_name, mention.text))
print("__________________")

0 comments on commit 3ca9966

Please sign in to comment.