<commit_before>import os

import pandas as pd
import twitter

ACCESS_TOKEN_KEY = os.environ['TWITTER_ACCESS_TOKEN_KEY']
ACCESS_TOKEN_SECRET = os.environ['TWITTER_ACCESS_TOKEN_SECRET']
CONSUMER_KEY = os.environ['TWITTER_CONSUMER_KEY']
CONSUMER_SECRET = os.environ['TWITTER_CONSUMER_SECRET']
API = twitter.Api(consumer_key=CONSUMER_KEY,
                  consumer_secret=CONSUMER_SECRET,
                  access_token_key=ACCESS_TOKEN_KEY,
                  access_token_secret=ACCESS_TOKEN_SECRET)

ACCOUNTS = pd.read_csv('data/twitter_accounts.csv')


def follow_congresspeople():
    handlers = pd.concat([ACCOUNTS['twitter_handle'],
                          ACCOUNTS['secondary_twitter_handle']])
    for handler in handlers[handlers.notnull()].values:
        try:
            API.CreateFriendship(screen_name=handler)
        except Exception as e:
            print('{} handle not found'.format(handler))


def handle_for_reimbursement(reimbursement):
    name = reimbursement['congressperson_name']
    query = 'congressperson == "{}"'.format(name)
    return ACCOUNTS.query(query)['twitter_handle'].values[0]


def post_reimbursement(reimbursement):
    handle = handle_for_reimbursement(reimbursement)
    if handle:
        link = 'https://jarbas.serenatadeamor.org/#/documentId/{}'.format(
            reimbursement['document_id'])
        message = (
            '🚨Gasto suspeito de Dep. @{}. '
            'Você pode me ajudar a verificar? '
            '{} #SerenataDeAmor'
        ).format(handle, link)
    else:
        raise ValueError('Congressperson does not have a registered Twitter account.')


def post(text):
    """Post an update to Twitter's timeline."""
    return API.PostUpdate(text)<commit_msg>Add state name to Twitter message<commit_after>import os

import pandas as pd
import twitter

ACCESS_TOKEN_KEY = os.environ['TWITTER_ACCESS_TOKEN_KEY']
ACCESS_TOKEN_SECRET = os.environ['TWITTER_ACCESS_TOKEN_SECRET']
CONSUMER_KEY = os.environ['TWITTER_CONSUMER_KEY']
CONSUMER_SECRET = os.environ['TWITTER_CONSUMER_SECRET']
API = twitter.Api(consumer_key=CONSUMER_KEY,
                  consumer_secret=CONSUMER_SECRET,
                  access_token_key=ACCESS_TOKEN_KEY,
                  access_token_secret=ACCESS_TOKEN_SECRET)

ACCOUNTS = pd.read_csv('data/twitter_accounts.csv')


def follow_congresspeople():
    handlers = pd.concat([ACCOUNTS['twitter_handle'],
                          ACCOUNTS['secondary_twitter_handle']])
    for handler in handlers[handlers.notnull()].values:
        try:
            API.CreateFriendship(screen_name=handler)
        except Exception as e:
            print('{} handle not found'.format(handler))


def handle_for_reimbursement(reimbursement):
    name = reimbursement['congressperson_name']
    query = 'congressperson == "{}"'.format(name)
    return ACCOUNTS.query(query)['twitter_handle'].values[0]


def post_reimbursement(reimbursement):
    handle = handle_for_reimbursement(reimbursement)
    if handle:
        link = 'https://jarbas.serenatadeamor.org/#/documentId/{}'.format(
            reimbursement['document_id'])
        message = (
            '🚨Gasto suspeito de Dep. @{} ({}). '
            'Você pode me ajudar a verificar? '
            '{} #SerenataDeAmor'
        ).format(handle, reimbursement['state_x'], link)
        post(message)
    else:
        raise ValueError('Congressperson does not have a registered Twitter account.')


def post(text):
    """Post an update to Twitter's timeline."""
    return API.PostUpdate(text)
{'fraction_non_alphanumeric': 0.10921985815602837, 'fraction_numerical': 0.0005673758865248227, 'mean_word_length': 3.4019975031210987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '188837', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1118, 'n_words': 194}