Repository navigation
Expand file tree
/
Copy pathimport.py
More file actions
65 lines (43 loc) · 1.51 KB
/
Copy pathimport.py
File metadata and controls
65 lines (43 loc) · 1.51 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sqlite3
import csv
import os
#PATHS = 'C:\Users\Adam\Dropbox\YRS\Hu-Map POI Dumps\\'
PATHS = '/home/mancub/Dev/maps/poi_files/'
DATABASE = '/home/mancub/Dev/maps/maps.db'
db = sqlite3.connect(DATABASE)
def insert_poi(lat, lng, icon, title, category):
db.execute('INSERT INTO points_of_interest ( lat, lng, icon_location, name, category ) values ( ?, ?, ?, ?, ? )', [lat, lng, icon, title, category])
def get_poi():
data = db.execute('SELECT * FROM points_of_interest LIMIT 20')
for row in data.fetchall():
print row
"""
@author Adam Ferguson <adam@fergie57@btinternet.com>
@description Parses POI files contained in the directory set above and adds it to the SQLite database
"""
def process_files():
location_filename=[]
for dirname, dirnames, filenames in os.walk(PATHS):
for filename in filenames:
location_filename.append(filename)
csv_list = []
for csv_file in location_filename:
locations = csv.reader(open(PATHS+csv_file, 'r+'), delimiter=",", quotechar='|')
for row in locations:
place_record = { 'lat':row[1],
'lng':row[0],
'type':csv_file[:-4]
}
csv_list.append(place_record)
return csv_list
"""
@author Adam Ferguson <fergie57@btinternet.com>
@description Inserts the POI data from the CSV files
"""
def process_formatted_list(formatted_list):
for row in formatted_list:
insert_poi(row['lat'],row['lng'], 'x', str(row['type']), 'x')
db.commit()
#formatted_list = process_files()
#process_formatted_list(formatted_list)
#get_poi()