csvsoundsystem / federal-treasury-api

The scraper, parser, and database creation scripts for Financial Management Service daily U.S. Treasury statements.
www.treasury.io/
106 stars 27 forks source link

Twitter bot #44

Closed tlevine closed 11 years ago

tlevine commented 11 years ago

We will deliver a "Twitter bot that will tweet daily new data notifications."

tlevine commented 11 years ago

@abelsonlive Does this work? https://github.com/csvsoundsystem/fms_parser/blob/master/twitter/tweetbot.py

If so, maybe

and then it's done

abelsonlive commented 11 years ago

Yes, the twitter bot does work, But it needs more tweet types!

Here's how to contribute tweets:

SELECT date, close_today FROM t3c WHERE (item LIKE \'%subject to limit%\' AND year = 2013 AND month >=1) ORDER BY date DESC
QUERIES = {'total_debt': 'SELECT date, close_today FROM t3c WHERE (item LIKE \'%subject to limit%\' AND year = 2013 AND month >=1) ORDER BY date DESC'}
def total_debt_tweet(df):
    # determine length of DataFrame
    end = len(df)-1

    # extract current amount and amount at the beginning of the year
    current_amt = df['close_today'][0]*MIL
    previous_amt = df['close_today'][end]*MIL

    # calculate change
    delta = abs(current_amt - previous_amt)

    # generate word to represnet the direction of change
    if current_amt > previous_amt:
        change = "increased"
    elif current_amt < previous_amt:
        change = "decreased"

    # humanize values
    # Notice the included `human_date` and `human_number` functions which simplify these values for you
    current_date = human_date(df['date'][0])
    amt = human_number(current_amt)
    delta = human_number(delta)
    previous_date = human_date(df['date'][end])

    # generate tweet
    vals = (current_date, amt, change, previous_date, URL)
    return "As of %s, the US Gov is $%s in debt. This amount has %s since %s - %s" % vals

def construct_tweet(options):
    t = options.tweet_type
    df = treasury_io(QUERIES[t])
    if t == 'total_debt':
        return total_debt_tweet(df)
python twitter/tweetbot.py -t total_debt
tlevine commented 11 years ago

It might be convenient to put this in the Python package along with the the importer code.

abelsonlive commented 11 years ago

I suppose so, I'm not sure how much we want to encourage other people to make their own tweet bots. What do others think?

tlevine commented 11 years ago

@abelsonlive, can you document how to get those tokens?

And if you have an api.yml for a test account, could you send it to me?

I think letting people make their own tweet bots is like letting people make their own graphs.

Check out csvsoundsystem/pytreasuryio@73dca84a3e43502e425e864b02715fd4fa9ffe06.

tlevine commented 11 years ago
tlevine commented 11 years ago

It wasn't quite working when I closed it, but now it seems to be. f29e95f1a764aa68addbb00bbed2928f20817bbf