Upload
claudio-sparpaglione
View
190
Download
7
Embed Size (px)
DESCRIPTION
Tech talk about setting up an open source project given at Italian Developers in London meetup (Oct 1st, 2014) http://www.meetup.com/Italian-Developers-in-London/events/205107652/
Citation preview
PYOWMMY FIRST OPEN SOURCE
PROJECT
CLAUDIO SPARPAGLIONE
@CSPARPA
THE BIRTH OF PYOWM
Once upon a time ...
1.I need to use weather data in my own Python app
2.Open Weather Map web API? Wow!
3.There are no Python clients for this web API... Damn!
4.Ok, I’ll build one!
THERE’S ALWAYS A FIRST TIME
• PyOWM (Sep 2013) is my first open source project ever
• Why such an effort?– pay the open source community back for its outstanding gifts
– will to learn something new– meet fellow devs– gain exposure in the community
WHAT IS OPEN WEATHER MAP?
• openweathermap.org is a free weather data provider website + API
• Weather data is retrieved from global meteo services and from 40000+ community meteostations
• Light JSON/XML API, suitable for mobile apps and web widgets
WHAT DATA CAN I GET FROM IT?
• Data samples:– weather status, temperature, wind speed & direction, clouds coverage, humidity, rain & snow amount, ...
• Context:– historic/current/forecast weather data on locations or lat-lon
• OGC-compliant WMS layers
WHAT IS PYOWM?
• Python client wrapper around the OWM web API (v2.5)
• It allows easy OWM weather data consumption to both:
1. humans (via high-level abstractions and a human-friendly interface)
2. machines (via a simple OO API)
HOW TO INSTALL
• From the Python Package Index– Use pip :
• Supported platforms:– Python 2.7 and 3.2+– No deps required
pip install pyowm
• Current release: 2.0.0• MIT license
SHOW ME SOME CODE!from pyowm import OWM, timeutilsowm = OWM()
# Current wind and temp in Londonobs = owm.weather_at_place('London,uk')w = obs.get_weather()print w.get_wind(), w.get_temperature('celsius')
# Will it be sunny tomorrow in Milan?f = owm.daily_forecast("Milan,it")print f.will_be_sunny_at(timeutils.tomorrow())
# Current weather in cities around Rio de Janeiro# (lat 22.57 S, lon 43.12 W)print owm.weather_around_coords(-22.57, -43.12)
ALL FEATURES (1/2)# Retrieve current weatherowm.weather_at_place('London,uk')owm.weather_at_coords(-22.57, -43.12)owm.weather_at_places('London', searchtype='accurate', \ limit=3)owm.weather_around_coords(-22.57, -43.12, limit=2)
# Retrieve weather forecastowm.three_hours_forecast('London,uk')owm.daily_forecast('London,uk')
# Retrieve weather historyowm.weather_history_at_place('London,uk', \ '2013-09-13 16:46:40+00', '2013-09-13 19:16:40+00')h = owm.station_tick_history(39276)
ALL FEATURES (2/2)# Human-friendly utilities (subset)f.will_have_rain()f.will_have_fog()f.when_sun()f.when_snow()f.will_be_sunny_at(timeutils.tomorrow())f.will_be_cloudy_at(timeutils.next_three_hours())f.most_hot()f.most_windy()
# Historic weather data seriesh.temperature_series(unit='kelvin')h.rain_series()
# Dump all objects to JSON or XMLobs.to_JSON()w.to_XML()
PROJECT STRUCTURE
• Code modules:– abstract classes– basic cache implementation– common utilities– object model for OWM web API
2.5 wrapping
• Test modules:– unit tests for each class– functional tests (integration
against the real API)
PYOWM├───pyowm │ ├───abstractions │ ├───caches │ ├───commons │ ├───exceptions │ ├───utils │ └───webapi25└───tests ├───functional │ └───webapi25 └───unit ├───caches ├───commons ├───utils └───webapi25
WHAT DO YOU NEED TO STARTAN OPEN SOURCE PROJECT?
• Cooperate– collaborative platform for code and information sharing
– distributed revision control tool
• Strive for quality– documentation– testing– issue tracker
• Automatise repetitive tasks• Ship quickly to as many as possible
• Project platform and SCM:– GitHub (code, wiki, issues)– Git
• Testing:– pyUnit for all testing– continous integration using Travis-CI– code coverage check with coveralls.io
PROJECT SETUP AND TOOLS (1/2)
PROJECT SETUP AND TOOLS (2/2)
• Documentation:– continuous integration with Sphinx & readthedocs
• Distribution tools:– PyPI to store .eggs, source tarballs and Win installers
THE MAJOR DEEDS
• OWM web API has pitfalls:– poorly documented– doesn’t rely on HTTP status codes!– different JSON payloads for same conceptual data entities
• No code contributors• Little time!
ACHIEVEMENTS
• Learned a lot of tech things and so became a better programmer
• New followers on social networks• Got new issues reported• PyOWM quite downloaded from PyPI (~ 500/week)
• I’m now giving it a talk!
THE NEXT CHALLENGES
• Workflow: use @nvie’s branching• Testing:– test platform compatibility using tox– check code coverage– increase code coverage (now 89%)
• Stronger community involvement on– bug tracking– code reviews
• Support for next OWM API version?
CHECK IT OUT!
•https://github.com/csparpa/pyowm
at = "@"me = "csparpa"
# E-mailprint "".join([me, at, "gmail.com"])# Twitterprint "".join([at, me])
• And get in touch!
THANKS! - QUESTIONS?