2020-04-24 14:38:39 -05:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2020-04-25 03:19:32 -05:00
|
|
|
from tweepy import OAuthHandler, API
|
2020-04-25 15:52:51 -05:00
|
|
|
from webdav3.client import Client
|
2020-04-29 11:59:01 -05:00
|
|
|
from mastodon import Mastodon as masto
|
2020-04-25 03:19:32 -05:00
|
|
|
|
2020-04-24 14:38:39 -05:00
|
|
|
|
|
|
|
def authenticate_twitter(config):
|
2020-04-29 13:36:47 -05:00
|
|
|
"""
|
|
|
|
Authenticate with the Tweepy API and return client object
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
config {dict} -- Configuration dictionary object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
obj -- Tweepy API client object
|
|
|
|
"""
|
2020-04-25 15:52:51 -05:00
|
|
|
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):
|
2020-04-29 13:36:47 -05:00
|
|
|
"""
|
|
|
|
Authenticate Nextcloud with WebDAV and return client object
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
config {dict} -- Configuration dictionary object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
obj -- WebDAV client object
|
|
|
|
"""
|
2020-04-25 15:52:51 -05:00
|
|
|
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)
|
2020-04-29 11:59:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
def authenticate_mastodon(config):
|
2020-04-29 13:36:47 -05:00
|
|
|
"""
|
|
|
|
Authenticate Mastodon API and return client object
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
config {dict} -- Configuration dictionary object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
obj -- Mastodon API client object
|
|
|
|
"""
|
2020-04-29 11:59:01 -05:00
|
|
|
try:
|
2020-04-29 13:16:35 -05:00
|
|
|
client = masto(access_token=config['access_token'],
|
|
|
|
api_base_url=config['api_base_url'])
|
2020-04-29 11:59:01 -05:00
|
|
|
return client
|
|
|
|
except Exception as e:
|
|
|
|
print('There was some error attempting to authenticate with Mastodon API')
|
|
|
|
print(f'\t{e}')
|
|
|
|
exit(1)
|