PolicyEngine / blank-slate-ubi-in-the-us

blank-slate-ubi-in-the-us
1 stars 3 forks source link

Get results for each reform #5

Closed MaxGhenis closed 3 months ago

MaxGhenis commented 3 months ago

For posterity here's some old code I had in this that I didn't commit:

import requests
import time
import csv

def get_json_from_id(id):
    res = requests.get(f"https://api.policyengine.org/us/economy/{id}/over/2?time_period=2024&region=enhanced_us").json()

    while res["status"] == "computing":
        time.sleep(5)
        res = requests.get(f"https://api.policyengine.org/us/economy/{id}/over/2?time_period=2024&region=enhanced_us").json()

    return res["result"]

# Get reforms from loss_by_rate.csv
reform_ids = []

with open('loss_by_rate.csv', 'r') as file:
    reader = csv.reader(file)
    next(reader)  # Skip header row
    for row in reader:
        reform_ids.append(row[0])

print(reform_ids)

reforms = []

json_data = {}

for reform in reforms:
    json_data[reform] = get_json_from_id(reform)

get_json_from_id(42848)