I must admit I really need some help understanding how I can make my own parser for the Feed API so that I can support the module that I'm making. This could be very simple to those who know how to do this.

I need to make a parser for the Google Calendar API. I've figured out how to get back an ATOM feed from Google, all I need to do is write a function that will take the feed and parse it into an event.

Note: I don't want to do this through the available user interface of the Feed API. I want to do this behind the scenes and programatically.

Can someone hold my hand on this one. If necessary I we can talk it out in the #drupal chatroom on irc.

Comments

cosmicdreams’s picture

Sorry forgot to link
Here's my module: LINK

cosmicdreams’s picture

I've been able to dig deeper in to the code of Feed API. Here's what I understand so far:

I've been able to see that in order to use Feed API for my module I will have to write a parser that handles the incoming data the way I want. The existing atom parser will put data into the wrong fields, for example the title element of the calendar feed is really the name of that calendar. And the name of the event will be coming from the subtitle element. So I need to customize the parser.

Most of the existing atom parser I will only have to alter a little. Like how the parser handles entries. Basically what data goes where. I could easily write a new parser that handles things the way I want, but is that better than perhaps using the field mapper somehow. I'd rather reuse existing solutions than writing something new that does basically the same thing.

Let me know if there is a better way than what I'm planning. I'll report back later if I can get things to work.

alex_b’s picture

Title: Need help with making my own parser » Aggregating Google Calendar Events

This sounds like a job for the field element mapper.

* Mapping subtitle to node title: could be done with a very simple custom mapper that maps any text or number on feed to a simple node property like $node->title
* I guess you will want to map dates to date fields, there is a patch in the queue for this: http://drupal.org/project/issues/feedapi_mapper
* Note that the feed element mapper also allows defining a mapping on a per content type basis. This feature is not fully built out - e. g. it supports only standard RSS fields - but this can be easily extended.

What other feed elements do you want to aggregate to which node components? Does parser_simplepie expose all those elements or are there some that you can't find after the parsing process?

Alex

cosmicdreams’s picture

I haven't looking into simplepie much ( just the one that comes with PHP 5.2) and I haven't actually inspected the output of the parsers. From the code I can't find support for the incoming gd:who, gd:when, or gd:where tags coming for Google Calendar. Everything else I get in from Google Calendar seems to be supported by the atom parser.

Even the fact that $title is off could be acceptable since at the root level it defines the calendar it's coming from. There is another $title inside the entry tag that is intended to name the event. That's the one I care about.

In the end I'm looking for an automated way of importing the events from Google Calendar into the event table. This allows me to reuse the existing user interface with minor alterations and only have to work about syncing the event module and Google Calendar.

It seems like the mapper is for allowing an administrator to map an arbitrary feed to existing node types. I'm not really looking for dynamic way of mapping feed elements to node elements. I'll settle for a static set way, that I can hardcode.

alex_b’s picture

Component: Code » Code feedapi (core module)
Status: Active » Closed (fixed)

Closing after extended period of inactivity.