-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpjs.py
47 lines (44 loc) · 1.31 KB
/
dumpjs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#coding: utf-8
import sqlite3
import json
import codecs
import sys
conn = sqlite3.connect('spider.sqlite')
cur = conn.cursor()
cur.execute('SELECT * FROM Results')
fhand = codecs.open('locations.js','w', 'utf-8')
fhand.write("myLocations = [\n")
count = 0
for row in cur :
lat = str(row[14])
lng = str(row[15])
if lat == 'NULL' or lat == 'NULL':continue
url = row[1]
title = row[2]
title = unicode(title).replace("'","\\'")
price = row[3]
zone = row[4]
cp = row[5]
pieces = row[6]
surface = row[7]
chambre = row[8]
metro1 = row[9]
metro1 = unicode(metro1).replace("'","\\'")
metro2 = row[10]
metro2 = unicode(metro2).replace("'","\\'")
metro3 = row[11]
metro3 = unicode(metro3).replace("'","\\'")
tel = row[12]
try :
count = count + 1
if count > 1 : fhand.write(",\n")
output = "["+lat+","+lng+", '"+url+"\', \'"+title+"\', \'"+price+"\', \'"+zone+"\', \'"+cp+"\', \'"+pieces+"\', \'"+surface+"\', \'"+chambre+"\', \'"+metro1+"\', \'"+metro2+"\', \'"+metro2+"\', \'"+metro3+"\', \'"+tel+"']"
fhand.write(output)
except:
print sys.exc_info,sys.exc_type
continue
fhand.write("\n];\n")
cur.close()
fhand.close()
print count, "records written to locations.js"
print "Open map.html to view the data in a browser"