-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9192ed
commit 6148609
Showing
2 changed files
with
16 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ requests==2.28.2 | |
requests-oauthlib==1.3.1 | ||
beautifulsoup4==4.11.1 | ||
python-dotenv==1.0.0 | ||
python-twitter-v2==0.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
import requests | ||
from requests_oauthlib import OAuth1 | ||
import json, os | ||
import pytwitter | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
def tweet(message): | ||
url = "https://api.twitter.com/2/tweets" | ||
|
||
payload = json.dumps({"text": message}) | ||
|
||
consumer_key = os.environ['TWITTER_CONSUMER_KEY'] | ||
consumer_secret = os.environ['TWITTER_CONSUMER_SECRET'] | ||
access_token = os.environ['TWITTER_ACCESS_TOKEN'] | ||
access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET'] | ||
|
||
oauth = OAuth1( | ||
consumer_key, | ||
consumer_secret, | ||
access_token, | ||
access_token_secret | ||
) | ||
|
||
headers = { | ||
'Content-Type': 'application/json', | ||
} | ||
|
||
response = requests.post(url, headers=headers, data=payload, auth=oauth) | ||
response.raise_for_status() | ||
|
||
return response | ||
consumer_key = os.environ['TWITTER_CONSUMER_KEY'] | ||
consumer_secret = os.environ['TWITTER_CONSUMER_SECRET'] | ||
access_token = os.environ['TWITTER_ACCESS_TOKEN'] | ||
access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET'] | ||
|
||
twitter_api = pytwitter.Api( | ||
consumer_key=consumer_key, | ||
consumer_secret=consumer_secret, | ||
access_token=access_token, | ||
access_secret=access_token_secret | ||
) | ||
|
||
return twitter_api.create_tweet(text=message) |