]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/osmauth/osm.py
q may not be there
[osqa.git] / forum_modules / 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         }