mirror of
https://github.com/DerTyp7/local-analyzer-python.git
synced 2025-10-29 04:22:10 +01:00
get rid of sql
This commit is contained in:
BIN
__pycache__/init_sql.cpython-310.pyc
Normal file
BIN
__pycache__/init_sql.cpython-310.pyc
Normal file
Binary file not shown.
17
objects.py
Normal file
17
objects.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, _id, _lon, _lat, _version, _timestamp, _changeset, _uid, _user):
|
||||||
|
self.id = int(_id)
|
||||||
|
self.lon = str(_lon)
|
||||||
|
self.lat = str(_lat)
|
||||||
|
self.version = str(_version)
|
||||||
|
self.timestamp = str(_timestamp)
|
||||||
|
self.changeset = int(_changeset)
|
||||||
|
self.uid = int(_uid)
|
||||||
|
self.user = str(_user)
|
||||||
|
|
||||||
|
|
||||||
|
class NodeTags:
|
||||||
|
def __init__(self, _nodeId, _key, _value):
|
||||||
|
self.nodeId = int(_nodeId)
|
||||||
|
self.key = str(_key)
|
||||||
|
self.value = str(_value)
|
||||||
0
.gitattributes → old/.gitattributes
vendored
0
.gitattributes → old/.gitattributes
vendored
0
.gitignore → old/.gitignore
vendored
0
.gitignore → old/.gitignore
vendored
66
osm.py
Normal file
66
osm.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
from objects import
|
||||||
|
class OSM:
|
||||||
|
def __init__(self, _osmContent):
|
||||||
|
self.osmContent = str(_osmContent)
|
||||||
|
self.nodeList = []
|
||||||
|
self.parseOsmContent()
|
||||||
|
|
||||||
|
def parseOsmContent(self):
|
||||||
|
lines = self.osmContent.split("\n")
|
||||||
|
|
||||||
|
wayLines = []
|
||||||
|
nodeLines = []
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if "<node" in line:
|
||||||
|
if "/>" in line:
|
||||||
|
try:
|
||||||
|
self.createNode(conn, [line])
|
||||||
|
except:
|
||||||
|
print("Node could not be inserted")
|
||||||
|
else:
|
||||||
|
nodeLines.append(line)
|
||||||
|
elif "</node>" in line:
|
||||||
|
try:
|
||||||
|
self.createNode(conn, nodeLines)
|
||||||
|
except:
|
||||||
|
print("Node could not be inserted")
|
||||||
|
nodeLines = []
|
||||||
|
elif len(nodeLines) > 0:
|
||||||
|
nodeLines.append(line)
|
||||||
|
|
||||||
|
elif "<way " in line:
|
||||||
|
wayLines.append(line)
|
||||||
|
elif "</way>" in line:
|
||||||
|
try:
|
||||||
|
#self.createWay(conn, wayLines)
|
||||||
|
except:
|
||||||
|
print("Way could not be inserted")
|
||||||
|
wayLines = []
|
||||||
|
elif len(wayLines) > 0:
|
||||||
|
wayLines.append(line)
|
||||||
|
|
||||||
|
def createNode(self, lines):
|
||||||
|
nodeId = ""
|
||||||
|
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if "<node" in line:
|
||||||
|
nodeId = str(line.split('id="')[1].split('"')[0])
|
||||||
|
nodeLon = str(line.split('lon="')[1].split('"')[0])
|
||||||
|
nodeLat = str(line.split('lat="')[1].split('"')[0])
|
||||||
|
nodeVersion = str(line.split('version="')[1].split('"')[0])
|
||||||
|
nodeTimestamp = str(line.split('timestamp="')[1].split('"')[0])
|
||||||
|
nodeChangeset = str(line.split('changeset="')[1].split('"')[0])
|
||||||
|
nodeUid = str(line.split('uid="')[1].split('"')[0])
|
||||||
|
nodeUser = str(line.split('user="')[1].split('"')[0])
|
||||||
|
|
||||||
|
n = Node
|
||||||
|
cur.execute('INSERT INTO nodes("id", "lon", "lat", "version", "timestamp", "changeset", "uid", "user") VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
|
(nodeId, nodeLon, nodeLat, nodeVersion, nodeTimestamp, nodeChangeset, nodeUid, nodeUser))
|
||||||
|
|
||||||
|
elif '<tag ' in line:
|
||||||
|
print("HALLO")
|
||||||
|
key = str(line.split('k="')[1].split('"')[0])
|
||||||
|
value = str(line.split('v="')[1].split('"')[0])
|
||||||
|
cur.execute('INSERT INTO node_tags("nodeId", "key", "value") VALUES (?,?,?)', (nodeId, key, value))
|
||||||
Reference in New Issue
Block a user