-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from pavobravo11/revert-2-main-manuel
Revert "Finalize tweepy stuff"
- Loading branch information
Showing
5 changed files
with
32 additions
and
46 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,42 @@ | ||
import os | ||
|
||
import tweepy | ||
import configparser | ||
import os | ||
|
||
#def publish_tweet(): | ||
dirname = os.path.dirname(__file__) | ||
|
||
consumer_key = os.environ["CONSUMER_KEY"] | ||
consumer_secret = os.environ["CONSUMER_SECRET"] | ||
access_token = os.environ["ACCESS_TOKEN"] | ||
access_token_secret = os.environ["ACCESS_TOKEN_SECRET"] | ||
|
||
auth = tweepy.OAuth1UserHandler( | ||
consumer_key=consumer_key, consumer_secret=consumer_secret, | ||
access_token=access_token, | ||
access_token_secret=access_token_secret | ||
) | ||
|
||
# open config file | ||
config_init_filename = os.path.join(dirname, 'config.ini') | ||
config_parser = configparser.ConfigParser() | ||
config_parser.readfp(open(config_init_filename)) | ||
# read tweeter credentials | ||
consumer_key = config_parser['tweeter']['consumer_key'] | ||
consumer_secret = config_parser['tweeter']['consumer_secret'] | ||
access_token = config_parser['tweeter']['access_token'] | ||
access_token_secret = config_parser['tweeter']['access_token_secret'] | ||
bearer_token = config_parser['tweeter']['bearer_token'] | ||
|
||
# authorization of consumer key and consumer secret | ||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | ||
|
||
# set access to user's access key and access secret | ||
auth.set_access_token(access_token, access_token_secret) | ||
|
||
# calling the api | ||
api = tweepy.API(auth) | ||
client = tweepy.Client(consumer_key=consumer_key, consumer_secret=consumer_secret, | ||
access_token=access_token, | ||
access_token_secret=access_token_secret) | ||
|
||
client = tweepy.Client(bearer_token=bearer_token, | ||
access_token=access_token, | ||
access_token_secret=access_token_secret, | ||
consumer_key=consumer_key, | ||
consumer_secret=consumer_secret) | ||
|
||
# the name of the media file | ||
graph_filename = os.path.join(dirname, "input/aiqmap.png") | ||
|
||
graph_filename = os.path.join(dirname, 'newplot.png') | ||
# upload the file | ||
media = api.media_upload(graph_filename) | ||
|
||
# printing the information | ||
print("The media ID is : " + media.media_id_string) | ||
print("The size of the file is : " + str(media.size) + " bytes") | ||
client.create_tweet(media_ids=[media.media_id_string]) | ||
client.create_tweet(media_ids= [media.media_id_string]) |