ratpmetro/main.py
def load(
        self, line, number_of_tweets=3200, folder_tweets="tweets", force_download=False
    ):
        """
        Download the tweets from the official RATP Twitter account.

        Some code is adapted from https://github.com/gitlaura/get_tweets

        Args:
            line (int or str): RATP metro line number (1 to 14), or ``"A"``, ``"B"`` for RER lines
            number_of_tweets (int): Number of tweets to download, must be smaller than 3200 due to some limitation of the Twitter API
            folder_tweets (str): Folder to store the downloaded tweets as a ``.csv`` file
            force_download (bool): If ``False``, it will directly load the already downloaded file without re-downloading it. You can force downloading by using ``force_download = True``
        """
        import os

        username = self._twitter_account(line)
        outfile = os.path.join(folder_tweets, username + ".csv")
        if not os.path.isfile(outfile) or force_download:
            os.makedirs(os.path.dirname(outfile), exist_ok=True)
            import csv
            import tweepy

            auth = tweepy.OAuthHandler(
                self.api["consumer_key"], self.api["consumer_secret"]
            )
            auth.set_access_token(self.api["access_key"], self.api["access_secret"])
            api = tweepy.API(auth, wait_on_rate_limit=True)

            tweets_for_csv = [["time", "tweet"]]
            print(f"Downloading tweets for {username}")
            for tweet in tweepy.Cursor(api.user_timeline, screen_name=username).items(
                number_of_tweets
            ):
                tweets_for_csv.append([tweet.created_at, tweet.text])

            with open(outfile, "w", newline="") as f:
                writer = csv.writer(f, delimiter=",")
                writer.writerows(tweets_for_csv)

        self.df = pd.read_csv(outfile)
        self.line = line
        self.color = self._color_line(line)

        Download the tweets from the official RATP Twitter account.

        Some code is adapted from https://github.com/gitlaura/get_tweets

        Args:
            line (int or str): RATP metro line number (1 to 14), or ``"A"``, ``"B"`` for RER lines
            number_of_tweets (int): Number of tweets to download, must be smaller than 3200 due to some limitation of the Twitter API
            folder_tweets (str): Folder to store the downloaded tweets as a ``.csv`` file
            force_download (bool): If ``False``, it will directly load the already downloaded file without re-downloading it. You can force downloading by using ``force_download = True``
        
Download the tweets from the official RATP Twitter account.
Download the tweets from the official RATP Twitter account .
def load(
        self, line, number_of_tweets=3200, folder_tweets="tweets", force_download=False
    ):
        import os
        username = self._twitter_account(line)
        outfile = os.path.join(folder_tweets, username + ".csv")
        if not os.path.isfile(outfile) or force_download:
            os.makedirs(os.path.dirname(outfile), exist_ok=True)
            import csv
            import tweepy
            auth = tweepy.OAuthHandler(
                self.api["consumer_key"], self.api["consumer_secret"]
            )
            auth.set_access_token(self.api["access_key"], self.api["access_secret"])
            api = tweepy.API(auth, wait_on_rate_limit=True)
            tweets_for_csv = [["time", "tweet"]]
            print(f"Downloading tweets for {username}")
            for tweet in tweepy.Cursor(api.user_timeline, screen_name=username).items(
                number_of_tweets
            ):
                tweets_for_csv.append([tweet.created_at, tweet.text])
            with open(outfile, "w", newline="") as f:
                writer = csv.writer(f, delimiter=",")
                writer.writerows(tweets_for_csv)
        self.df = pd.read_csv(outfile)
        self.line = line
        self.color = self._color_line(line)
def load ( self , line , number_of_tweets = 3200 , folder_tweets = "tweets" , force_download = False ) : import os username = self . _twitter_account ( line ) outfile = os . path . join ( folder_tweets , username + ".csv" ) if not os . path . isfile ( outfile ) or force_download : os . makedirs ( os . path . dirname ( outfile ) , exist_ok = True ) import csv import tweepy auth = tweepy . OAuthHandler ( self . api [ "consumer_key" ] , self . api [ "consumer_secret" ] ) auth . set_access_token ( self . api [ "access_key" ] , self . api [ "access_secret" ] ) api = tweepy . API ( auth , wait_on_rate_limit = True ) tweets_for_csv = [ [ "time" , "tweet" ] ] print ( f"Downloading tweets for {username}" ) for tweet in tweepy . Cursor ( api . user_timeline , screen_name = username ) . items ( number_of_tweets ) : tweets_for_csv . append ( [ tweet . created_at , tweet . text ] ) with open ( outfile , "w" , newline = "" ) as f : writer = csv . writer ( f , delimiter = "," ) writer . writerows ( tweets_for_csv ) self . df = pd . read_csv ( outfile ) self . line = line self . color = self . _color_line ( line )
Download the tweets from the official RATP Twitter account.
Download the tweets from the official RATP Twitter account .
"""
        Download the tweets from the official RATP Twitter account.

        Some code is adapted from https://github.com/gitlaura/get_tweets

        Args:
            line (int or str): RATP metro line number (1 to 14), or ``"A"``, ``"B"`` for RER lines
            number_of_tweets (int): Number of tweets to download, must be smaller than 3200 due to some limitation of the Twitter API
            folder_tweets (str): Folder to store the downloaded tweets as a ``.csv`` file
            force_download (bool): If ``False``, it will directly load the already downloaded file without re-downloading it. You can force downloading by using ``force_download = True``
        """
self
line
RATP metro line number (1 to 14), or ``"A"``, ``"B"`` for RER lines
RATP metro line number ( 1 to 14 ) or ` ` " A " ` ` ` ` " B " ` ` for RER lines
number_of_tweets
Number of tweets to download, must be smaller than 3200 due to some limitation of the Twitter API
Number of tweets to download must be smaller than 3200 due to some limitation of the Twitter API
folder_tweets
Folder to store the downloaded tweets as a ``.csv`` file
Folder to store the downloaded tweets as a ` ` . csv ` ` file
force_download
If ``False``, it will directly load the already downloaded file without re-downloading it. You can force downloading by using ``force_download = True``
If ` ` False ` ` it will directly load the already downloaded file without re - downloading it . You can force downloading by using ` ` force_download = True ` `