user1724295
user1724295

Reputation:

Syntax Error when converting “time” from the Meetup API to a recognizable format

Using the code below, I'm saving Meetup events to my database but am unable to save the time due to Meetup's time format.

There are two other StackOverflow questions that cover this, but I got a Syntax Error when trying to implement them. Any suggestions would be greatly appreciated!

  1. Converting milliseconds to a date (jQuery/JS)

  2. How do I convert the "time" from the Meetup API to a recognizable format?

Meetup Event Time Format:

Code without converting timestamp:

require 'rubygems'
require 'json'
require 'net/http'

class MeetupController < ApplicationController

    respond_to :json
    $meetupRI = "http://api.meetup.com/2/open_events?status=upcoming&radius=25.0&category=2&and_text=False&limited_events=False&desc=False&offset=0&photo-host=public&format=json&zip=02903&page=20&sig_id=MYKEY"

    def getJobs
        if response.code == '200' then

            response = Net::HTTP.get_response(URI.parse($meetupRI))
            data = response.body
            parsed_response = JSON.parse(data)
            parsed_response["results"].each do |event|
                e = Event.new(:name => event["name"], :description => event["description"], :url => event["event_url"], :start_time => event["time"] )
                e.save
            end
        end
    end
end

Upvotes: 1

Views: 153

Answers (1)

mansilladev
mansilladev

Reputation: 988

I'd turn it into a date object like this:

DateTime.strptime(event['time'].to_s,'%Q')

Upvotes: 2

Related Questions