<commit_before>"""
Get authenticated tweepy API object
"""

import json
import os

import tweepy

localdir = os.path.dirname(os.path.abspath(__file__))


def _get_secret_stuffs():
    """ Retrieves Twitter API tokens & keys from stored secrets """
    secrets = ["CONSUMER_KEY",
               "CONSUMER_SECRET",
               "ACCESS_TOKEN",
               "ACCESS_SECRET"]
    with open(os.path.join(localdir, "token.json")) as f:
        t = json.load(f)
        return [t[s] for s in secrets]


def _get_api():
    """ Gets an authenticated tweepy API instance from stored JSON secrets """
    secrets = _get_secret_stuffs()<commit_msg>Use environment variables for authentication<commit_after>"""
Get authenticated tweepy API object
"""

import json
import os

import tweepy

localdir = os.path.dirname(os.path.abspath(__file__))

# On personal computers, .gitignored JSON files can be more convenient than
# environment variables. If the "token.json" file is present, we copy its
# values as environment variables
tokenpath = os.path.join(localdir, "token.json")
if os.path.exists(tokenpath):
    with open(tokenpath, "r") as f:
        data = json.load(f)
        os.environ.update(data)


def _get_secret_stuffs():
    """ Retrieves Twitter API tokens & keys from stored secrets """
    secrets = ["CONSUMER_KEY",
               "CONSUMER_SECRET",
               "ACCESS_TOKEN",
               "ACCESS_SECRET"]
    return [os.environ[s] for s in secrets]


def _get_api():
    """ Gets an authenticated tweepy API instance from stored JSON secrets """
    secrets = _get_secret_stuffs()
{'fraction_non_alphanumeric': 0.10658307210031348, 'fraction_numerical': 0.0, 'mean_word_length': 3.24468085106383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6593166', 'n_tokens_mistral': 499, 'n_tokens_neox': 490, 'n_words': 147}