Created
November 4, 2011 16:57
-
-
Save hackervera/1339843 to your computer and use it in GitHub Desktop.
geoloqi nerdout layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Copyright 2011 Tyler Gillies | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
#I have this running in a one minute cron | |
require 'nokogiri' | |
require 'typhoeus' | |
require 'redis' | |
require 'cgi' | |
redis = Redis.new | |
#RSS feed for category, can be anything | |
response = Typhoeus::Request.get("http://plancast.com/plan/listings?type=category&category_id=10544&scope=everywhere&_=1320084603278&feed=rss&key=iG6Sxa4m-Xp3OH1xlrC7g2jwNuTrm50HgLzWg8eIuOh2m7roN70MFgBVwRKZTw04ag03eWZBjJ59K4y--N19") | |
doc = Nokogiri::XML(response.body) | |
#uses redis for caching | |
ids = redis.smembers "plancast:ids" | |
doc.xpath("//item").each do |item| | |
title = item.xpath(".//title").text | |
cords = item.xpath(".//georss:point", "georss" => "http://www.georss.org/georss").text | |
lat, long = cords.split " " | |
id = item.xpath(".//guid").text | |
link = item.xpath(".//link").text | |
puts "Title: #{title}" | |
puts "Link: #{link}" | |
puts "Lat: #{lat}" | |
puts "Long #{long}" | |
puts "ID: #{id}" | |
redis.sadd "plancast:ids", id | |
url = "https://api.geoloqi.com/1/message/broadcast" | |
puts "url: #{url}" | |
unless ids.include? id | |
response = Typhoeus::Request.post(url, :params => {:layer_id => "1SC", :text => "#{title}", :latitude => lat, :longitude => long, :oauth_token => "INSERT_PERMANENT_OAUTH_TOKEN_HERE", :radius => 10000, :url => link}) | |
puts "gL response: #{response.body}" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment