Skip to content

Commit

Permalink
Remove dropbox and local sync option
Browse files Browse the repository at this point in the history
  • Loading branch information
charlieegan3 committed Sep 10, 2021
1 parent b0cd5b8 commit 1d056c5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 317 deletions.
59 changes: 9 additions & 50 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,19 @@ package cmd

import (
"log"
"os"

dbx "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
air "github.com/mehanizm/airtable"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/charlieegan3/airtable-contacts/pkg/airtable"
"github.com/charlieegan3/airtable-contacts/pkg/carddav"
"github.com/charlieegan3/airtable-contacts/pkg/dropbox"
"github.com/charlieegan3/airtable-contacts/pkg/vcard"
)

var syncDropbox, syncCardDAV, syncFile bool

// syncCmd represents the sync command
var syncCmd = &cobra.Command{
Use: "sync",
Short: "download data from airtable and upload to dropbox",
Short: "download data from airtable and upload to carddav server",
Run: func(cmd *cobra.Command, args []string) {
// get the latest data
airtableClient := air.NewClient(viper.GetString("airtable.key"))
Expand All @@ -50,54 +43,20 @@ var syncCmd = &cobra.Command{
log.Fatalf("failed to download contacts: %s", err)
}

// generate string for all contacts
vcardString, err := vcard.Generate(
records,
viper.GetBool("vcard.use_v3"),
viper.GetInt("vcard.photo.size"),
"",
)
if err != nil {
log.Fatal(err)
}

if syncCardDAV {
cardDAVClient := carddav.Client{
URL: viper.GetString("carddav.serverURL"),
User: viper.GetString("carddav.user"),
Password: viper.GetString("carddav.password"),
}

// records passed as vcard sync is done on per contact basis
err := carddav.Sync(cardDAVClient, records)
if err != nil {
log.Fatal(err)
}
cardDAVClient := carddav.Client{
URL: viper.GetString("carddav.serverURL"),
User: viper.GetString("carddav.user"),
Password: viper.GetString("carddav.password"),
}
if syncDropbox {
dropboxClient := files.New(dbx.Config{
Token: viper.GetString("dropbox.token"),
LogLevel: dbx.LogOff,
})
dropbox.Upload(dropboxClient, viper.GetString("dropbox.path"), []byte(vcardString))
}
if syncFile {
outputPath := viper.GetString("local.outputPath")
if outputPath == "" {
outputPath = "output.vcard"
}

err = os.WriteFile(outputPath, []byte(vcardString), 0644)
if err != nil {
log.Fatal(err)
}
// records passed as vcard sync is done on per contact basis
err = carddav.Sync(cardDAVClient, records)
if err != nil {
log.Fatalf("failed to upload to carddav: %s", err)
}
},
}

func init() {
syncCmd.Flags().BoolVar(&syncDropbox, "dropbox", false, "if set, dropbox will be synced")
syncCmd.Flags().BoolVar(&syncCardDAV, "carddav", false, "if set, carddav will be synced")
syncCmd.Flags().BoolVar(&syncFile, "file", false, "if set, local will saved at the path set in config, default: output.vcard")
rootCmd.AddCommand(syncCmd)
}
35 changes: 13 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@ module github.com/charlieegan3/airtable-contacts
go 1.16

require (
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect
github.com/antchfx/xmlquery v1.3.6 // indirect
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/charlieegan3/special-days v0.0.0-20210701231319-175bc74510e3 // indirect
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/d4l3k/messagediff v1.2.1 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.1 // indirect
github.com/emersion/go-vcard v0.0.0-20210521075357-3445b9171995 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/gregdel/pushover v1.1.0 // indirect
github.com/maxatome/go-testdeep v1.10.0 // indirect
github.com/mehanizm/airtable v0.2.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/antchfx/xmlquery v1.3.6
github.com/cenkalti/backoff/v4 v4.1.1
github.com/charlieegan3/special-days v0.0.0-20210701231319-175bc74510e3
github.com/disintegration/imaging v1.6.2
github.com/emersion/go-vcard v0.0.0-20210521075357-3445b9171995
github.com/gregdel/pushover v1.1.0
github.com/maxatome/go-testdeep v1.10.0
github.com/mehanizm/airtable v0.2.4
github.com/pkg/errors v0.9.1
github.com/sergi/go-diff v1.2.0 // indirect
github.com/spf13/cobra v1.1.3 // indirect
github.com/spf13/viper v1.7.0 // indirect
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.0
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
gopkg.in/d4l3k/messagediff.v1 v1.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
)

0 comments on commit 1d056c5

Please sign in to comment.