mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 08:50:39 +00:00
Add refresh_data script and startup script for offline data setup
- Introduced `scripts/refresh_data.py` to download UNRATE and WTI data from FRED and store it in a SQLite database. - Added `startup.sh` script to set up a Python virtual environment and install dependencies for offline use. - Updated `repo-context.txt` to reflect the new scripts and their purposes.
This commit is contained in:
1 parent
175e9ba4e2
commit
71e3bf4ab9
24 files changed
+238
-51
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
refresh_data.py
|
||||
---------------
|
||||
Download UNRATE and DCOILWTICO from FRED and store them in SQLite
|
||||
(data/fred.db). Run on a connected machine; commit the DB afterwards.
|
||||
"""
|
||||
|
||||
from datetime import date
|
||||
import pathlib
|
||||
import sqlite3
|
||||
|
||||
import pandas as pd
|
||||
from pandas_datareader.data import DataReader
|
||||
|
||||
HERE = pathlib.Path(__file__).resolve().parent
|
||||
DATA_PATH = HERE.parent / "data"
|
||||
DB_FILE = DATA_PATH / "fred.db"
|
||||
|
||||
START = "1948-01-01" # earliest UNRATE observation
|
||||
END = date.today().isoformat()
|
||||
SERIES = ("UNRATE", "DCOILWTICO")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
DATA_PATH.mkdir(exist_ok=True)
|
||||
with sqlite3.connect(DB_FILE) as conn:
|
||||
for s in SERIES:
|
||||
print(f"↯ downloading {s} …")
|
||||
df = DataReader(s, "fred", START, END)
|
||||
df.to_sql(s, conn, if_exists="replace", index_label="date")
|
||||
print(f"✓ wrote {s}: {len(df):,} rows")
|
||||
print(f"\nDone. SQLite DB at {DB_FILE} ({DB_FILE.stat().st_size/1024:.0f} KB)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user