Pontifications

with-outliers-Chinatown-instagram-vancouver-2015-average-colour-overplotted

  • 2. So I wrote some code called remove-outliers-chinatown.rb[1] to remove anything that isn’t in woeid 91977405 because apparently there’s another woeid for another Vancouver Chinatown :-) (there is only one Chinatown!). This other wooed is a subwoeid of Strathcona.
  • 3. Here’s how I invoked it
chinatown_ig_van_2015 <-
all_neighbourhoods_ig_van_2015 %>%
filter(neighbourhood == "Chinatown")
chinatown_ig_van_2015 <-
all_neighbourhoods_ig_van_2015 %>%
filter(neighbourhood == "Chinatown")
cat \
WITH_NEIGHBOURHOOD_CSV_FILES_FOR_GGMAP_2015/CHROMELESS_MAPS_FOR_EACH_NEIGHBOURHOOD/with_outliers_chinatown_ig_van_2015.csv |\
 ./remove-outliers-chinatown.rb \
 > WITH_NEIGHBOURHOOD_CSV_FILES_FOR_GGMAP_2015/CHROMELESS_MAPS_FOR_EACH_NEIGHBOURHOOD/with__91977405_chinatown_ig_van_2015.csv \
 2>stderr.with__91977405_chinatown_ig_van_2015.txt
  • 4. Next up is plotting: with\__91977405_chinatown_ig_van_2015.csv (which due to a bug or a network timeout only goes from Jan 1, 2015 until December 5, 2015)

[1] remove-outliers-chinatown.rb

#!/usr/bin/env ruby
require 'rubygems'
require 'parseconfig'
require 'pp'
require 'typhoeus'
require 'json'

def getFlickrResponse(url, params)
  url = "https://api.flickr.com/" + url
  result = Typhoeus::Request.get(url,
             :params => params )
  return JSON.parse(result.body)
end

flickr_config = ParseConfig.new('flickr.conf').params
api_key = flickr_config['api_key']

# pp api_key

first = true
ARGF.each do |line|
  if first
    first = false
    printf("colour,lat,long,date,neighbourhood\n")
    next
  end
  averagecolour_lat_lon_date = line.chomp
  fields = averagecolour_lat_lon_date.split(',')
  lat = fields[1]
  lon = fields[2]

  base_url = "services/rest/"
  
  url_params = {:method => "flickr.places.findByLatLon",
      :api_key => api_key,
      :format => "json",
      :nojsoncallback => "1",
      :lat => lat,
      :lon => lon
    }
  woeid_rsp = getFlickrResponse(base_url, url_params)
  PP::pp(woeid_rsp, $stderr)
  
  place = woeid_rsp["places"]["place"]
  if place == []
    $stderr.printf("place is nil, skipping\n")
    next
  end
  
  woeid =  place[0]["woeid"]
  if woeid != "91977405"
    $stderr.printf("WOEID is %s, SKIPPING\n", woeid)
    next
  end
  puts(line)
  sleep(0.5)
  
end

Leave a comment on github