-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add clear cmd - Add list cmd - Add version cmd - Add sync cmd
- Loading branch information
Showing
11 changed files
with
456 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Example user template template | ||
### Example user template | ||
|
||
credentials.json | ||
token.json | ||
|
||
# IntelliJ project files | ||
.idea | ||
*.iml | ||
out | ||
gen | ||
### Go template | ||
# Binaries for programs and plugins | ||
epical | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,33 @@ | ||
# epical | ||
Epitech calendar | ||
# EpiCal | ||
A simple to synchronize your Epitech events with Google calendar. | ||
|
||
# Requirements | ||
|
||
To run this script you have to use your Epitech auto login token which can be found [here](https://intra.epitech.eu/admin/autolog). | ||
The URL is of the form `https://intra.epitech.eu/auth-XXX...` | ||
The token used by the script is only the right part of the URL after the `auth-` part. | ||
|
||
## Installation | ||
```go | ||
go build . | ||
``` | ||
|
||
## Commands | ||
|
||
### Sync | ||
A command to synchronize Epitech events with your Google calendar. | ||
```go | ||
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN sync | ||
``` | ||
|
||
### List | ||
A command to list Epitech events. | ||
```go | ||
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN list | ||
``` | ||
|
||
### Clear | ||
Delete all events previously created by EpiCal. | ||
```go | ||
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN clear | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ShellBear/epical/pkg/epical" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var clearCmd = &cobra.Command{ | ||
Use: "clear", | ||
Short: "Clear all calendar events generated by Epical", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
epical.ClearEvents(cmd.Flag("credentials").Value.String()) | ||
fmt.Println("Successfully cleared calendar events.") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var ( | ||
EpitechToken string | ||
Credentials string | ||
) | ||
|
||
var cli = &cobra.Command{ | ||
Use: "epical", | ||
Short: "Synchronize your Epitech's events with Google calendar", | ||
Long: "A fast and simple way to sync your Epitech calendar with Google.\n" + | ||
"Complete documentation is available at https://github.com/shellbear/epical", | ||
} | ||
|
||
func Execute() { | ||
cli.PersistentFlags().StringVarP(&EpitechToken, "token", "t", "", "Epitech API Token") | ||
cli.PersistentFlags().StringVarP(&Credentials, "credentials", "c", "credentials.json", "Google API credentials") | ||
|
||
cli.MarkPersistentFlagRequired("token") | ||
|
||
if err := cli.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cli.AddCommand(versionCmd) | ||
cli.AddCommand(clearCmd) | ||
cli.AddCommand(listCmd) | ||
cli.AddCommand(syncCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/ShellBear/epical/pkg/epical" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all upcoming Epitech events", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
epical.ListEvents(cmd.Flag("token").Value.String()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ShellBear/epical/pkg/epical" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var syncCmd = &cobra.Command{ | ||
Use: "sync", | ||
Short: "Sync all upcoming Epitech events to Google calendar", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
epical.SyncCalendar(cmd.Flag("credentials").Value.String(), cmd.Flag("token").Value.String()) | ||
fmt.Println("Successfully synchronized Epitech events to Google calendar.") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ShellBear/epical/pkg/epical" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of Epical", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Printf("Epical v%s\n", epical.VERSION) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module github.com/ShellBear/epical | ||
|
||
go 1.12 | ||
|
||
require ( | ||
cloud.google.com/go v0.45.0 // indirect | ||
github.com/google/go-cmp v0.3.1 // indirect | ||
github.com/hashicorp/golang-lru v0.5.3 // indirect | ||
github.com/spf13/cobra v0.0.5 | ||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 | ||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 | ||
golang.org/x/sys v0.0.0-20190904005037-43c01164e931 // indirect | ||
google.golang.org/api v0.9.0 | ||
google.golang.org/appengine v1.6.2 // indirect | ||
google.golang.org/grpc v1.23.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/ShellBear/epical/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package epical | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
const ( | ||
CALENDAR_NAME = "EpiCal" | ||
VERSION = "0.1" | ||
) | ||
|
||
func ListEvents(epitechToken string) { | ||
data, err := GetRegisteredEvents(epitechToken) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(data) == 0 { | ||
fmt.Println("No upcoming events found.") | ||
} else { | ||
for _, evt := range data { | ||
fmt.Printf("%v (%v-%v)\n", evt.ActiTitle, evt.Start, evt.End) | ||
} | ||
} | ||
} | ||
|
||
func ClearEvents(credentialsPath string) { | ||
svc, err := GetGoogleCalendarService(credentialsPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
cal, err := GetGoogleCalendarByName(svc, CALENDAR_NAME) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if cal != nil { | ||
events, err := svc.Events.List(cal.Id).Do() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, evt := range events.Items { | ||
err = svc.Events.Delete(cal.Id, evt.Id).Do() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
err = svc.Calendars.Delete(cal.Id).Do() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func SyncCalendar(credentialsPath, token string) { | ||
data, err := GetRegisteredEvents(token) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Found %d events to synchronize.\n", len(data)) | ||
|
||
svc, err := GetGoogleCalendarService(credentialsPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ClearEvents(credentialsPath) | ||
fmt.Println("Cleared old calendar events.") | ||
|
||
cal, err := GetOrCreateGoogleCalendar(svc, CALENDAR_NAME) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(data) == 0 { | ||
fmt.Println("There is no upcoming Epitech event.") | ||
} else { | ||
for _, c := range data { | ||
newEvt, err := NewGoogleCalendarEvent(&c) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
evt, err := svc.Events.Insert(cal.Id, newEvt).Do() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("Created event", evt.Summary) | ||
} | ||
} | ||
} |