[+] Create separate twitter file

This commit is contained in:
Hykilpikonna
2021-11-03 16:22:07 -04:00
parent 1af5182f91
commit af203e4c2f
2 changed files with 21 additions and 14 deletions
+21
View File
@@ -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
-14
View File
@@ -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