Last active
June 8, 2019 07:36
-
-
Save ybenjo/b8ab1aa943416b9006c499f19deef9b0 to your computer and use it in GitHub Desktop.
converts foursquare's (dumped) check-ins data to ics file.
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
# coding: utf-8 | |
require 'json' | |
require 'time' | |
require 'digest/md5' | |
srand(0) | |
data = JSON.load(open("#{__dir__}/checkins.json").read) | |
output_file = "#{__dir__}/checkins.ics" | |
open(output_file, 'w'){|f| | |
header = <<"EOS" | |
BEGIN:VCALENDAR | |
PRODID: 4sq checkins | |
VERSION:2.0 | |
CALSCALE:GREGORIAN | |
METHOD:PUBLISH | |
X-WR-CALNAME:y_benjo | |
X-WR-TIMEZONE:Asia/Tokyo | |
BEGIN:VTIMEZONE | |
TZID:Asia/Tokyo | |
X-LIC-LOCATION:Asia/Tokyo | |
BEGIN:STANDARD | |
TZOFFSETFROM:+0900 | |
TZOFFSETTO:+0900 | |
TZNAME:JST | |
DTSTART:19700101T000000 | |
END:STANDARD | |
END:VTIMEZONE | |
EOS | |
f.puts header | |
data['items'].each do |elem| | |
next if elem['venue'].nil? | |
text = elem['shout'] | |
text.gsub!(/\n/, '') unless text.nil? | |
poi = elem['venue']['name'] | |
timestamp = elem['createdAt'].to_i | |
t = Time.at(timestamp) | |
t_str = t.gmtime.strftime("%Y%m%dT%H%M00Z") | |
f.puts 'BEGIN:VEVENT' | |
f.puts "DTSTART:#{t_str}" | |
f.puts "DTEND:#{t_str}" | |
f.puts "DTSTAMP:#{t_str}" | |
# generate random UID | |
uid = Digest::MD5.hexdigest(rand().to_s)[0...26] + '@google.com' | |
f.puts "UID:#{uid}" | |
f.puts "CREATED:#{t_str}" | |
f.puts "DESCRIPTION:#{text}" | |
f.puts "LAST-MODIFIED:#{t_str}" | |
f.puts 'LOCATION:' | |
f.puts 'SEQUENCE:0' | |
f.puts 'STATUS:CONFIRMED' | |
f.puts "SUMMARY:@ #{poi}" | |
f.puts 'TRANSP:OPAQUE' | |
f.puts 'END:VEVENT' | |
end | |
f.puts 'END:VCALENDAR' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment