-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeder.py
More file actions
56 lines (49 loc) · 2.07 KB
/
seeder.py
File metadata and controls
56 lines (49 loc) · 2.07 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
# seeder.py by Noah Krause
import google_streetview.api
import random
import os
import sqlite3
from time import sleep, time
def create_connection():
conn = None
project_dir = os.path.dirname(os.path.abspath(__file__))
database_file = "{}".format(os.path.join(project_dir, "database.db"))
try:
conn = sqlite3.connect(database_file)
except Exception as e:
print(e)
cur = conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS street_images (id INTEGER PRIMARY KEY AUTOINCREMENT, latitude VARCHAR(255) NOT NULL, longitude VARCHAR(255) NOT NULL, file_name VARCHAR(255) NOT NULL, contains_litter TINYINT(1) NOT NULL DEFAULT 0, evaluated_filename VARCHAR(255) DEFAULT NULL);")
return conn
def insert_file(conn, latitude, longitude, file_name):
cur = conn.cursor()
cur.execute("INSERT INTO street_images (latitude, longitude, file_name) VALUES (?,?,?);", (latitude, longitude, file_name))
lastrowid = cur.lastrowid
print(f"Inserted id={lastrowid} lat={latitude} lon={longitude} file_name={file_name}")
def seed(conn, topLeft, bottomRight):
params = [{
'size': '960x540',
'location': 'temp',
'heading': '270',
'pitch': '-0.76',
'key': ""
}]
for _ in range(1000):
latitude = str(random.uniform(topLeft[0], bottomRight[0]))
longitude = str(random.uniform(topLeft[1], bottomRight[1]))
file_name = str(time()) + ".jpg"
params[0]['location'] = str(random.uniform(topLeft[0], bottomRight[0])) + ',' + str(random.uniform(topLeft[1], bottomRight[1]))
results = google_streetview.api.results(params)
results.download_links('photos')
sleep(1.2)
if (results.metadata[0]['status'] == "OK"):
os.rename("photos/gsv_0.jpg", "photos/" + file_name)
insert_file(conn, latitude, longitude, file_name)
if __name__ == "__main__":
# lat, lon
topLeft = [29.440235, -98.503513]
bottomRight = [29.410889, -98.481520]
conn = create_connection()
with conn:
seed(conn, topLeft, bottomRight)
conn.commit()