#api #api-client #energy #national-grid

bin+lib carbonintensity-api

提供英国国家电网碳强度 API 的客户端

2 个不稳定版本

0.2.0 2023 年 12 月 4 日
0.1.0 2023 年 11 月 21 日

#22 in #energy

Apache-2.0

21KB
316

carbonintensity-api

crates.io crates.io API

一个简单的 Rust 库,用于从 碳强度 API 获取数据,可能不会公开 CarbonIntensity API 的所有功能。

请阅读 API 的 使用条款

命令行界面

提供了一个可执行文件来尝试库。在安装了 Rust 和 Cargo 后

cargo install --path .

然后

carbonintensity-api-h

应显示可用的命令和选项列表。

Provides a client for the UK National Grid Carbon Intensity API

Usage: carbonintensity-api [OPTIONS] <COMMAND>

Commands:
  postcode  Outward section of a UK postcode e.g. E1, BS7, WC2N
  region    Region ID, a number between 1 and 17
  help      Print this message or the help of the given subcommand(s)

Options:
  -s, --start-date <START_DATE>  
  -e, --end-date <END_DATE>
  -h, --help                     Print help
  -V, --version                  Print version

要显示给定邮政编码的当前碳强度

carbonintensity-api postcode bs7

要对同一地区进行操作

carbonintensity-api region11

地区 ID 是介于 1 和 17 之间的数字

  1. 苏格兰北部
  2. 苏格兰南部
  3. 英格兰西北部
  4. 英格兰东北部
  5. 南约克郡
  6. 北威尔士、默西塞德郡和切舍郡
  7. 南威尔士
  8. 西 Midlands
  9. 东 Midlands
  10. 英格兰东部
  11. 英格兰西南部
  12. 英格兰南部
  13. 伦敦
  14. 英格兰东南部
  15. 英格兰
  16. 苏格兰
  17. 威尔士

指定日期将返回地区或邮政编码的强度列表。如果没有提供结束日期,将使用当前日期和时间。

日期应遵循 %Y-%m-%dT%H:%MZ 格式或简单地 %Y-%m-%d,例如

carbonintensity-api-s2023-11-11 -e2023-11-11T12:00Z postcode bs7

强度由 30 分钟的窗口返回。

您可以通过在 cargo 中添加它来在 Rust 项目中使用该库

cargoadd carbonintensity-api

然后在您的代码中声明它

use carbonintensity::{
    get_intensities_postcode, get_intensities_region, get_intensity_postcode, get_intensity_region,
    ApiError,
};

...

  let result = get_intensity_postcode(postcode).await;

许可证

本项目根据 Apache 许可证 提供。

依赖关系

~8–21MB
~316K SLoC