This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
twitter_media_tool/lib/authentication.py

67 lines
1.7 KiB
Python
Raw Normal View History

2020-04-24 14:38:39 -05:00
#!/usr/bin/python3
from tweepy import OAuthHandler, API
from webdav3.client import Client
from mastodon import Mastodon as masto
2020-04-24 14:38:39 -05:00
def authenticate_twitter(config):
"""
Authenticate with the Tweepy API and return client object
Arguments:
config {dict} -- Configuration dictionary object
Returns:
obj -- Tweepy API client object
"""
try:
auth = OAuthHandler(config['api_key'], config['api_key_secret'])
auth.set_access_token(config['access_token'],
config['access_token_secret'])
twitter_api = API(auth)
return twitter_api
except Exception as e:
print('There was some error attempting to authenticate with Twitter API')
print(f'\t{e}')
exit(1)
def authenticate_nextcloud(config):
"""
Authenticate Nextcloud with WebDAV and return client object
Arguments:
config {dict} -- Configuration dictionary object
Returns:
obj -- WebDAV client object
"""
try:
client = Client(config)
return client
except Exception as e:
print('There was some error attempting to authenticate through WebDAV')
print(f'\t{e}')
exit(1)
def authenticate_mastodon(config):
"""
Authenticate Mastodon API and return client object
Arguments:
config {dict} -- Configuration dictionary object
Returns:
obj -- Mastodon API client object
"""
try:
client = masto(access_token=config['access_token'],
api_base_url=config['api_base_url'])
return client
except Exception as e:
print('There was some error attempting to authenticate with Mastodon API')
print(f'\t{e}')
exit(1)