source: subversion/imports/ongoing/osmsync_metavera.py @ 26655

Last change on this file since 26655 was 26653, checked in by bnesbitt, 8 years ago

Any car share supported by metavera: for example Drivemint

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/usr/bin/python
2##
3##  Author: Bryce Nesbitt, June 2011
4##  Licence: Public Domain, no rights reserved
5##
6##  osmsync module to mirror City CarShare "pods" into osm
7##
8##  See also:
9##      http://wiki.openstreetmap.org/wiki/Tag:amenity%3Dcar_sharing
10##
11##  Future work:
12##      Support capacity=* tag
13##      Warn human about location discrepencies over 100 meters
14##
15import sys
16sys.path = ['../../applications/utils/import/osmsync/'] + sys.path
17from osmsync import osmsync
18
19import sys, re, urllib, urllib2
20import csv, demjson
21import xml.sax.saxutils
22
23from   pprint     import pprint
24from   xml.etree  import ElementTree
25
26
27
28class osmsync_metavera(osmsync):
29    """ Mirror merge Metavera car share reservation system data into OSM """
30
31    #
32    #   [{"id":"1","descr":"33 W 56th Street",
33    #   "latitude":"40.763199","longitude":"-73.976380","vehicle_types":"4,15,"},
34    #
35    def fetch_source(self, sourcedata):
36        sourcenodes = {}
37
38        req = urllib2.Request(sourcedata, headers=self.http_headers);
39        body = urllib2.urlopen(req).read()
40
41        pods = demjson.decode(body)
42
43        for pod in pods:
44            pkey    = pod['id']
45            commas  = pod['vehicle_types'].strip().count(',')
46
47            osmnode = {}
48            osmnode['tag']                  = {}
49            osmnode['lat']                  = pod['latitude']
50            osmnode['lon']                  = pod['longitude']
51            osmnode['tag']['amenity']       = 'car_sharing'
52            osmnode['tag']['operator']      = 'Drivemint'
53            osmnode['tag']['capacity']      = str(commas + 1)
54            osmnode['tag']['name']          = pod['descr'].strip()
55           #osmnode['tag']['website']       = pod['url'].strip()
56           #osmnode['tag']['description']   = pod['addr'] .strip()+ " with " + ccs_pod['vstring'].strip()
57            osmnode['tag']['source']        = 'osmsync:metavera'
58            osmnode['tag']['source:pkey']   = pkey
59            sourcenodes[pkey] = osmnode
60
61        source_is_master_for=['name','website','description','amenity','operator','source','capacity']
62        return(sourcenodes, source_is_master_for)
63
64
65    #   Override a few keys
66    def record_action(self, osmnode, action):
67        return(osmsync.record_action(self, osmnode, action))
68
69
70#############################################################################################
71#############################################################################################
72changeSetTags = {
73    'source'            : 'osmsync:metavera',
74    'source:website'    : 'https://reserve.drivemint.com/',
75    'conflation_key'    : 'source:pkey',
76    'note'              : 'Prepared for human review by osmsync: '+
77                          'reads the car share reservation system and suggests matching updates for osm.'
78    }
79myfetch = osmsync_metavera()
80myfetch.run(description='Metavera car sharing location mirror script',
81            ext_url="https://reserve.drivemint.com/maps/api/lots.php",
82            osm_url=osmsync.xapi_url + urllib.quote("node[source=osmsync:metavera]"),
83            )
84myfetch.output(changeSetTags)
Note: See TracBrowser for help on using the repository browser.