Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- con = psycopg2.connect("dbname='osm' user='ubuntu' password='ubuntu' host='localhost'")
- cur = con.cursor()
- def delete_node(node_id):
- cur.execute("SELECT EXISTS(SELECT 1 FROM current_way_nodes WHERE node_id = %s);", (node_id,))
- exists = list(cur.fetchone())[0]
- if not exists:
- print('Deleting ' + str(node_id) + ' from current_node_tags')
- cur.execute("DELETE FROM current_node_tags WHERE node_id = %s;", (node_id,))
- cur.execute("DELETE FROM current_nodes WHERE id = %s;", (node_id,))
- else:
- cur.execute("DELETE FROM current_node_tags WHERE node_id = %s;", (node_id,))
- cur.execute("SELECT EXISTS(SELECT 1 FROM way_nodes WHERE node_id = %s);", (node_id,))
- exists = list(cur.fetchone())[0]
- if not exists:
- print('Deleting ' + str(node_id) + ' from node_tags')
- cur.execute("DELETE FROM node_tags WHERE node_id = %s;", (node_id,))
- cur.execute("DELETE FROM nodes WHERE node_id = %s;", (node_id,))
- else:
- cur.execute("DELETE FROM node_tags WHERE node_id = %s;", (node_id,))
- file = open('typeReduction.txt', 'r')
- cnt = 0
- for id in file:
- cnt += 1
- print(id)
- print(cnt)
- cur.execute("SELECT node_id from current_node_tags WHERE v = %s;", (str(id).strip(),))
- rows = cur.fetchall()
- for row in rows:
- print(row[0])
- # file1.write(str(row[0]) + '\n')
- delete_node(str(row[0]))
- # cur.execute("DELETE FROM node_tags WHERE node_id = %s;", (str(row[0]),))
- # cur.execute("DELETE FROM nodes WHERE node_id = %s;", (str(row[0]),))
- con.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement