From db6c5328cac56d8a2b3dcbb201860fb3892ffa4c Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 3 Nov 2021 15:42:18 -0400 Subject: [PATCH] [+] Create function for tweepy login --- collect/twitter_individual.py | 2 ++ collect/utils.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/collect/twitter_individual.py b/collect/twitter_individual.py index 229e4c0..24dcf05 100644 --- a/collect/twitter_individual.py +++ b/collect/twitter_individual.py @@ -8,3 +8,5 @@ from collect.utils import * if __name__ == '__main__': conf = load_config() + + diff --git a/collect/utils.py b/collect/utils.py index 6dfdd55..d7b6049 100644 --- a/collect/utils.py +++ b/collect/utils.py @@ -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