diff --git a/__pycache__/managers.cpython-310.pyc b/__pycache__/managers.cpython-310.pyc index ac61974..8a3dabe 100644 Binary files a/__pycache__/managers.cpython-310.pyc and b/__pycache__/managers.cpython-310.pyc differ diff --git a/__pycache__/objects.cpython-310.pyc b/__pycache__/objects.cpython-310.pyc index 0d781e7..7061d60 100644 Binary files a/__pycache__/objects.cpython-310.pyc and b/__pycache__/objects.cpython-310.pyc differ diff --git a/__pycache__/osm.cpython-310.pyc b/__pycache__/osm.cpython-310.pyc index f7ea589..c42c4b9 100644 Binary files a/__pycache__/osm.cpython-310.pyc and b/__pycache__/osm.cpython-310.pyc differ diff --git a/__pycache__/publicTransport.cpython-310.pyc b/__pycache__/publicTransport.cpython-310.pyc index 1ba5809..8be78c3 100644 Binary files a/__pycache__/publicTransport.cpython-310.pyc and b/__pycache__/publicTransport.cpython-310.pyc differ diff --git a/main.py b/main.py index 8412795..055b7ab 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ OFFLINE = True -from managers import ShopManager +from managers import PlaceManager from osm import OSM from publicTransport import PublicTransportAccessibility import requests @@ -46,7 +46,7 @@ else: osm = OSM(r.text) pta = PublicTransportAccessibility(osm) -shopManager = ShopManager(osm) +placeManager = PlaceManager(osm) print("\n--- Public Transport Accessibility ---") print("Bus: " + str(pta.isBusAccessible())) @@ -56,11 +56,9 @@ print("Subway: " + str(pta.isSubwayAccessible())) print("Train: " + str(pta.isTrainAccessible())) print("Monorail: " + str(pta.isMonorailAccessible())) -print("\n--- 10 Most present shop types ---") +print("\n--- 20 Most present places types ---") counter = 0 -for s in shopManager.getCountsOfTypes(): - if counter <= 10: +for s in placeManager.getCountsOfTypes(): + if counter <= 20: print(s['type'] + " : " + str(s['count']) + " times") counter = counter + 1 - - diff --git a/managers.py b/managers.py index 6a8931c..170acfa 100644 --- a/managers.py +++ b/managers.py @@ -1,6 +1,6 @@ from operator import itemgetter -class ShopManager: +class PlaceManager: def __init__(self, _osm): self.osm = _osm @@ -13,9 +13,25 @@ class ShopManager: return True return False - if self.osm.shopList: - for shop in self.osm.shopList: - if not isInDict(shop.type): - countDict.append({'type': shop.type, 'count': sum(a.type == shop.type for a in self.osm.shopList)}) + if self.osm.placeList: + for place in self.osm.placeList: + if not isInDict(place.type): + countDict.append({'type': place.type, 'count': sum(a.type == place.type for a in self.osm.placeList)}) return sorted(countDict, key=itemgetter('count'), reverse=True) + + def getPlacesByType(self, type): + result = [] + for a in self.osm.placeList: + if a.type == type: + result.append(a) + + return result + + def getPlacesByName(self, name): + result = [] + for a in self.osm.placeList: + if a.name == name: + result.append(a) + + return result \ No newline at end of file diff --git a/objects/__pycache__/amenities.cpython-310.pyc b/objects/__pycache__/amenities.cpython-310.pyc new file mode 100644 index 0000000..eae9fda Binary files /dev/null and b/objects/__pycache__/amenities.cpython-310.pyc differ diff --git a/objects/__pycache__/baseObjects.cpython-310.pyc b/objects/__pycache__/baseObjects.cpython-310.pyc new file mode 100644 index 0000000..9d08c78 Binary files /dev/null and b/objects/__pycache__/baseObjects.cpython-310.pyc differ diff --git a/objects/__pycache__/metaObjects.cpython-310.pyc b/objects/__pycache__/metaObjects.cpython-310.pyc new file mode 100644 index 0000000..3b8b292 Binary files /dev/null and b/objects/__pycache__/metaObjects.cpython-310.pyc differ diff --git a/objects.py b/objects/baseObjects.py similarity index 76% rename from objects.py rename to objects/baseObjects.py index 60104ef..e5f4b66 100644 --- a/objects.py +++ b/objects/baseObjects.py @@ -1,18 +1,19 @@ -# ! "amenity" are used very often in osm it's referreing to healtcare, police, cafe, pub, ice cream, post etc. -# ! There is defently a need to sort them more on not just take them all into a "amenity" class - # TODO new objects: healthcare, police +# TODO Address object "addr:" # ? offices # ? How to handle districts -class Shop: - # TODO More optional details/attributes. Example: "website", "brand", "Telefone", "Owner", "opening times" - def __init__(self, _nodeIds, _name, _type): + +class Place: + def __init__(self, _nodeIds, _type, _name, _address = None, _contact = None, _openingHours = None): self.nodeIds = _nodeIds - self.name = _name self.type = _type + self.name = _name + self.address = _address + self.contact = _contact + self.openingHours = _openingHours class Node: def __init__(self, _id, _lon, _lat, _version, _timestamp, _changeset, _uid, _user): diff --git a/objects/metaObjects.py b/objects/metaObjects.py new file mode 100644 index 0000000..f263671 --- /dev/null +++ b/objects/metaObjects.py @@ -0,0 +1,44 @@ +class Contact: + def __init__(self, _phone = None, _fax = None, _email = None, _website = None, _mobile = None): + self.phone = _phone + self.fax = _fax + self.email = _email + self.website = _website + self.mobile = _mobile + #Social + self.facebook = None + self.vk = None + self.instagram = None + self.twitter = None + self.youtube = None + self.ok = None + self.webcam = None + self.telegram = None + self.whatsapp = None + self.linkedin = None + self.pinterest = None + self.viper = None + self.foursquare = None + self.skype = None + self.xing = None + self.vhf = None + self.flickr = None + self.mastodon = None + self.sip = None + self.diaspora = None + self.gnusocial = None + # TODO support custom social tags MAYBE: there should ne no need + + +class Address: + def __init__(self, _housenumber = None, _street = None, _place = None, + _city = None, _postcode = None, _country = None, _suburb = None, _state = None, _province = None): + self.housenumber = _housenumber + self.street = _street + self.place = _place + self.city = _city + self.postcode = _postcode + self.country = _country + self.suburb = _suburb + self.state = _state + self.province = _province \ No newline at end of file diff --git a/osm.py b/osm.py index 4465189..8c5b786 100644 --- a/osm.py +++ b/osm.py @@ -1,4 +1,5 @@ -from objects import Node, NodeTag, Way, WayTag, Shop +from objects.baseObjects import Node, NodeTag, Way, WayTag, Place +from objects.metaObjects import Address, Contact class OSM: # TODO Average value of "last updated" to see how up to date the data is. @@ -8,7 +9,8 @@ class OSM: self.nodeTagList = [] self.wayList = [] self.wayTagList = [] - self.shopList = [] + self.placeList = [] + self.parseOsmContent() def parseOsmContent(self): @@ -45,29 +47,129 @@ class OSM: elif len(wayLines) > 0: wayLines.append(line) - def createShop(self, lines): - # TODO Make sure shops are not duplicates. - # TODO e.g. REWE(shop) is big enough to have some "Ways" of it's own and multiple nodes, which can cause duplicates. - - nodeIds = [] - type = "" - name = "" + def createContact(self, lines): + c = Contact() for line in lines: if '