ntdservices commited on
Commit
2fbf000
·
verified ·
1 Parent(s): b083297

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile.txt +6 -0
  2. app.py +32 -0
  3. requirements.txt +2 -0
  4. templates/index.html +62 -0
Dockerfile.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+ WORKDIR /code
3
+ COPY requirements.txt .
4
+ RUN pip install -r requirements.txt
5
+ COPY . .
6
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, jsonify
2
+ import requests
3
+
4
+ app = Flask(__name__)
5
+
6
+ API_URL = "https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny"
7
+
8
+ @app.route('/')
9
+ def index():
10
+ return render_template('index.html')
11
+
12
+ @app.route('/api/debt')
13
+ def get_debt_data():
14
+ try:
15
+ params = {
16
+ "fields": "record_date,tot_pub_debt_out_amt",
17
+ "sort": "-record_date",
18
+ "limit": 2
19
+ }
20
+ response = requests.get(API_URL, params=params)
21
+ data = response.json()["data"]
22
+
23
+ latest_debt = float(data[0]["tot_pub_debt_out_amt"])
24
+ previous_debt = float(data[1]["tot_pub_debt_out_amt"])
25
+ rate_per_second = (latest_debt - previous_debt) / 86400 # seconds in a day
26
+
27
+ return jsonify({
28
+ "startingDebt": latest_debt,
29
+ "ratePerSecond": rate_per_second
30
+ })
31
+ except Exception as e:
32
+ return jsonify({"error": str(e)}), 500
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask
2
+ requests
templates/index.html ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>US Debt Clock</title>
6
+ <style>
7
+ body {
8
+ background: #111;
9
+ color: #0f0;
10
+ font-family: monospace;
11
+ display: flex;
12
+ flex-direction: column;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ margin: 0;
17
+ }
18
+ h1 {
19
+ font-size: 2rem;
20
+ color: #aaa;
21
+ margin-bottom: 10px;
22
+ }
23
+ #debt {
24
+ font-size: 3rem;
25
+ white-space: nowrap;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <h1>U.S. National Debt (Real-Time Estimate)</h1>
31
+ <div id="debt">Loading...</div>
32
+
33
+ <script>
34
+ let startingDebt = 0;
35
+ let ratePerSecond = 0;
36
+ let startTime = Date.now();
37
+
38
+ fetch('/api/debt')
39
+ .then(res => res.json())
40
+ .then(data => {
41
+ startingDebt = data.startingDebt;
42
+ ratePerSecond = data.ratePerSecond;
43
+ startTime = Date.now();
44
+ updateDebtDisplay();
45
+ setInterval(updateDebtDisplay, 100);
46
+ })
47
+ .catch(err => {
48
+ document.getElementById('debt').textContent = 'Error loading data';
49
+ console.error(err);
50
+ });
51
+
52
+ function updateDebtDisplay() {
53
+ let elapsed = (Date.now() - startTime) / 1000;
54
+ let currentDebt = startingDebt + (ratePerSecond * elapsed);
55
+ document.getElementById('debt').textContent = '$' + currentDebt.toLocaleString(undefined, {
56
+ minimumFractionDigits: 2,
57
+ maximumFractionDigits: 2
58
+ });
59
+ }
60
+ </script>
61
+ </body>
62
+ </html>