|
1 | 1 | parser = require 'xml2json' |
2 | 2 | rest = require 'restler' |
3 | 3 | date = require 'date-utils' |
4 | | -_date = require 'underscore.date' |
| 4 | +moment = require 'moment' |
| 5 | +ical = require 'ical' |
5 | 6 |
|
6 | 7 | parseFeed = (feed) -> |
7 | 8 | JSON.parse(parser.toJson(feed)).feed.entry |
8 | 9 |
|
9 | 10 | messageFeed = 'http://groups.google.com/group/kc-nodejs/feed/atom_v1_0_topics.xml' |
10 | | -eventFeed = 'http://www.google.com/calendar/feeds/nodekc.org_e8lg6hesldeld1utui23ebpg7k%40group.calendar.google.com/public/basic' |
| 11 | +eventFeed = 'http://www.google.com/calendar/ical/nodekc.org_e8lg6hesldeld1utui23ebpg7k%40group.calendar.google.com/public/basic.ics' |
11 | 12 | twitterFeed = 'http://search.twitter.com/search.json?q=%40nodekc' |
12 | 13 |
|
13 | 14 | lastMessageFetchResult = {} |
14 | 15 | lastEventFetchResult = {} |
15 | 16 | lastTwitterFetchResult = {} |
16 | 17 |
|
| 18 | +determineDate = (start, end) -> |
| 19 | + start = moment(new Date start) |
| 20 | + end = moment(new Date end) |
| 21 | + date = start.format('dddd, MMM, Do') |
| 22 | + |
| 23 | + return date if start.diff(end, 'days') == -1 |
| 24 | + |
| 25 | + date + start.format(' h:mma') + " for " + start.from(end, true) |
| 26 | + |
| 27 | + |
17 | 28 | striphtml = (value) -> |
18 | 29 | value.replace(/<(?:.|\n)*?>/gm, ' ') |
19 | 30 |
|
20 | 31 | timeAgo = (date) -> |
21 | | - _date(new Date(date)).fromNow() |
| 32 | + moment(new Date(date)).fromNow() |
22 | 33 |
|
23 | 34 | formatContent = (content) -> |
24 | 35 | content = striphtml(content).trim() |
@@ -61,16 +72,16 @@ fetchEvents = (cb) -> |
61 | 72 | if lastEventFetchResult.on? and lastEventFetchResult.on > (new Date).addMinutes(-1) |
62 | 73 | cb lastEventFetchResult.value |
63 | 74 | return |
| 75 | + |
| 76 | + ical.fromURL eventFeed, {}, (err, calendar) -> |
| 77 | + console.log calendar |
| 78 | + events = for k,v of calendar |
| 79 | + {title: v.summary, location: v.location, details: v.description, when: determineDate v.start, v.end } |
| 80 | + console.log events |
| 81 | + lastEventFetchResult.value = events |
| 82 | + lastEventFetchResult.on = new Date |
64 | 83 |
|
65 | | - rest.get(eventFeed).on('complete', (data) -> |
66 | | - events = for x in parseFeed data |
67 | | - { title: x.title.$t, when: striphtml(x.summary.$t), url: x.id } |
68 | | - |
69 | | - lastEventFetchResult.value = events |
70 | | - lastEventFetchResult.on = new Date |
71 | | - |
72 | | - cb events |
73 | | - ) |
| 84 | + cb events |
74 | 85 |
|
75 | 86 | module.exports = { |
76 | 87 | load: (keys...) -> |
|
0 commit comments