convert_u_vertex.py 1.13 KB
import csv, sqlite3

con = sqlite3.connect("database2.db")
cur = con.cursor()

suffix = ["LN","LS","R","LE"]
	
fin = open("i.csv", "rt")
for line in fin:
	number = int(line)
	if(number >= 4000 and number <= 4057):
		ins = "'" + line
		ins = ins.replace('\n', '')
		ins = ins + "_"
		if(number >= 4000 and number < 4022):
			ins = ins + suffix[0] + "'"
		elif(number >= 4022 and number < 4027):
			ins = ins + suffix[1] + "'"
		elif(number >= 4027 and number < 4046):
			ins = ins + suffix[2] + "'"
		elif(number >= 4046 and number < 4057):
			ins = ins + suffix[3] + "'"
		else:
			ins = ins + suffix[1] + "'"
		
		cur.execute("SELECT internal FROM ug_ids WHERE external LIKE "+ins+";");

		ugid = cur.fetchall()

		print("% s" % ugid[0] + ",")
		
	elif '_' in line:
		ins = "'" + line
		ins = ins.replace('\n', '\'')
		cur.execute("SELECT internal FROM ug_ids WHERE external LIKE "+ins+";");
		ugid = cur.fetchall()
		print("% s" % ugid[0] + ",")
	elif '-1' in line:
		print("-1,")
	else:
		cur.execute("SELECT internal FROM ug_ids WHERE external = "+line+";")
		ugid = cur.fetchall()
		print("% s" % ugid[0] + ",")



con.commit()
con.close()
fin.close()