]> git.openstreetmap.org Git - chef.git/blob - cookbooks/osqa/files/default/osmauth/osm.py
Use 12.04 chef packages on 12.10
[chef.git] / cookbooks / osqa / files / default / osmauth / osm.py
1 from xml.etree.ElementTree import ElementTree
2 import urllib2
3
4 class OpenStreetMapAPI:
5     def __init__(self, username, password):
6         passman = urllib2.HTTPPasswordMgr()
7         passman.add_password("Web Password", "https://api.openstreetmap.org/api/0.6", username, password)
8         authhandler =  urllib2.HTTPBasicAuthHandler(passman)
9         self.opener = urllib2.build_opener(authhandler)
10
11     def user_details(self):
12         response = self.opener.open("https://api.openstreetmap.org/api/0.6/user/details")
13         tree = ElementTree()
14         root = tree.parse(response)
15         user = root.find("user")
16         return {
17             "id": user.attrib["id"],
18             "display_name": user.attrib["display_name"]
19         }