Mercurial > code > home > repos > gcalendarwatch
annotate calsync/convert/convert.go @ 49:2991c1166852
start calsync in go. Calendar list seems to sync
author | drewp@bigasterisk.com |
---|---|
date | Mon, 19 Aug 2024 13:25:03 -0700 |
parents | |
children | a9b720445bcf |
rev | line source |
---|---|
49
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
1 package convert |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
2 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
3 import ( |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
4 "net/url" |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
5 "time" |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
6 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
7 "bigasterisk.com/go/gcalendarwatch/gcalclient" |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
8 "bigasterisk.com/go/gcalendarwatch/mongoclient" |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
9 "google.golang.org/api/calendar/v3" |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
10 ) |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
11 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
12 func MongoCalFromGoogleCal(cal *calendar.CalendarListEntry) mongoclient.MongoCal { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
13 return mongoclient.MongoCal{ |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
14 Url: gcalclient.MakeCalUrl(cal.Id), |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
15 GoogleId: cal.Id, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
16 Summary: cal.Summary, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
17 Description: cal.Description, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
18 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
19 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
20 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
21 func MakeEventUrl(calUrl string, evId string) string { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
22 return calUrl + "/" + url.QueryEscape(evId) |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
23 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
24 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
25 func MakeEventUrl2(cal mongoclient.MongoCal, evId string) string { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
26 return MakeEventUrl3(cal.GoogleId, evId) |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
27 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
28 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
29 func MakeEventUrl3(googleCalId string, evId string) string { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
30 return MakeEventUrl("http://bigasterisk.com/calendar/"+ |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
31 url.QueryEscape(googleCalId), evId) |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
32 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
33 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
34 func MongoEventFromGoogleEvent2( |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
35 calUrl string, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
36 ev *gcalclient.CalendarEvent, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
37 now time.Time, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
38 ) mongoclient.MongoEvent { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
39 return mongoEventFromGoogleEvent(calUrl, ev, now) |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
40 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
41 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
42 func MongoEventFromGoogleEvent( |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
43 cal *calendar.CalendarListEntry, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
44 ev *gcalclient.CalendarEvent, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
45 now time.Time, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
46 ) mongoclient.MongoEvent { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
47 return mongoEventFromGoogleEvent(MakeEventUrl3(cal.Id, ev.Id), ev, now) |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
48 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
49 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
50 func mongoEventFromGoogleEvent(calUrl string, ev *gcalclient.CalendarEvent, now time.Time) mongoclient.MongoEvent { |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
51 return mongoclient.MongoEvent{ |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
52 Url: calUrl, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
53 GoogleId: ev.Event.Id, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
54 HtmlLink: ev.HtmlLink, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
55 Title: ev.Summary, //? |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
56 // FeedId : ev.Event.FeedId, // or calid? |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
57 // FeedTitle : ev.Event.FeedTitle, // /or what |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
58 EndTimeUnspecified: ev.Event.EndTimeUnspecified, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
59 // Start : ev.Start.DateTime, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
60 // StartDate : ev.Event.StartDate, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
61 // StartTime : ev.Event.StartTime, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
62 // End : ev.Event.End, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
63 // EndDate : ev.Event.EndDate, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
64 // EndTime : ev.Event.EndTime, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
65 LastUpdated: now, |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
66 } |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
67 |
2991c1166852
start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff
changeset
|
68 } |