This repository has been archived by the owner on Jan 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipboy_places.py
164 lines (147 loc) · 5.3 KB
/
pipboy_places.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# RasPipBoy: A Pip-Boy 3000 implementation for Raspberry Pi
# Neal D Corbett, 2013
# Map Place management
import time, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, io, json
import config
# Google Places custom-search documentation:
# https://developers.google.com/places/documentation/search
# Place-types are listed here:
# https://developers.google.com/places/documentation/supported_types
placeTypeIconNames = {
'accounting':'office',
'airport':'military',
'amusement_park':'encampment',
'aquarium':'monument',
'art_gallery':'monument',
'atm':'vault',
'bakery':'factory',
'bank':'vault',
'bar':'ruins_urban',
'beauty_salon':'ruins_town',
'bicycle_store':'office',
'book_store':'ruins_urban',
'bowling_alley':'ruins_urban',
'bus_station':'metro',
'cafe':'ruins_urban',
'campground':'encampment',
'car_dealer':'office',
'car_rental':'office',
'car_repair':'factory',
'car_wash':'factory',
'casino':'vault',
'cemetery':'monument',
'church':'monument',
'city_hall':'monument',
'clothing_store':'ruins_urban',
'convenience_store':'ruins_urban',
'courthouse':'monument',
'dentist':'office',
'department_store':'city',
'doctor':'office',
'electrician':'ruins_town',
'electronics_store':'city',
'embassy':'monument',
'finance':'office',
'fire_station':'military',
'florist':'ruins_town',
'food':'settlement',
'funeral_home':'monument',
'furniture_store':'ruins_urban',
'gas_station':'settlement',
'general_contractor':'settlement',
'grocery_or_supermarket':'ruins_urban',
'gym':'ruins_urban',
'hair_care':'ruins_town',
'hardware_store':'ruins_town',
'health':'ruins_town',
'hindu_temple':'monument',
'home_goods_store':'ruins_urban',
'hospital':'monument',
'insurance_agency':'ruins_urban',
'jewelry_store':'ruins_urban',
'laundry':'ruins_town',
'lawyer':'ruins_urban',
'library':'monument',
'liquor_store':'ruins_town',
'local_government_office':'monument',
'locksmith':'ruins_town',
'lodging':'settlement',
'meal_delivery':'ruins_town',
'meal_takeaway':'settlement',
'mosque':'monument',
'movie_rental':'ruins_urban',
'movie_theater':'monument',
'moving_company':'ruins_town',
'museum':'monument',
'night_club':'cave',
'painter':'settlement',
'park':'natural_landmark',
'parking':'metro',
'pet_store':'ruins_urban',
'pharmacy':'ruins_town',
'physiotherapist':'office',
'place_of_worship':'monument',
'plumber':'ruins_town',
'police':'military',
'post_office':'office',
'real_estate_agency':'ruins_urban',
'restaurant':'settlement',
'rv_park':'encampment',
'school':'monument',
'shoe_store':'ruins_town',
'shopping_mall':'monument',
'spa':'cave',
'stadium':'encampment',
'storage':'factory',
'store':'office',
'subway_station':'metro',
'synagogue':'monument',
'taxi_stand':'metro',
'train_station':'metro',
'travel_agency':'ruins_urban',
'university':'monument',
'veterinary_care':'office',
'zoo':'monument',
'DEFAULT':'ruins_town',
}
# Gets list of up to 60 establishments in area:
def getPlaces(lat,lon,radius=2000,types='establishment'):
places = []
# These search-arguments will show the initial results-page:
pageArgs = "location=%s,%s&radius=%s&types=%s" %(lat,lon,radius,types)
pageNum = 0
while (pageArgs != None):
url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?%s&sensor=false&key=%s" %(pageArgs,config.gKey)
pageArgs = None
pageNum += 1
#print ("Page %s: %s" %(pageNum, url))
response = urllib.request.urlopen( url )
responseBody = response.read()
body = io.StringIO( responseBody )
result = json.load(body)
if 'results' in result:
#print ("Page results: %s" %(len(result['results'])))
for thisPlace in result['results']:
placeLoc = thisPlace['geometry']['location']
placeTypes = thisPlace['types']
# Get icon for place:
iconName = None
for thisType in placeTypes:
if (iconName == None):
if thisType in placeTypeIconNames:
iconName = placeTypeIconNames[thisType]
# Set default if name wasn't found:
if (iconName == None):
iconName = placeTypeIconNames['DEFAULT']
placeItem = {'name':thisPlace['name'],'lat':placeLoc['lat'],'lon':placeLoc['lng'],'icon':iconName} #,'types':placeTypes
places.append(placeItem)
print(placeItem)
# Set loop to download next page - there'll be up to 3 pages, of up to 20 results each:
if 'next_page_token' in result:
#print "Next page..."
# Set up argument to download next page:
pageArgs = "pagetoken=%s" %(result['next_page_token'])
# Pause, as Google delays enabling the next page:
time.sleep(2)
return places
#getPlaces(53.79420270000001,-1.5356686)