-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrest_fetch.rb
40 lines (19 loc) · 885 Bytes
/
rest_fetch.rb
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
require "json"
require "rest-client"
# def set_restaurant_score(district)
response = RestClient.get "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=45.523791,-73.599567&radius=1000&type=restaurant&key=AIzaSyCts7bn5lhpEAqj4ePBF3zjJkO9m6XSVZw"
results = JSON.parse(response)
last_page_token = results["next_page_token"]
restaurants = []
restaurants << results["results"]
while last_page_token != nil
sleep 2
response = RestClient.get "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=AIzaSyCts7bn5lhpEAqj4ePBF3zjJkO9m6XSVZw&pagetoken=#{last_page_token}"
results = JSON.parse(response)
last_page_token = results["next_page_token"]
restaurants << results["results"]
end
json_string = JSON.pretty_generate(restaurants)
# district.update()
# end
File.write("#{Time.now.to_i}_restaurant_seed.json", json_string)