Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # -*- coding: utf-8 -*-
- require 'json'
- require 'net/http'
- require 'pp'
- require 'Time'
- require 'uri'
- require 'parseconfig'
- def getResponse(url)
- http = Net::HTTP.new("api.flickr.com",80)
- request = Net::HTTP::Get.new(url)
- resp = http.request(request)
- if resp.code != "200"
- $stderr.puts "Error: #{resp.code} from:#{url}"
- raise JSON::ParserError # This is a kludge. Should return a proper exception instead!
- end
- result = JSON.parse(resp.body)
- return result
- end
- def getPlaceInfo(woe_id, index, name)
- flickr_config = ParseConfig.new('flickr.conf').params
- api_key = flickr_config['api_key']
- info_url = "/services/rest/?method=flickr.places.getChildrenWithPhotosPublic&api_key="+api_key+
- "&format=json&nojsoncallback=1&content_type="+
- "&woe_id="+woe_id
- $stderr.printf("info url:%s\n", info_url)
- i = getResponse(info_url)
- $stderr.printf("woeid:%s has %s places\n", name,i["places"]["total"])
- print JSON.generate(i), "\n"
- i["places"]["place"].each { |place|$stderr.printf("place name:%s\n",place["_content"]) }
- end
- getPlaceInfo("9807",0,"Vancouver")
- getPlaceInfo("2487956",1,"San Francisco")
- getPlaceInfo("2459115",2,"NYC")
- getPlaceInfo("727232",3,"Amsterdam")
- getPlaceInfo("2475687",4,"Portland,OR")
- getPlaceInfo("2345496",5,"Berlin")
- getPlaceInfo("615702",6,"Paris")
- getPlaceInfo("44418",7,"London")
- getPlaceInfo("20070333", 8,"Taipei")
- getPlaceInfo("2151330", 9,"Beijing")
- getPlaceInfo("2151849", 10,"Shanghai")
- getPlaceInfo("12581062", 11,"Rio de Janeiro")
- getPlaceInfo("29375205",12,"Toronto")
- getPlaceInfo("2379574",13,"Chicago")
- getPlaceInfo("2490383",14,"Seattle")
- getPlaceInfo("2442047",15,"Los Angeles")
- getPlaceInfo("1118370",16,"Tokyo")
- getPlaceInfo("3534",17,"Montréal")
Add Comment
Please, Sign In to add comment