Skip to content

Instantly share code, notes, and snippets.

@fofr
Created February 23, 2014 09:57
Show Gist options
  • Save fofr/9169410 to your computer and use it in GitHub Desktop.
Save fofr/9169410 to your computer and use it in GitHub Desktop.
Convert an RSS of Foursquare checkins into a SIFTTTER format
#!/usr/bin/ruby
# Convert an RSS of Foursquare checkins into a SIFTTTER format
# Find feed at https://foursquare.com/feeds/
# eg https://feeds.foursquare.com/history/YOUR_FEED_HERE.rss?count=COUNT
# SIFTTTER: http://craigeley.com/post/72565974459/sifttter-an-ifttt-to-day-one-logger
require 'rubygems'
require 'simple-rss'
require 'open-uri'
output_path = 'foursquare.md'
saved_rss = 'feed.rss'
username = ''
entries = []
SimpleRSS.item_tags << :"georss:point"
response = SimpleRSS.parse open(saved_rss)
class Entry
def parse(item)
@title = item[:title]
@description = item[:description].gsub("@ #{@title}", '').strip()
@coordinates = item[:georss_point].split(' ').join(',')
@map = "https://www.google.co.uk/maps/place/#{@coordinates}"
@checkin_url = "https://foursquare.com/#{username}/checkin/#{item[:guid]}"
@date = item[:pubDate].strftime('%B %d, %Y at %I:%M%p')
end
def render
"- #{@date} - #{@title}#{" #{@description}" if [email protected]?} [Map](#{@map}) | [4SQ](#{@checkin_url}) @done\n"
end
end
def read_file(file)
f = File.open(file.strip, encoding: 'UTF-8')
lines = f.read
f.close
lines
end
response.items.each do |item|
entry = Entry.new
entry.parse(item)
entries << entry
end
fh = File.new(File.expand_path(output_path),'w+')
fh.puts entries.map {|entry| entry.render}
fh.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment