<filename>src/services/twitter_service.py
from os import environ

import tweepy


consumer_key = environ.get("CUSTOMER_KEY")
consumer_secret = environ.get("CUSTOMER_SECRET")
access_token = environ.get("ACCESS_TOKEN")
access_token_secret = environ.get("ACCESS_TOKEN_SECRET")


class TwitterAPI:
    """
    """
    def __init__(self):
        """
        """
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        self.api = tweepy.API(auth)

    def retrieve_tweets(
            self,
            twitter_username: str,
            count: int = 200,
    ):
        """
        """
        self.tweets = self.api.user_timeline(
            screen_name=twitter_username,
            count=count,
            include_rts=False,
            tweet_mode="extended"
            )
        return self.serialize_tweets()

    def serialize_tweets(self):
        """
        """
        return {
            f"tweet_{count}": {
                "ID": tweet.id,
                "created_at": tweet.created_at,
                "full_text": tweet.full_text
                } for count, tweet in enumerate(self.tweets)
            }
<filename>src/services/twitter_service.py
from os import environ

import tweepy


consumer_key = environ.get("CUSTOMER_KEY")
consumer_secret = environ.get("CUSTOMER_SECRET")
access_token = environ.get("ACCESS_TOKEN")
access_token_secret = environ.get("ACCESS_TOKEN_SECRET")


class TwitterAPI:
    """
    """
    def __init__(self):
        """
        """
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        self.api = tweepy.API(auth)

    def retrieve_tweets(
            self,
            twitter_username: str,
            count: int = 200,
    ):
        """
        """
        self.tweets = self.api.user_timeline(
            screen_name=twitter_username,
            count=count,
            include_rts=False,
            tweet_mode="extended"
            )
        return self.serialize_tweets()

    def serialize_tweets(self):
        """
        """
        return {
            f"tweet_{count}": {
                "ID": tweet.id,
                "created_at": tweet.created_at,
                "full_text": tweet.full_text
                } for count, tweet in enumerate(self.tweets)
            }