SHARE
TWEET

Untitled

a guest May 27th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import psycopg2
  2.  
  3. con = psycopg2.connect("dbname='osm' user='ubuntu' password='ubuntu' host='localhost'")
  4. cur = con.cursor()
  5.  
  6.  
  7. def delete_node(node_id):
  8.     cur.execute("SELECT EXISTS(SELECT 1 FROM current_way_nodes WHERE node_id = %s);", (node_id,))
  9.     exists = list(cur.fetchone())[0]
  10.     if not exists:
  11.         print('Deleting ' + str(node_id) + ' from current_node_tags')
  12.         cur.execute("DELETE FROM current_node_tags WHERE node_id = %s;", (node_id,))
  13.         cur.execute("DELETE FROM current_nodes WHERE id = %s;", (node_id,))
  14.     else:
  15.         cur.execute("DELETE FROM current_node_tags WHERE node_id = %s;", (node_id,))
  16.  
  17.     cur.execute("SELECT EXISTS(SELECT 1 FROM way_nodes WHERE node_id = %s);", (node_id,))
  18.     exists = list(cur.fetchone())[0]
  19.     if not exists:
  20.         print('Deleting ' + str(node_id) + ' from node_tags')
  21.         cur.execute("DELETE FROM node_tags WHERE node_id = %s;", (node_id,))
  22.         cur.execute("DELETE FROM nodes WHERE node_id = %s;", (node_id,))
  23.     else:
  24.         cur.execute("DELETE FROM node_tags WHERE node_id = %s;", (node_id,))
  25.  
  26.  
  27. file = open('typeReduction.txt', 'r')
  28. cnt = 0
  29. for id in file:
  30.     cnt += 1
  31.     print(id)
  32.     print(cnt)
  33.     cur.execute("SELECT node_id from current_node_tags WHERE v = %s;", (str(id).strip(),))
  34.     rows = cur.fetchall()
  35.     for row in rows:
  36.         print(row[0])
  37.         # file1.write(str(row[0]) + '\n')
  38.         delete_node(str(row[0]))
  39.         # cur.execute("DELETE FROM node_tags WHERE node_id = %s;", (str(row[0]),))
  40.         # cur.execute("DELETE FROM nodes WHERE node_id = %s;", (str(row[0]),))
  41.         con.commit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top