GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - metwit/metwit-python: Metwit weather API client library for Python

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
metwit
metwit
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
example.py
example.py
 
 
setup.py
setup.py
 
 

Repository files navigation

Metwit API for Python

A Python client for Metwit weather API.

It's as simple as this:

from metwit import Metwit

weather = Metwit.weather.get(location_lat=45.45,
                             location_lng=9.18)

Good! Hope it's not raining.

# weather[0] is the real-time weather in a location
if weather[0]['weather']['status'] == 'rainy':
    print 'Better take my umbrella with me'

What if I want to authenticate my app?

from metwit import Metwit

CLIENT_ID = '111111'
CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

metwit = Metwit(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
metwit.token_client_credentials()

metwit.weather.get(location_lat=45.45, location_lng=9.18)

Fine. This will allow me to use credits from my plan and make more API calls.

Posting data

Metwit API plans come with a number of weather calls you can make daily. You can overcome the limit by posting data. Every time you post meaningful data to Metwit, your limits will extend.

How? Post a Metag:

metag = {
    'geo': {
        'lat': 45.45,
        'lng': 9.18,
    }
    'weather': {
        'status': 'rainy',
    },
}
metwit.metags.post(metag)

geo is the only mandatory field. As an overview, a Metag object may contain weather status, measured data (temperature, pressure, humidity, etc) and sensory info (I feel hot/warm/etc). Detailed reference is available on the Metwit API documentation page for metags.

Reference

All you need is the Metwit class.

class metwit.Metwit([client_id], [client_secret], [access_token], [refresh_token])

client_id and client_secret come from the Developer Dashboard. You only need those if you registered an application. You shouldn't include a client secret if you are going to distribute the code of your application (as opposed to application code hosted on a server, or running on your machine, for example).

If you stored an access_token (and refresh_token) elsewhere you can pass them to the constructor, otherwise you can make unauthenticated calls, or obtain a token with get_token() or one of the shortcut methods.

Metwit.metags

Metwit.weather

Metwit.users

These are the API resources. You can .get() and .post() these, or get individual items with the subscript operator (e.g. Metwit.metag['123456'].get()).

Metwit.get_token(grant_type, **kwargs)

Calls the token endpoint to obtain an access token. The Metwit object stores the access token for you, so API calls after this will be authenticated.

Metwit.dialog(redirect_uri, [scope], [state], [implicit])

Returns the URL for the OAuth 2.0 authorization dialog. If you want to act in behalf of the users, you should redirect their browser to this URL.

Metwit.token_auth_code(code, redirect_uri)

This is a shortcut to get_token(). Use it when your users go through the authorization dialog and you get the authorization code back.

Metwit.token_client_credentials()

This is a shortcut to get_token(). Use it when you just want to query the weather and don't need to act in behalf of a user.

Metwit.token_password(username, password, [scope])

This is a shortcut to get_token(). Use it when you have the username and the password of a Metwit user.

Metwit.resource(uri)

Use this when you have the URI of a resource and need to access it. E.g. metwit.resource('/v2/metags/123456/').get().

About

Metwit weather API client library for Python

Resources

Readme
BSD-3-Clause license
Activity
Custom properties

Stars

0 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.