Skip to content

Commit

Permalink
- Add vendors dependencies
Browse files Browse the repository at this point in the history
- Improve list cmd
- Add required token flag to list and sync cmd
  • Loading branch information
shellbear committed Sep 5, 2019
1 parent 9272b4c commit 79c71b8
Show file tree
Hide file tree
Showing 746 changed files with 383,117 additions and 11 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
# EpiCal
A simple to synchronize your Epitech events with Google calendar.
A simple tool to synchronize your Epitech events with Google calendar.

# Requirements

#### Epitech token
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.

#### Google calendar credentials

You have to enable the Google Calendar API for your account.
You can follow the [Google developer QuickStart](https://developers.google.com/calendar/quickstart/go) and click **ENABLE THE GOOGLE CALENDAR API** button.
Then in the resulting dialog click **DOWNLOAD CLIENT CONFIGURATION** and save the file credentials.json to your working directory.

## Installation
```go
You have to install
```bash
go build .
```

## Commands

### Sync
A command to synchronize Epitech events with your Google calendar.
```go
```bash
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN sync
```

### List
A command to list Epitech events.
```go
```bash
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN list
```

### Clear
Delete all events previously created by EpiCal.
```go
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN clear
```
```bash
./epical clear
```

## Options

#### Credentials

You can specify the Google Calendar API `credentials.json` file path using the `--credentials` or `-c` option.

```bash
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN --credentials ~/credentials.json sync
```
8 changes: 5 additions & 3 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ var cli = &cobra.Command{
}

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() {
listCmd.PersistentFlags().StringVarP(&EpitechToken, "token", "t", "", "Epitech API Token")
listCmd.MarkPersistentFlagRequired("token")
syncCmd.PersistentFlags().StringVarP(&EpitechToken, "token", "t", "", "Epitech API Token")
syncCmd.MarkPersistentFlagRequired("token")

cli.AddCommand(versionCmd)
cli.AddCommand(clearCmd)
cli.AddCommand(listCmd)
Expand Down
17 changes: 16 additions & 1 deletion pkg/epical/epical.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package epical
import (
"fmt"
"log"
"os"
"strings"
"text/tabwriter"
)

const (
Expand All @@ -16,13 +19,25 @@ func ListEvents(epitechToken string) {
log.Fatal(err)
}

writer := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', tabwriter.AlignRight)
fmt.Fprintln(writer, "NAME\tSTART\tEND\tROOM")

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)
rdv, valid := evt.RdvGroupRegistered.(string)

if valid {
parts := strings.Split(rdv, "|")
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\n", evt.ActiTitle, parts[0], parts[1], evt.Room.Code)
} else {
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\n", evt.ActiTitle, evt.Start, evt.End, evt.Room.Code)
}
}
}

writer.Flush()
}

func ClearEvents(credentialsPath string) {
Expand Down
202 changes: 202 additions & 0 deletions vendor/cloud.google.com/go/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 79c71b8

Please sign in to comment.