[+] Create function for tweepy login

This commit is contained in:
Hykilpikonna
2021-11-03 15:42:18 -04:00
parent 102cad055e
commit db6c5328ca
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -8,3 +8,5 @@ from collect.utils import *
if __name__ == '__main__':
conf = load_config()
+14
View File
@@ -1,6 +1,7 @@
import os
import json5
import tweepy
def load_config() -> dict:
@@ -14,3 +15,16 @@ def load_config() -> dict:
return json5.load(f)
else:
return json5.loads(os.getenv('config'))
def tweepy_login(conf: dict) -> tweepy.API:
"""
Login to tweepy
:param conf: Config from load_config()
:return: Tweepy API object
"""
auth = tweepy.OAuthHandler(conf['consumer_key'], conf['consumer_secret'])
auth.set_access_token(conf['access_token'], conf['access_secret'])
api: tweepy.API = tweepy.API(auth)
return api