Re: new here

Liste des GroupesRevenir à cl python 
Sujet : Re: new here
De : bowman (at) *nospam* montana.com (rbowman)
Groupes : comp.lang.python
Date : 28. Aug 2024, 19:06:33
Autres entêtes
Message-ID : <lj9799F3k5jU1@mid.individual.net>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Pan/0.149 (Bellevue; 4c157ba)
On Wed, 28 Aug 2024 08:41:28 +0100, Daniel wrote:

That is so cool. I've had the same idea to use the API with AWS for my
bbs. I also want to do the same thing for other government sites like
ecfr for pulling aviation regulations.
 
Is your code somewhere I can look at it?

The NOAA?  I didn't get dncy so I'm calling get_station_info with a
hardcoded latitude and longitude.  The commented out print(json.dumps())
pretty print the JSON so you can decide what to extract. I'm not 100% sure
about tacking K onto the grid ID. The famous 'works for me' A URL like

https://forecast.weather.gov/MapClick.php?lat=40.8551337&lon=-114.0140115

will show the same info, in this case for Wendover Airport (KENV).

https://www.weather.gov/documentation/services-web-api

is the documentation for the API.

import json
import requests

def get_station_info(latitude, longitude):
    url = f"https://api.weather.gov/points/{latitude},{longitude}"
    response = requests.get(url).json()
#    print(json.dumps(response, indent=4, sort_keys=True))
    property = response['properties']
    grid_id = property["gridId"]
    grid_x = property["gridX"]
    grid_y = property["gridY"]
    forecast_url = property["forecast"]
    observation_url = f"https://api.weather.gov/stations/K{grid_id}/
observations/latest"
    response = requests.get(observation_url).json()
#   print(json.dumps(response, indent=4, sort_keys=True))
    properties = response['properties']
    pressure = properties['barometricPressure']
    temperature = properties['temperature']
    humidity = properties['relativeHumidity']
    dewpoint = properties['dewpoint']

    temp = 9 * temperature['value'] / 5 + 32
    dew = 9 * dewpoint['value'] / 5 + 32
    hum = humidity['value']
    bp = pressure['value'] * 0.000295
    print(f"temperature {temp} dewpoint {dew:.2f} humidity  {hum:.2f} 
pressure {bp:.2f}\n")

    response = requests.get(forecast_url).json()
    properties = response['properties']
    periods = properties['periods']
#        print(json.dumps(period, indent=4, sort_keys=True))
    for i in range(0, len(periods)):
        period = periods[i]
        print(period['name'])
        print(period['detailedForecast'])
        print(f"temperature: {period['temperature']}")
        print(f"wind {period['windSpeed']}  {period['windDirection']}")
        print()


Date Sujet#  Auteur
21 Aug 24 * Re: new here22rbowman
22 Aug 24 +* Re: new here2dn
22 Aug 24 i`- Re: new here1rbowman
22 Aug 24 +- Re: new here1Jason Friedman
22 Aug 24 +* Re: new here2rbowman
22 Aug 24 i`- Re: new here1rbowman
22 Aug 24 `* Re: new here16Paul Rubin
22 Aug 24  `* Re: new here15rbowman
22 Aug 24   `* Re: new here14dn
23 Aug 24    +* Re: new here3Paul Rubin
23 Aug 24    i`* Re: new here2rbowman
26 Aug 24    i `- Re: new here1dn
23 Aug 24    `* Re: new here10rbowman
23 Aug 24     +* Re: new here (Posting On Python-List Prohibited)2Lawrence D'Oliveiro
25 Aug 24     i`- Re: new here1Keith Thompson
23 Aug 24     `* Re: new here7dn
23 Aug 24      `* Re: new here6rbowman
26 Aug 24       +* Re: new here3<avi.e.gross
26 Aug 24       i`* Re: new here2rbowman
28 Aug 24       i `- Re: new here1rbowman
26 Aug 24       +- Re: new here1MRAB
26 Aug 24       `- Re: new here1<avi.e.gross

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal