Initial commit in new repo with new history.

This commit is contained in:
calcu1on 2025-04-02 20:39:30 -04:00
commit 8e1ae39164
7 changed files with 2731 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1728
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "pulse"
version = "0.1.0"
edition = "2024"
[dependencies]
reqwest = { version = "0.12.15", features = ["blocking"] }
serde = {version = "1.0.219", features = ["derive"]}
serde_alias = "0.0.2"
serde_json = "1.0.140"
tabled = "0.18.0"

792
assets/sox-schedule.json Normal file
View File

@ -0,0 +1,792 @@
[
{
"date": "2025-03-31",
"start_time": "2025-03-31 18:35:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-04-02",
"start_time": "2025-04-02 22:35:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-04-03",
"start_time": "2025-04-03 17:05:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-04-04",
"start_time": "2025-04-04 18:10:00",
"opponent": "St. Louis Cardinals"
},
{
"date": "2025-04-05",
"start_time": "2025-04-05 20:10:00",
"opponent": "St. Louis Cardinals"
},
{
"date": "2025-04-06",
"start_time": "2025-04-06 23:10:00",
"opponent": "St. Louis Cardinals"
},
{
"date": "2025-04-07",
"start_time": "2025-04-07 22:45:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-04-08",
"start_time": "2025-04-08 22:45:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-04-09",
"start_time": "2025-04-09 22:45:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-04-10",
"start_time": "2025-04-10 20:10:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-04-11",
"start_time": "2025-04-11 23:40:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-12",
"start_time": "2025-04-12 20:10:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-13",
"start_time": "2025-04-13 18:10:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-14",
"start_time": "2025-04-14 23:05:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-04-15",
"start_time": "2025-04-15 23:05:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-04-16",
"start_time": "2025-04-16 23:05:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-04-18",
"start_time": "2025-04-18 23:10:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-19",
"start_time": "2025-04-19 20:10:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-20",
"start_time": "2025-04-20 17:35:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-21",
"start_time": "2025-04-21 15:10:00",
"opponent": "Chicago White Sox"
},
{
"date": "2025-04-22",
"start_time": "2025-04-22 22:45:00",
"opponent": "Seattle Mariners"
},
{
"date": "2025-04-23",
"start_time": "2025-04-23 22:45:00",
"opponent": "Seattle Mariners"
},
{
"date": "2025-04-24",
"start_time": "2025-04-24 17:35:00",
"opponent": "Seattle Mariners"
},
{
"date": "2025-04-25",
"start_time": "2025-04-25 23:10:00",
"opponent": "Cleveland Guardians"
},
{
"date": "2025-04-26",
"start_time": "2025-04-26 22:10:00",
"opponent": "Cleveland Guardians"
},
{
"date": "2025-04-27",
"start_time": "2025-04-27 17:40:00",
"opponent": "Cleveland Guardians"
},
{
"date": "2025-04-29",
"start_time": "2025-04-29 23:07:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-04-30",
"start_time": "2025-04-30 23:07:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-05-01",
"start_time": "2025-05-01 23:07:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-05-02",
"start_time": "2025-05-02 23:10:00",
"opponent": "Minnesota Twins"
},
{
"date": "2025-05-03",
"start_time": "2025-05-03 20:10:00",
"opponent": "Minnesota Twins"
},
{
"date": "2025-05-04",
"start_time": "2025-05-04 17:35:00",
"opponent": "Minnesota Twins"
},
{
"date": "2025-05-06",
"start_time": "2025-05-06 22:45:00",
"opponent": "Texas Rangers"
},
{
"date": "2025-05-07",
"start_time": "2025-05-07 22:45:00",
"opponent": "Texas Rangers"
},
{
"date": "2025-05-08",
"start_time": "2025-05-08 17:35:00",
"opponent": "Texas Rangers"
},
{
"date": "2025-05-09",
"start_time": "2025-05-09 23:40:00",
"opponent": "Kansas City Royals"
},
{
"date": "2025-05-10",
"start_time": "2025-05-10 23:10:00",
"opponent": "Kansas City Royals"
},
{
"date": "2025-05-11",
"start_time": "2025-05-11 18:10:00",
"opponent": "Kansas City Royals"
},
{
"date": "2025-05-12",
"start_time": "2025-05-12 22:40:00",
"opponent": "Detroit Tigers"
},
{
"date": "2025-05-13",
"start_time": "2025-05-13 22:40:00",
"opponent": "Detroit Tigers"
},
{
"date": "2025-05-14",
"start_time": "2025-05-14 22:40:00",
"opponent": "Detroit Tigers"
},
{
"date": "2025-05-16",
"start_time": "2025-05-16 23:10:00",
"opponent": "Atlanta Braves"
},
{
"date": "2025-05-17",
"start_time": "2025-05-17 23:15:00",
"opponent": "Atlanta Braves"
},
{
"date": "2025-05-18",
"start_time": "2025-05-18 17:35:00",
"opponent": "Atlanta Braves"
},
{
"date": "2025-05-19",
"start_time": "2025-05-19 22:45:00",
"opponent": "New York Mets"
},
{
"date": "2025-05-20",
"start_time": "2025-05-20 22:45:00",
"opponent": "New York Mets"
},
{
"date": "2025-05-21",
"start_time": "2025-05-21 22:45:00",
"opponent": "New York Mets"
},
{
"date": "2025-05-22",
"start_time": "2025-05-22 22:45:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-05-23",
"start_time": "2025-05-23 23:10:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-05-24",
"start_time": "2025-05-24 20:10:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-05-25",
"start_time": "2025-05-25 17:35:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-05-26",
"start_time": "2025-05-26 18:10:00",
"opponent": "Milwaukee Brewers"
},
{
"date": "2025-05-27",
"start_time": "2025-05-27 23:40:00",
"opponent": "Milwaukee Brewers"
},
{
"date": "2025-05-28",
"start_time": "2025-05-28 17:10:00",
"opponent": "Milwaukee Brewers"
},
{
"date": "2025-05-30",
"start_time": "2025-05-30 23:15:00",
"opponent": "Atlanta Braves"
},
{
"date": "2025-05-31",
"start_time": "2025-05-31 20:10:00",
"opponent": "Atlanta Braves"
},
{
"date": "2025-06-01",
"start_time": "2025-06-01 17:35:00",
"opponent": "Atlanta Braves"
},
{
"date": "2025-06-02",
"start_time": "2025-06-02 23:10:00",
"opponent": "Los Angeles Angels"
},
{
"date": "2025-06-03",
"start_time": "2025-06-03 23:10:00",
"opponent": "Los Angeles Angels"
},
{
"date": "2025-06-04",
"start_time": "2025-06-04 17:35:00",
"opponent": "Los Angeles Angels"
},
{
"date": "2025-06-06",
"start_time": "2025-06-06 23:05:00",
"opponent": "New York Yankees"
},
{
"date": "2025-06-07",
"start_time": "2025-06-07 23:35:00",
"opponent": "New York Yankees"
},
{
"date": "2025-06-08",
"start_time": "2025-06-08 17:35:00",
"opponent": "New York Yankees"
},
{
"date": "2025-06-09",
"start_time": "2025-06-09 23:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-06-10",
"start_time": "2025-06-10 23:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-06-11",
"start_time": "2025-06-11 23:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-06-13",
"start_time": "2025-06-13 23:10:00",
"opponent": "New York Yankees"
},
{
"date": "2025-06-14",
"start_time": "2025-06-14 23:15:00",
"opponent": "New York Yankees"
},
{
"date": "2025-06-15",
"start_time": "2025-06-15 17:35:00",
"opponent": "New York Yankees"
},
{
"date": "2025-06-16",
"start_time": "2025-06-17 01:40:00",
"opponent": "Seattle Mariners"
},
{
"date": "2025-06-17",
"start_time": "2025-06-18 01:40:00",
"opponent": "Seattle Mariners"
},
{
"date": "2025-06-18",
"start_time": "2025-06-18 20:10:00",
"opponent": "Seattle Mariners"
},
{
"date": "2025-06-20",
"start_time": "2025-06-21 02:15:00",
"opponent": "San Francisco Giants"
},
{
"date": "2025-06-21",
"start_time": "2025-06-21 20:05:00",
"opponent": "San Francisco Giants"
},
{
"date": "2025-06-22",
"start_time": "2025-06-22 20:05:00",
"opponent": "San Francisco Giants"
},
{
"date": "2025-06-23",
"start_time": "2025-06-24 01:38:00",
"opponent": "Los Angeles Angels"
},
{
"date": "2025-06-24",
"start_time": "2025-06-25 01:38:00",
"opponent": "Los Angeles Angels"
},
{
"date": "2025-06-25",
"start_time": "2025-06-25 20:07:00",
"opponent": "Los Angeles Angels"
},
{
"date": "2025-06-27",
"start_time": "2025-06-27 23:10:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-06-28",
"start_time": "2025-06-28 20:10:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-06-29",
"start_time": "2025-06-29 17:35:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-06-30",
"start_time": "2025-06-30 23:10:00",
"opponent": "Cincinnati Reds"
},
{
"date": "2025-07-01",
"start_time": "2025-07-01 23:10:00",
"opponent": "Cincinnati Reds"
},
{
"date": "2025-07-02",
"start_time": "2025-07-02 23:10:00",
"opponent": "Cincinnati Reds"
},
{
"date": "2025-07-04",
"start_time": "2025-07-04 15:05:00",
"opponent": "Washington Nationals"
},
{
"date": "2025-07-05",
"start_time": "2025-07-05 20:05:00",
"opponent": "Washington Nationals"
},
{
"date": "2025-07-06",
"start_time": "2025-07-06 17:35:00",
"opponent": "Washington Nationals"
},
{
"date": "2025-07-07",
"start_time": "2025-07-07 23:10:00",
"opponent": "Colorado Rockies"
},
{
"date": "2025-07-08",
"start_time": "2025-07-08 23:10:00",
"opponent": "Colorado Rockies"
},
{
"date": "2025-07-09",
"start_time": "2025-07-09 23:10:00",
"opponent": "Colorado Rockies"
},
{
"date": "2025-07-10",
"start_time": "2025-07-10 23:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-07-11",
"start_time": "2025-07-11 23:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-07-12",
"start_time": "2025-07-12 20:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-07-13",
"start_time": "2025-07-13 17:35:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-07-18",
"start_time": "2025-07-18 18:20:00",
"opponent": "Chicago Cubs"
},
{
"date": "2025-07-19",
"start_time": "2025-07-19 23:15:00",
"opponent": "Chicago Cubs"
},
{
"date": "2025-07-20",
"start_time": "2025-07-20 18:20:00",
"opponent": "Chicago Cubs"
},
{
"date": "2025-07-21",
"start_time": "2025-07-21 22:45:00",
"opponent": "Philadelphia Phillies"
},
{
"date": "2025-07-22",
"start_time": "2025-07-22 22:45:00",
"opponent": "Philadelphia Phillies"
},
{
"date": "2025-07-23",
"start_time": "2025-07-23 23:05:00",
"opponent": "Philadelphia Phillies"
},
{
"date": "2025-07-25",
"start_time": "2025-07-25 23:10:00",
"opponent": "Los Angeles Dodgers"
},
{
"date": "2025-07-26",
"start_time": "2025-07-26 23:15:00",
"opponent": "Los Angeles Dodgers"
},
{
"date": "2025-07-27",
"start_time": "2025-07-27 17:35:00",
"opponent": "Los Angeles Dodgers"
},
{
"date": "2025-07-28",
"start_time": "2025-07-28 23:40:00",
"opponent": "Minnesota Twins"
},
{
"date": "2025-07-29",
"start_time": "2025-07-29 23:40:00",
"opponent": "Minnesota Twins"
},
{
"date": "2025-07-30",
"start_time": "2025-07-30 17:10:00",
"opponent": "Minnesota Twins"
},
{
"date": "2025-08-01",
"start_time": "2025-08-01 23:10:00",
"opponent": "Houston Astros"
},
{
"date": "2025-08-02",
"start_time": "2025-08-02 20:10:00",
"opponent": "Houston Astros"
},
{
"date": "2025-08-03",
"start_time": "2025-08-03 15:35:00",
"opponent": "Houston Astros"
},
{
"date": "2025-08-04",
"start_time": "2025-08-04 23:10:00",
"opponent": "Kansas City Royals"
},
{
"date": "2025-08-05",
"start_time": "2025-08-05 23:10:00",
"opponent": "Kansas City Royals"
},
{
"date": "2025-08-06",
"start_time": "2025-08-06 23:10:00",
"opponent": "Kansas City Royals"
},
{
"date": "2025-08-08",
"start_time": "2025-08-09 01:40:00",
"opponent": "San Diego Padres"
},
{
"date": "2025-08-09",
"start_time": "2025-08-10 00:40:00",
"opponent": "San Diego Padres"
},
{
"date": "2025-08-10",
"start_time": "2025-08-10 20:10:00",
"opponent": "San Diego Padres"
},
{
"date": "2025-08-11",
"start_time": "2025-08-12 00:10:00",
"opponent": "Houston Astros"
},
{
"date": "2025-08-12",
"start_time": "2025-08-13 00:10:00",
"opponent": "Houston Astros"
},
{
"date": "2025-08-13",
"start_time": "2025-08-13 23:10:00",
"opponent": "Houston Astros"
},
{
"date": "2025-08-15",
"start_time": "2025-08-15 23:10:00",
"opponent": "Miami Marlins"
},
{
"date": "2025-08-16",
"start_time": "2025-08-16 20:10:00",
"opponent": "Miami Marlins"
},
{
"date": "2025-08-17",
"start_time": "2025-08-17 17:35:00",
"opponent": "Miami Marlins"
},
{
"date": "2025-08-18",
"start_time": "2025-08-18 23:10:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-08-19",
"start_time": "2025-08-19 23:10:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-08-21",
"start_time": "2025-08-21 23:15:00",
"opponent": "New York Yankees"
},
{
"date": "2025-08-22",
"start_time": "2025-08-22 23:05:00",
"opponent": "New York Yankees"
},
{
"date": "2025-08-23",
"start_time": "2025-08-23 17:05:00",
"opponent": "New York Yankees"
},
{
"date": "2025-08-24",
"start_time": "2025-08-24 17:35:00",
"opponent": "New York Yankees"
},
{
"date": "2025-08-25",
"start_time": "2025-08-25 22:35:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-08-26",
"start_time": "2025-08-26 22:35:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-08-27",
"start_time": "2025-08-27 22:35:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-08-28",
"start_time": "2025-08-28 17:05:00",
"opponent": "Baltimore Orioles"
},
{
"date": "2025-08-29",
"start_time": "2025-08-29 23:10:00",
"opponent": "Pittsburgh Pirates"
},
{
"date": "2025-08-30",
"start_time": "2025-08-30 20:10:00",
"opponent": "Pittsburgh Pirates"
},
{
"date": "2025-08-31",
"start_time": "2025-08-31 17:35:00",
"opponent": "Pittsburgh Pirates"
},
{
"date": "2025-09-01",
"start_time": "2025-09-01 17:35:00",
"opponent": "Cleveland Guardians"
},
{
"date": "2025-09-02",
"start_time": "2025-09-02 22:45:00",
"opponent": "Cleveland Guardians"
},
{
"date": "2025-09-03",
"start_time": "2025-09-03 22:45:00",
"opponent": "Cleveland Guardians"
},
{
"date": "2025-09-05",
"start_time": "2025-09-06 01:40:00",
"opponent": "Arizona Diamondbacks"
},
{
"date": "2025-09-06",
"start_time": "2025-09-07 00:10:00",
"opponent": "Arizona Diamondbacks"
},
{
"date": "2025-09-07",
"start_time": "2025-09-07 20:10:00",
"opponent": "Arizona Diamondbacks"
},
{
"date": "2025-09-08",
"start_time": "2025-09-09 02:05:00",
"opponent": "Athletics"
},
{
"date": "2025-09-09",
"start_time": "2025-09-10 02:05:00",
"opponent": "Athletics"
},
{
"date": "2025-09-10",
"start_time": "2025-09-10 19:35:00",
"opponent": "Athletics"
},
{
"date": "2025-09-12",
"start_time": "2025-09-12 23:10:00",
"opponent": "New York Yankees"
},
{
"date": "2025-09-13",
"start_time": "2025-09-13 20:10:00",
"opponent": "New York Yankees"
},
{
"date": "2025-09-14",
"start_time": "2025-09-14 17:35:00",
"opponent": "New York Yankees"
},
{
"date": "2025-09-16",
"start_time": "2025-09-16 22:45:00",
"opponent": "Athletics"
},
{
"date": "2025-09-17",
"start_time": "2025-09-17 22:45:00",
"opponent": "Athletics"
},
{
"date": "2025-09-18",
"start_time": "2025-09-18 17:35:00",
"opponent": "Athletics"
},
{
"date": "2025-09-19",
"start_time": "2025-09-19 23:35:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-09-20",
"start_time": "2025-09-20 23:05:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-09-21",
"start_time": "2025-09-21 16:10:00",
"opponent": "Tampa Bay Rays"
},
{
"date": "2025-09-23",
"start_time": "2025-09-23 23:07:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-09-24",
"start_time": "2025-09-24 23:07:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-09-25",
"start_time": "2025-09-25 23:07:00",
"opponent": "Toronto Blue Jays"
},
{
"date": "2025-09-26",
"start_time": "2025-09-26 23:10:00",
"opponent": "Detroit Tigers"
},
{
"date": "2025-09-27",
"start_time": "2025-09-27 20:10:00",
"opponent": "Detroit Tigers"
},
{
"date": "2025-09-28",
"start_time": "2025-09-28 19:05:00",
"opponent": "Detroit Tigers"
}
]

73
src/main.rs Normal file
View File

@ -0,0 +1,73 @@
#![cfg_attr(debug_assertions, allow(dead_code, unused_imports))]
mod weather;
mod redsox;
use tabled::Table;
use tabled::settings::{
peaker::Priority, Width, Style, Alignment, object::Columns
};
use serde::{Deserialize, Serialize};
use tabled::Tabled;
#[derive(Serialize, Deserialize, Debug, Tabled)]
#[tabled(rename_all = "UPPERCASE")]
struct TableRow {
date: String,
time_of_day: String,
temp: u64,
red_sox: String,
forecast: String,
}
#[allow(unreachable_code)]
fn main() {
let baseball_diamond = '\u{f15ec}';
let sunny = '\u{f0599}';
// Set the weather location here.
let location = weather::WeatherOfficeLocation {
x: 75,
y: 59,
code: "GYX".to_string(),
};
// @todo - add a way to configure which teams to add
// @todo - add a way to get news articles?
let entire_forecast: Vec<weather::WeatherPeriod> = weather::get_full_forecast(location);
let sox_games: Vec<redsox::Game> = redsox::get_upcoming_games();
let mut table_rows: Vec<TableRow> = vec![];
for i in 0..entire_forecast.len() {
let item = &entire_forecast[i];
let date = &item.start_time[0..10];
let mut sox_status = String::new();
// Check if there is a sox game and print opp.
for sox_game in &sox_games {
if sox_game.date == date {
let mut opp_str = String::new();
opp_str.push(baseball_diamond);
opp_str.push_str(" ");
opp_str.push_str(&sox_game.opponent);
sox_status = opp_str;
break;
}
}
let mut forecast_w_icon = String::new();
forecast_w_icon.push(sunny);
forecast_w_icon.push_str(" ");
forecast_w_icon.push_str(&item.detailed_forecast);
let row = TableRow {
date: date.to_string(),
time_of_day: item.name.clone(),
temp: item.temperature,
red_sox: sox_status,
forecast: forecast_w_icon,
};
table_rows.push(row);
}
let mut table = Table::new(table_rows);
table.with(Style::modern());
table.with((
Width::wrap(210).priority(Priority::max(true)),
Width::increase(50).priority(Priority::min(true)),
));
table.modify(Columns::first(), Alignment::right());
println!("{}", table);
}

72
src/redsox/mod.rs Normal file
View File

@ -0,0 +1,72 @@
use serde::{Deserialize, Serialize};
use serde_alias::serde_alias;
use std::fs;
const SOX_ID: i32 = 111;
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_alias(CamelCase,SnakeCase)]
pub struct Schedule {
pub games: Vec<Game>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_alias(CamelCase,SnakeCase)]
pub struct Game {
// pub teams: Teams,
pub date: String,
// pub start_time: String,
pub opponent: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_alias(CamelCase,SnakeCase)]
pub struct Teams {
away: Team,
home: Team,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_alias(CamelCase,SnakeCase)]
pub struct Team {
team: TeamInfo,
league_record: TeamRecord,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_alias(CamelCase,SnakeCase)]
pub struct TeamInfo {
id: i32,
name: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_alias(CamelCase,SnakeCase)]
pub struct TeamRecord {
wins: i32,
losses: i32,
}
pub fn get_upcoming_games() -> Vec<Game> {
// @todo - change this to be a dynamic request from the API endpoint instead of a local file.
let schedule_json: String = fs::read_to_string("/Users/danchadwick/Projects/rust/weather/assets/sox-schedule.json").expect("Unable to read file").to_owned();
let json: Vec<Game> = serde_json::from_str(&schedule_json).expect("Something not good?");
let upcoming_games: &Vec<Game> = &json.into_iter().take(7).collect();
upcoming_games.to_owned()
}
// Gets the full forecast from the response.
pub fn get_schedule() -> Schedule {
let url = "https://statsapi.mlb.com/api/v1/schedule?sportId=1&teamId=111&startDate=2025-04-01&endDate=2025-09-30".to_string();
let client = reqwest::blocking::Client::new();
let schedule_string: String = client.get(&url).send().expect("Unable to get data").text().unwrap().to_string();
let json: Schedule = serde_json::from_str(&schedule_string).expect("JSON was not well-formatted");
dbg!(json);
let schedule = Schedule {
games: vec![],
};
schedule
// json
}

54
src/weather/mod.rs Normal file
View File

@ -0,0 +1,54 @@
use reqwest::header::USER_AGENT;
use serde::{Deserialize, Serialize};
use serde_alias::serde_alias;
#[derive(Debug, Serialize, Deserialize)]
pub struct ForecastWrapper {
properties: Properties,
}
#[derive(Debug, Serialize, Deserialize)]
struct Properties {
periods: Vec<WeatherPeriod>,
}
#[serde_alias(CamelCase,SnakeCase)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WeatherPeriod {
pub name: String,
pub temperature: u64,
pub wind_direction: String,
pub wind_speed: String,
pub detailed_forecast: String,
pub start_time: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct WeatherOfficeLocation {
pub x: i32,
pub y: i32,
pub code: String,
}
impl WeatherOfficeLocation {
pub fn build_url(&self) -> String {
format!(
"https://api.weather.gov/gridpoints/{}/{},{}/forecast",
self.code,
self.x,
self.y
)
}
}
// Gets the full forecast from the response.
pub fn get_full_forecast(location: WeatherOfficeLocation) -> Vec<WeatherPeriod> {
let url = WeatherOfficeLocation::build_url(&location);
let client = reqwest::blocking::Client::new();
let forecast = client.get(&url).header(USER_AGENT, "My SuperAwesome Weather App").send().expect("Unable to get data").text().unwrap().to_string();
let json: ForecastWrapper = serde_json::from_str(&forecast).expect("JSON was not well-formatted");
let periods: Vec<WeatherPeriod> = json.properties.periods.into_iter().collect();
periods
}