Skip to main content

OpenWeatherMap.org API wrapper

Project description

VERY basic start for a OpenWeatherMap.org API client.

Frankly, it as been written rather to test how Python modules are distributed. :)

Install

pip install openweather

Python module example

import openweather
from datetime import datetime

# create client
ow = openweather.OpenWeather()

# find weather stations near me
stations = ow.find_stations_near(
    7.0,  # longitude
    50.0, # latitude
    100   # kilometer radius
)

# iterate results
for station in stations:
    print station

# get current weather at Cologne/Bonn airport
# (station id = 4885)
print ow.get_weather(4885)

# historic weather
start_date = datetime(2013, 09, 10)
end_date = datetime(2013, 09, 15)

# default: hourly interval
print ow.get_historic_weather(4885, start_date, end_date)

# raw data (resolution = "tick")
print ow.get_historic_weather(4885, start_date, end_date, "tick")

# daily aggregates
print ow.get_historic_weather(4885, start_date, end_date, "day")

Command line client example

Print current weather at station ID 4885:

$ openweather -s 4885

Print historic weather at station ID 4885:

$ openweather -s 4885 --historic

Print historic weather for 2013-10-01 at station ID 4885:

$ openweather -s 4885 --historic --date 20131001

For valid formats of the --date parameter, see daterangestr.

Print historic data in CSV format

$ python openweather.py -s 4885 --historic --date 20131022 --csv

This is particularly usefull if you want to store that data to a file…

$ openweather -s 4885 --historic --date 20131022 --csv > weather.csv

… or want to manipulate and display it (using csvkit):

$ openweather -s 4885 --historic --date 20131027 --csv|csvcut -c 9,26,30,35,43|csvlook
|-------------+-------------+------------+------------+---------------|
|  dt         | main_temp_v | pressure_v | wind_deg_v | wind_speed_v  |
|-------------+-------------+------------+------------+---------------|
|  1382824800 | 287.15      | 1005       |            | 4.1           |
|  1382835600 | 290.4       | 1008.25    | 170        | 5.93          |
|  1382839200 | 289.15      | 1007.5     | 175        | 5.1           |
...
|  1382904000 | 287.15      | 1007       | 210        | 5.9           |
|  1382907600 | 287.15      | 1007       | 200        | 6.2           |
|  1382911200 | 287.15      | 1006       | 177        | 5.1           |
|             |             |            |            |               |
|-------------+-------------+------------+------------+---------------|

Like openweather?

Feel free to tip me!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openweather-0.9.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file openweather-0.9.tar.gz.

File metadata

  • Download URL: openweather-0.9.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for openweather-0.9.tar.gz
Algorithm Hash digest
SHA256 5586ecb84f17271fb6c10422fbea04fe5e361caaa2ea73c606bccfc11ee9dbd7
MD5 0a18115ce9862b73f7a0c4eb143d4d8b
BLAKE2b-256 2f24e5d77006e8d8c4cbc03a3e7e0c9bef5e664f590cb78fd4ed989ac17b857f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page