| name | price-api |
| description | Fetch construction material prices from open APIs. Track price trends, regional variations, and update cost databases. |
| homepage | https://datadrivenconstruction.io |
| metadata | {"openclaw":{"emoji":"🌐","os":["darwin","linux","win32"],"homepage":"https://datadrivenconstruction.io","requires":{"bins":["python3"]}}} |
Price API for Construction Materials
Overview
Material prices fluctuate constantly. This skill fetches prices from open sources, tracks trends, and updates cost databases with current market data.
Python Implementation
import requests
import pandas as pd
from typing import Dict, Any, List, Optional
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from enum import Enum
import json
class MaterialCategory():
CONCRETE =
STEEL =
LUMBER =
COPPER =
ALUMINUM =
CEMENT =
AGGREGATES =
ASPHALT =
:
material:
price:
unit:
currency:
source:
date: datetime
region: =
:
material:
current_price:
week_change:
month_change:
year_change:
trend_direction:
:
FRED_BASE =
FRED_SERIES = {
: ,
: ,
: ,
: ,
:
}
():
.fred_api_key = fred_api_key
() -> [MaterialPrice]:
material.lower() .FRED_SERIES:
[]
series_id = .FRED_SERIES[material.lower()]
start_date :
start_date = (datetime.now() - timedelta(days=)).strftime()
end_date :
end_date = datetime.now().strftime()
params = {
: series_id,
: start_date,
: end_date,
:
}
.fred_api_key:
params[] = .fred_api_key
:
response = requests.get(.FRED_BASE, params=params)
response.status_code != :
[]
data = response.json()
observations = data.get(, [])
prices = []
obs observations:
:
price = (obs[])
prices.append(MaterialPrice(
material=material,
price=price,
unit=,
currency=,
source=,
date=datetime.strptime(obs[], ),
region=
))
(ValueError, KeyError):
prices
Exception e:
()
[]
() -> pd.DataFrame:
data = [{
: p.material,
: p.price,
: p.unit,
: p.currency,
: p.source,
: p.date,
: p.region
} p prices]
pd.DataFrame(data)
:
REGIONAL_FACTORS = {
: ,
: ,
: ,
: ,
: ,
: ,
: ,
:
}
():
.price_cache: [, pd.DataFrame] = {}
() -> PriceTrend:
prices.empty prices.columns:
prices = prices.sort_values()
current = prices[].iloc[-]
week_ago_idx = (prices) - (prices) >=
month_ago_idx = (prices) - (prices) >=
year_ago_idx = (prices) - (prices) >=
week_price = prices[].iloc[week_ago_idx]
month_price = prices[].iloc[month_ago_idx]
year_price = prices[].iloc[year_ago_idx]
week_change = ((current - week_price) / week_price * ) week_price
month_change = ((current - month_price) / month_price * ) month_price
year_change = ((current - year_price) / year_price * ) year_price
month_change > :
trend =
month_change < -:
trend =
:
trend =
PriceTrend(
material=prices[].iloc[],
current_price=current,
week_change=(week_change, ),
month_change=(month_change, ),
year_change=(year_change, ),
trend_direction=trend
)
() -> :
factor = .REGIONAL_FACTORS.get(region, )
base_price * factor
() -> pd.DataFrame:
updated = cost_df.copy()
material, price price_updates.items():
mask = updated[]..lower() == material.lower()
mask.():
old_price = updated.loc[mask, ].mean()
factor = price / old_price old_price >
updated.loc[mask, ] *= factor
updated.loc[mask, date_column] = datetime.now()
updated
:
REFERENCE_PRICES = {
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
:
}
() -> :
base_price = .REFERENCE_PRICES.get(material, )
base_price == :
adjusted = base_price * ( + inflation_adjustment)
tracker = ConstructionPriceTracker()
tracker.apply_regional_factor(adjusted, region)
() -> pd.DataFrame:
estimates = []
material materials:
price = .estimate_price(material, region)
estimates.append({
: material,
: price,
: region,
: ,
: datetime.now()
})
pd.DataFrame(estimates)