annotate calsync/mongoclient/mongoclient.go @ 51:a9b720445bcf

now roughly syncs cals and events to mongodb, one time
author drewp@bigasterisk.com
date Mon, 19 Aug 2024 14:42:27 -0700
parents dade5bbd02e3
children 1f84bd5ce8e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
1 package mongoclient
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 "context"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
5 "log"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
6 "time"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
7
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
8 "go.mongodb.org/mongo-driver/mongo"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
9 "go.mongodb.org/mongo-driver/mongo/options"
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 type MongoClient struct {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
13 ctx context.Context
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
14 client *mongo.Client
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
15 db *mongo.Database
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
16 calsCollection *mongo.Collection
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
17 eventsCollection *mongo.Collection
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 // docs in eventsCollection
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
21 type MongoEvent struct {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
22 // e.g.
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 // "_id" : "http://bigasterisk.com/calendar/08s5m1_20140929T030000Z",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
25 // "htmlLink" : "https://www.google.com/calendar/event?eid=MDhz",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
26 // "title" : "meeting",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
27 // "feedId" : "drewpca@gmail.com",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
28 // "feedTitle" : "drewpca@gmail.com",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
29 // "endTimeUnspecified" : false,
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
30 // "start" : "2014-09-28T20:00:00-07:00",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
31 // "startDate" : "2014-09-28",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
32 // "startTime" : ISODate("2014-09-29T03:00:00Z"),
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
33 // "end" : "2014-09-28T21:00:00-07:00",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
34 // "endDate" : "2014-09-28",
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
35 // "endTime" : ISODate("2014-09-29T04:00:00Z")
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
36 // }
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
37
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
38 Url string `bson:"_id"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
39 GoogleId string `bson:"googleId"`
51
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 50
diff changeset
40 CalendarUrl string `bson:"calendarUrl"`
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
41 HtmlLink string `bson:"htmlLink"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
42 Title string `bson:"title"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
43 EndTimeUnspecified bool `bson:"endTimeUnspecified"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
44 Start string `bson:"start"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
45 StartDate string `bson:"startDate"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
46 StartTime time.Time `bson:"startTime"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
47 End string `bson:"end"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
48 EndDate string `bson:"endDate"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
49 EndTime time.Time `bson:"endTime"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
50 LastUpdated time.Time `bson:"lastUpdated"`
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
51 }
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
52
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
53 func New(ctx context.Context) (*MongoClient, error) {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
54 log.Println("todo: using fixed ip")
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
55 mclient, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://10.43.98.221:27017"))
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
56 if err != nil {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
57 return nil, err
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
58 }
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
59 db := mclient.Database("pim")
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
60 return &MongoClient{
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
61 ctx,
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
62 mclient,
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
63 db,
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
64 db.Collection("test_gcalendar_cals"),
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
65 db.Collection("test_gcalendar")},
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
66 nil
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
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
69 func (c *MongoClient) Close() {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
70 c.client.Disconnect(c.ctx)
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
71 }