Last active
August 7, 2026 05:08
-
-
Save donpdonp/420d6603c276bbe577c79a5331ccfe60 to your computer and use it in GitHub Desktop.
gluon usdebt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| setup() | |
| return { | |
| name: "usdebt" | |
| } | |
| }) | |
| var us_debt = {} | |
| function setup() { | |
| us_debt = fetch_debt() | |
| bot.say(bot.admin_channel, "usdebt: " + debt_to_str(us_debt)) | |
| } | |
| function go(msg) { | |
| if(msg.method == "irc.privmsg") { | |
| var cmd = /^\!usdebt(\s+(.+))?$/ | |
| var match = cmd.exec(msg.params.message) | |
| if(match){ | |
| report(msg.params, match[2]) | |
| } | |
| } | |
| if(msg.method == "clocktower" && (new Date(msg.params.time)).getMinutes() == 0) { | |
| us_debt = fetch_debt() | |
| } | |
| } | |
| function report(params) { | |
| bot.say(params.channel, "US Debt "+debt_to_str(us_debt)) | |
| } | |
| function debt_to_str(debts) { | |
| // "record_date": "2026-08-04", | |
| // "debt_held_public_amt": "32100703256953.12", | |
| // "intragov_hold_amt": "7727732133938.43", | |
| // "tot_pub_debt_out_amt": "39828435390891.55", | |
| var debt_day_difference = parseInt(debts.total[0]["tot_pub_debt_out_amt"]) - parseInt(debts.total[1]["tot_pub_debt_out_amt"]) | |
| var year_additional = debt_day_difference * 365 | |
| var next_year_est = parseInt(debts.total[0]["tot_pub_debt_out_amt"]) + year_additional | |
| return debt_total(debts.total[0]) + " 24hr_chg: $" + commify(""+debt_day_difference) + | |
| " " + debts.interest["avg_interest_rate_amt"]+"%APR"// + " next year est: "+ next_year_est | |
| } | |
| function debt_total(total) { | |
| var debt_str = total["tot_pub_debt_out_amt"] | |
| return total["record_date"]+": $"+commify(debt_str) | |
| } | |
| function commify(debt_str) { | |
| var debt_str_int = debt_str.split(".")[0] | |
| var debt_amt_str = debt_str_int.split("").reverse().join("").match(/.{1,3}/g).join(',').split("").reverse().join("") | |
| return debt_amt_str | |
| } | |
| function fetch_debt() { | |
| var url = "https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny" + | |
| "?sort=-record_date&format=json&page[size]=2" | |
| var debt = {} | |
| var doc = http.get({url: url}) | |
| var json = doc.body | |
| var data = JSON.parse(json)["data"] | |
| debt.total = data | |
| var url = "https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/avg_interest_rates"+ | |
| "?sort=-record_date&format=json&page[size]=20" | |
| // filter=security_desc:eq:Total Marketable, page[size]=1 | |
| var doc = http.get({url: url}) | |
| var json = doc.body | |
| var data = JSON.parse(json) | |
| for(var idx=0; idx < data["data"].length; idx++) { | |
| if (data["data"][idx]["security_desc"] == "Total Marketable") { | |
| debt.interest = data["data"][idx] | |
| break | |
| } | |
| } | |
| //debt.interest = data["data"][0] | |
| return debt | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment