· 6 years ago · Jul 01, 2019, 07:02 PM
1import sqlite3
2from slugify import slugify
3from locationsharinglib import Service
4import datetime
5import geocode
6
7service = Service('location_sharing.cookies')
8for person in service.get_all_people():
9
10 print(geocode.decode(person.latitude, person.longitude))
11 print("--")
12 db = sqlite3.connect('devices/' + person.id + "_" + slugify(person.full_name) + '.db')
13 cursor = db.cursor()
14 cursor.execute('''
15 CREATE TABLE IF NOT EXISTS locations(
16 epoch FLOAT,
17 latitude FLOAT,
18 longitude FLOAT,
19 accuracy INTEGER
20 )
21 ''')
22 cursor.execute('''SELECT max(epoch) FROM locations''')
23 max_epoch = cursor.fetchall()[0][0]
24
25 if person.datetime.timestamp() > max_epoch:
26 db.execute('''INSERT INTO locations (epoch,latitude,longitude,accuracy) VALUES (?,?,?,?)''',
27 (person.datetime.timestamp(), person.latitude, person.longitude, person.accuracy))
28
29 db.commit()
30 db.close()