generated from cvxgrp/simulator
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
105 experiment with python fire (#107)
* fire in pyproject * weather example with fire * wrote test for the fire application * wrote test for the fire application * remove the click based weather cli * move pyyaml out of 1st class dependencies * serialize into problem class * remove smallest eigenvalue cli * remove smallest eigenvalue cli * move from fff to main * switch minvariance.py to fire
- Loading branch information
Showing
14 changed files
with
191 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
import fire | ||
import requests | ||
|
||
|
||
def cli(metric: str, latitude: float = 37.4419, longitude: float = -122.143) -> None: | ||
""" | ||
Get the current weather for a given metric | ||
Parameters | ||
---------- | ||
metric : str | ||
The metric to get the current weather for | ||
latitude : float, optional | ||
The latitude to get the current weather for, by default 37.4419 | ||
longitude : float, optional | ||
The longitude to get the current weather for, by default -122.143 | ||
""" | ||
url = "https://api.open-meteo.com/v1/forecast" | ||
url = f"{url}?latitude={str(latitude)}&longitude={str(longitude)}¤t_weather=true" | ||
r = requests.get(url) | ||
|
||
if r.status_code == 200: | ||
if metric in r.json()["current_weather"]: | ||
x = r.json()["current_weather"][metric] | ||
return x | ||
else: | ||
raise ValueError("Metric not supported!") | ||
else: | ||
raise ConnectionError("Open-Meteo is down!") | ||
|
||
|
||
def main(): # pragma: no cover | ||
""" | ||
Run the CLI using Fire | ||
""" | ||
fire.Fire(cli) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.