-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
135 lines (105 loc) · 3.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"fmt"
"os"
"google.golang.org/api/drive/v2"
"log"
"flag"
"io/ioutil"
)
const (
EVENT_LOCATION = "Bahcesehir Universitesi Besiktas Kampus Ciragan Caddesi Osmanpasa Mektebi Sokak No: 4 - D504 Nolu sınıf"
EVENT_FILE_NAME = "Event Schedule"
)
var environmentName = os.Getenv("HOME")
func check(e error) {
if e != nil {
fmt.Println("Error :", e)
}
}
func main() {
commandType := os.Args[1]
switch commandType {
case "meetup":
mySet := flag.NewFlagSet("", flag.ExitOnError)
var desc = mySet.String("desc", "", "Description of the meetup event")
var apikey = mySet.String("apikey", "", "meetup developer apikey")
var gid = mySet.String("gid", "", "Groug id")
var name = mySet.String("name", "", "Name of the event")
var vid = mySet.String("vid", "", "Venue id")
var rsvp_limit = mySet.String("rsvp_limit", "", "Rsvp Limit")
var time = mySet.String("time", "", "Time for the event")
mySet.Parse(os.Args[2:])
if !mySet.Parsed() {
fmt.Println("Error parsing arguments:", mySet.Args())
}
eventUrl := initiateMeetup(*desc, *apikey, *gid, *name, *vid, *rsvp_limit, *time)
eventUrlFile := []byte(eventUrl)
err := ioutil.WriteFile("eventurl.md", eventUrlFile, 0644)
check(err)
case "twitter":
var ckey string
var csecret string
var atoken string
var asecret string
var subject string
mySet := flag.NewFlagSet("", flag.ExitOnError)
mySet.StringVar(&ckey, "ckey", "", "Consumer Key acquired from dev.twitter")
mySet.StringVar(&csecret, "csecret", "", "Consumer Secret acquired from dev.twitter")
mySet.StringVar(&atoken, "atoken", "", "Access token from dev.twitter")
mySet.StringVar(&asecret, "asecret", "", "Access secret from dev.twitter")
mySet.StringVar(&subject, "subject", "", "Istanbulcoders subject of the event")
mySet.Parse(os.Args[2:])
if !mySet.Parsed() {
fmt.Println("Error parsing arguments:", mySet.Args())
}
initiateTweet(ckey, csecret, atoken, asecret, subject)
case "gmail":
var to string
var cc string
var from string
var subject string
var body string
var username string
var password string
mySet := flag.NewFlagSet("", flag.ExitOnError)
mySet.StringVar(&to, "to", "", "email to")
mySet.StringVar(&cc, "cc", to, "email cc")
mySet.StringVar(&from, "from", "", "email from")
mySet.StringVar(&subject, "subject", "", "email subject")
mySet.StringVar(&body, "body", "", "email body")
mySet.StringVar(&username, "username", "", "email username")
mySet.StringVar(&password, "password", "", "email password")
mySet.Parse(os.Args[2:])
if !mySet.Parsed() {
fmt.Println("Error parsing arguments:", mySet.Args())
}
sendEmail(to, cc, from, subject, body, username, password)
case "calendar":
client := createGoogleApiClient()
driveService, err := createDriveService(client)
if err != nil {
log.Fatalf("Can not instantiate google drive service client: %v", err)
}
transport := createTransport()
downloadFile(driveService, transport, &drive.File{
DownloadUrl:getDownloadUrlByName(driveService, EVENT_FILE_NAME),
})
calendarService, err := createCalendarService(client)
if err != nil {
log.Fatalf("Can not instantiate google calendar service: %v", err)
}
eventListFromFile := getEventListInEventFile()
for _, event := range eventListFromFile {
if event.date != "" {
information := EventInformation{
date:convertDateStringToInnerFormat(event.date),
title:event.title,
description:event.description,
location: event.location,
}
insertEventToCalendar(calendarService, information)
}
}
}
}