get shops

This commit is contained in:
Janis M
2022-03-22 12:41:36 +01:00
parent b5f701aeab
commit 5d8894c5c5
9 changed files with 105 additions and 8 deletions

4
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,4 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

18
main.py
View File

@@ -1,9 +1,14 @@
from osm import OSM
from places import Shops
from publicTransport import PublicTransportAccessibility
import requests
# 52.9152386,,15.96z
# bhv 53.51500036203292, 8.603602165157444
lon = 8.603602165157444 # 8.6039883
lat = 53.51500036203292 # 52.51608
# TODO Get User input
lon = 8.8285578 # 8.6039883
lat = 52.9152386 # 52.51608
# TODO Get real value based on a metric radius
areaHeightRadius = 0.01 # 0.01
@@ -21,18 +26,19 @@ requestsUrlParams = f"?bbox={minLon},{minLat},{maxLon},{maxLat}"
print(requestUrl + requestsUrlParams)
print("Downloading OSM-File...")
# TODO Check if banned from overpass-api
# TODO Check if banned from overpass-api MAYBE get alternative API then
r = requests.get(requestUrl + requestsUrlParams, headers={'Content-Type': 'application/xml'})
print("Done: Downloading OSM-File")
osm = OSM(r.text)
pta = PublicTransportAccessibility(osm)
shops = Shops(osm)
print("Bus:" + str(pta.isBusAccessible()))
print("Tram:" + str(pta.isTramAccessible()))
print("Light Rail:" + str(pta.isLightRailAccessible()))
print("Subway:" + str(pta.isSubwayAccessible()))
print("Train:" + str(pta.isTrainAccessible()))
print("Monorail:" + str(pta.isMonorailAccessible()))
print("Monorail:" + str(pta.isMonorailAccessible()))
print(shops.countOfShops())

View File

@@ -12,7 +12,24 @@ class Node:
class NodeTag:
def __init__(self, _id, _nodeId, _key, _value):
self.id = _id
self.id = int(_id)
self.nodeId = int(_nodeId)
self.key = str(_key)
self.value = str(_value)
class Way:
def __init__(self, _id, _version, _timestamp, _changeset, _uid, _user):
self.id = int(_id)
self.version = str(_version)
self.timestamp = str(_timestamp)
self.changeset = int(_changeset)
self.uid = int(_uid)
self.user = str(_user)
class WayTag:
def __init__(self, _id, _wayId, _key, _value):
self.id = int(_id)
self.wayId = int(_wayId)
self.key = str(_key)
self.value = str(_value)

37
osm.py
View File

@@ -1,16 +1,19 @@
from objects import Node, NodeTag
from objects import Node, NodeTag, Way, WayTag
class OSM:
def __init__(self, _osmContent):
self.osmContent = str(_osmContent)
self.nodeList = []
self.nodeTagList = []
self.wayList = []
self.wayTagList = []
self.parseOsmContent()
def parseOsmContent(self):
lines = self.osmContent.split("\n")
nodeLines = []
wayLines = []
for line in lines:
if "<node" in line:
@@ -29,7 +32,39 @@ class OSM:
nodeLines = []
elif len(nodeLines) > 0:
nodeLines.append(line)
elif "<way" in line:
wayLines.append(line)
elif "</way>" in line:
try:
self.createWay(wayLines)
except:
print("Way could not be inserted")
wayLines = []
elif len(wayLines) > 0:
wayLines.append(line)
def createWay(self, lines):
wayId = ""
for line in lines:
if "<way" in line:
wayId = str(line.split('id="')[1].split('"')[0])
wayVersion = str(line.split('version="')[1].split('"')[0])
wayTimestamp = str(line.split('timestamp="')[1].split('"')[0])
wayChangeset = str(line.split('changeset="')[1].split('"')[0])
wayUid = str(line.split('uid="')[1].split('"')[0])
wayUser = str(line.split('user="')[1].split('"')[0])
w = Way(wayId, wayVersion, wayTimestamp, wayChangeset, wayUid, wayUser)
self.wayList.append(w)
elif '<tag ' in line:
key = str(line.split('k="')[1].split('"')[0])
value = str(line.split('v="')[1].split('"')[0])
wt = WayTag(len(self.wayTagList), wayId, key, value)
self.wayTagList.append(wt)
def createNode(self, lines):
nodeId = ""

35
places.py Normal file
View File

@@ -0,0 +1,35 @@
from operator import itemgetter
class Shops:
def __init__(self, _osm):
self.osm = _osm
def getAllShops(self):
shopList = []
for tag in self.osm.nodeTagList:
if tag.key == "shop":
shopList.append(tag.value)
for tag in self.osm.wayTagList:
if tag.key == "shop":
shopList.append(tag.value)
return shopList
def countOfShops(self):
shopList = self.getAllShops()
countDict = []
if shopList:
def isInDict(name):
for a in countDict:
if a['name'] == name:
return True
return False
for shop in shopList:
print(shop)
if not isInDict(shop):
print("add" + str(shopList.count(shop)))
countDict.append({'name': shop, 'count': shopList.count(shop)})
return sorted(countDict, key=itemgetter('count'), reverse=True)