Guest User

Untitled

a guest
Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # -*- coding: utf-8 -*-
  3. require 'json'
  4. require 'net/http'
  5. require 'pp'
  6. require 'Time'
  7. require 'uri'
  8. require 'parseconfig'
  9.  
  10. def getResponse(url)
  11.  
  12. http = Net::HTTP.new("api.flickr.com",80)
  13.  
  14. request = Net::HTTP::Get.new(url)
  15. resp = http.request(request)
  16. if resp.code != "200"
  17. $stderr.puts "Error: #{resp.code} from:#{url}"
  18. raise JSON::ParserError # This is a kludge. Should return a proper exception instead!
  19. end
  20.  
  21. result = JSON.parse(resp.body)
  22. return result
  23. end
  24.  
  25. def getPlaceInfo(woe_id, index, name)
  26. flickr_config = ParseConfig.new('flickr.conf').params
  27. api_key = flickr_config['api_key']
  28. info_url = "/services/rest/?method=flickr.places.getChildrenWithPhotosPublic&api_key="+api_key+
  29. "&format=json&nojsoncallback=1&content_type="+
  30. "&woe_id="+woe_id
  31. $stderr.printf("info url:%s\n", info_url)
  32. i = getResponse(info_url)
  33. $stderr.printf("woeid:%s has %s places\n", name,i["places"]["total"])
  34.  
  35. print JSON.generate(i), "\n"
  36. i["places"]["place"].each { |place|$stderr.printf("place name:%s\n",place["_content"]) }
  37.  
  38. end
  39.  
  40. getPlaceInfo("9807",0,"Vancouver")
  41. getPlaceInfo("2487956",1,"San Francisco")
  42. getPlaceInfo("2459115",2,"NYC")
  43. getPlaceInfo("727232",3,"Amsterdam")
  44. getPlaceInfo("2475687",4,"Portland,OR")
  45. getPlaceInfo("2345496",5,"Berlin")
  46. getPlaceInfo("615702",6,"Paris")
  47. getPlaceInfo("44418",7,"London")
  48. getPlaceInfo("20070333", 8,"Taipei")
  49. getPlaceInfo("2151330", 9,"Beijing")
  50. getPlaceInfo("2151849", 10,"Shanghai")
  51. getPlaceInfo("12581062", 11,"Rio de Janeiro")
  52. getPlaceInfo("29375205",12,"Toronto")
  53. getPlaceInfo("2379574",13,"Chicago")
  54. getPlaceInfo("2490383",14,"Seattle")
  55. getPlaceInfo("2442047",15,"Los Angeles")
  56. getPlaceInfo("1118370",16,"Tokyo")
  57. getPlaceInfo("3534",17,"Montréal")
Add Comment
Please, Sign In to add comment