From af203e4c2f742eb18fa132a86dc93bc352619ec3 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 3 Nov 2021 16:22:07 -0400 Subject: [PATCH] [+] Create separate twitter file --- collect/twitter.py | 21 +++++++++++++++++++++ collect/utils.py | 14 -------------- 2 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 collect/twitter.py diff --git a/collect/twitter.py b/collect/twitter.py new file mode 100644 index 0000000..39f39a0 --- /dev/null +++ b/collect/twitter.py @@ -0,0 +1,21 @@ +from dataclasses import dataclass +from datetime import datetime +from typing import Union + +import tweepy + +from collect.utils import Config +def tweepy_login(conf: Config) -> 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 + + + diff --git a/collect/utils.py b/collect/utils.py index bb98ed2..98143fa 100644 --- a/collect/utils.py +++ b/collect/utils.py @@ -28,7 +28,6 @@ class Config: telegram_userid: int - def load_config() -> Config: """ Load config using JSON5, from either the local file ~/config.json5 or from the environment variable named config. @@ -42,16 +41,3 @@ def load_config() -> Config: conf = json5.loads(os.getenv('config')) return Config(**conf) - - -def tweepy_login(conf: Config) -> 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