Skip to content

Commit

Permalink
commit for v0.3.0
Browse files Browse the repository at this point in the history
* Added default value for some settings.
* Fixed issues with Eventbrite due to change of the api.
* Fixed issues with summary for Atnd/Zusaar which sometimes gets empty content.
  • Loading branch information
daikikohara committed Oct 11, 2015
1 parent a77d0f7 commit 6fa6872
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 119 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ enotify-slack

## Summary

This is a tool to get event information and send the information to a channel in [Slack](https://slack.com/).
The event information is provided by event provider's site such as [Meetup](http://www.meetup.com/) and [Eventbrite](https://www.eventbrite.com/)(the others are mainly Japanese sites).
This is a tool to get event(meetup) information and send the information to a channel in [Slack](https://slack.com/).
The event information is provided by event provider's site such as [Meetup](http://www.meetup.com/) and [Eventbrite](https://www.eventbrite.com/)(the others are mainly only used in Japan).
The event information will be sent to Slack if the title or description contains keyword specified in the configuration file.

![screenshot](https://raw.github.com/wiki/daikikohara/enotify-slack/images/capture01.png)
Expand All @@ -31,7 +31,7 @@ enotify-slack uses api shown below.
* [Eventbrite](http://developer.eventbrite.com/docs/)
* [Meetup](http://www.meetup.com/meetup_api/)
* [Partake](https://github.com/partakein/partake/wiki/PARTAKE-Web-API)
* [StreetAcademy](http://www.street-academy.com/api)
* [StreetAcademy](https://www.street-academy.com/api.html)
* [Zusaar](http://www.zusaar.com/doc/api.html)
* Slack
* [Slack](https://api.slack.com/)
Expand Down
134 changes: 130 additions & 4 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ type Config struct {
Nickname string
Taboo string
Place []string
Provider map[string]struct {
Provider map[string]*struct {
Url string
Color string
Interval uint32
Token string
}
Slack struct {
Pretext string
Expand All @@ -34,6 +35,80 @@ type Config struct {
ErrorToSlack bool `yaml:"error_to_slack"`
}

// defConf holds default values for Config
var defConf = Config{
Provider: map[string]*struct {
Url string
Color string
Interval uint32
Token string
}{
"atnd": {
Url: "https://api.atnd.org/events/?count=50&format=json&",
Color: "#000000",
Interval: 3600,
},
"connpass": {
Url: "http://connpass.com/api/v1/event/?order=3&count=50&",
Color: "#D00000",
Interval: 3600,
},
"doorkeeper": {
Url: "http://api.doorkeeper.jp/events/?sort=published_at&locale=ja&",
Color: "#00D0A0",
Interval: 3600,
},
"eventbrite": {
Url: "https://www.eventbriteapi.com/v3/events/search/?token=",
Color: "#FFaa33",
Interval: 3600,
},
"meetup": {
Url: "https://api.meetup.com/2/open_events?key=",
Color: "#F00000",
Interval: 3600,
},
"partake": {
Url: "http://partake.in/api/event/search?sortOrder=createdAt&maxNum=50&query=",
Color: "#AAAAAA",
Interval: 3600,
},
"strtacademy": {
Url: "http://www.street-academy.com/api/v1/events?page=",
Color: "#009900",
Interval: 3600,
},
"zusaar": {
Url: "http://www.zusaar.com/api/event/?count=50&",
Color: "#0000FF",
Interval: 3600,
},
},
Slack: struct {
Pretext string
Url string
Channel string
Short bool
Interval uint32
}{
Pretext: "New Event Arrived!",
Url: "",
Channel: "#event-notify",
Short: false,
Interval: 3,
},
Boltdb: struct {
Dbfile string
Bucketname string
}{
Dbfile: "enotify-slack.db",
Bucketname: "enotify-slack",
},
Logfile: "enotify-slack.log",
Timezone: "America/Los_Angeles",
ErrorToSlack: false,
}

// NewConfig constructs Config using a yaml file passed as the argument.
func NewConfig(yml string) *Config {
buf, err := ioutil.ReadFile(yml)
Expand All @@ -55,14 +130,65 @@ func NewConfig(yml string) *Config {
// It currently only checks the interval to avoid overloading api providers.
func (config *Config) isValid() bool {
if config.Slack.Interval < 1 {
log.Println("slack send interval must be 1 or bigger.")
config.Slack.Interval = defConf.Slack.Interval
}
if config.Slack.Url == "" {
log.Println("Slack webhook URL is empty.")
return false
}
if config.Slack.Pretext == "" {
config.Slack.Pretext = defConf.Slack.Pretext
}
if config.Slack.Channel == "" {
log.Println("Slack channel name is empty.")
return false
}
for _, provider := range config.Provider {
if provider.Interval < 60 {
if config.Boltdb.Dbfile == "" {
config.Boltdb.Dbfile = defConf.Boltdb.Dbfile
}
if config.Boltdb.Bucketname == "" {
config.Boltdb.Bucketname = defConf.Boltdb.Bucketname
}
if config.Logfile == "" {
config.Logfile = defConf.Logfile
}
if config.Timezone == "" {
config.Timezone = defConf.Timezone
}
for name, provider := range config.Provider {
if provider == nil {
provider = &struct {
Url string
Color string
Interval uint32
Token string
}{
Url: defConf.Provider[name].Url,
Color: defConf.Provider[name].Color,
Interval: defConf.Provider[name].Interval,
Token: "",
}
}
if provider.Interval == 0 {
provider.Interval = defConf.Provider[name].Interval
} else if provider.Interval < 60 {
log.Println("event check interval must be 60 or bigger. Do NOT overload providers.")
return false
}
if provider.Url == "" {
provider.Url = defConf.Provider[name].Url
}
if provider.Color == "" {
provider.Color = defConf.Provider[name].Color
}
if name == "meetup" || name == "eventbrite" {
if provider.Token == "" {
log.Println("token is empty for" + name)
return false
}
provider.Url = provider.Url + provider.Token + "&"
}
config.Provider[name] = provider
}
return true
}
94 changes: 50 additions & 44 deletions conf.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,99 @@
# Optional settings and/or insignificant settings are commented out. Please modify the others.


# If event title/description contains 'keyword', the event will be sent to Slack.
#
keyword: golang,slack,anotherkeyword,etc

# If the owner or participants contains 'nickname', the event will be sent to Slack.
# 'nickname' is OR'd with keyword.
# 'nickname' only works for Atnd, Connpass and Zusaar.
#
# NOTE: 'nickname' only works for Atnd, Connpass and Zusaar.
#
nickname: nickname1,nickname2,etc

# If event title/description contains 'taboo', the event will Not be sent to Slack even if the other conditions are satisfied.
#
taboo: taboo1,taboo2,etc

# Event will be sent if 'place' is included in the event address.
# 'place' is AND'd with 'keyword' or 'nickname'.
# NOTE: If you want to get information from Eventbrite,
# - write city name since Eventbrite requires city name.
# - use alphabet name for the city (Among non-alphabet character, only Japanese city(prefecture) name in Kanji character is supported).
#
place:
- "San Jose"
- "Santa Clara"
- "Sunnyvale"
- "Mountain View"

# Event provider specific configuration.
# url: url for the API. API key for meetup and eventbrite must be set using your key.
# color: color to be displayed on Slack.
# interval: interval in second to execute the API.
# Keep the value moderate to avoid overloading the event provider.
# Comment some provider's name(,url color and interval) out, if you don't want to get event information from them.
# Following settings are supported.
# token: (required for eventbrite and meetup) API key for meetup and API token for eventbrite.
# url: (optional) Url for the API.
# default value: see the source file(conf.go)
# color: (optional) color to be displayed on Slack.
# default value: see the source file(conf.go)
# interval: interval in second to call the API.
# Keep the value moderate to avoid overloading the event provider and exceeding the rate limit.
# default value: 3600
# Comment any provider's name out, if you don't want to get event information from the provider.
#
# NOTE: Icon in Slack message is shown as :providername: (like ":meetup:").
# Please set the icon for your Slack in advance or you'll see the name as text.
#
provider:
atnd:
url: https://api.atnd.org/events/?count=50&format=json&
color: "#000000"
interval: 600
connpass:
url: http://connpass.com/api/v1/event/?order=3&count=50&
color: "#D00000"
interval: 600
doorkeeper:
url: http://api.doorkeeper.jp/events/?sort=published_at&locale=ja&
color: "#00D0A0"
interval: 600
eventbrite:
url: https://www.eventbriteapi.com/v3/events/search/?token=your_api_token_here&
color: "#FFaa33"
interval: 600
meetup:
url: https://api.meetup.com/2/open_events?key=your_api_key_here&
color: "#F00000"
interval: 600
partake:
url: http://partake.in/api/event/search?sortOrder=createdAt&maxNum=50&query=
color: "#AAAAAA"
interval: 600
strtacademy:
url: http://www.street-academy.com/api/v1/events?page=
color: "#009900"
interval: 600
zusaar:
url: http://www.zusaar.com/api/event/?count=50&
color: "#0000FF"
interval: 600
eventbrite:
token: your_token_here
meetup:
token: your_api_key_here

# Slack configuration.
# pretex: text to be displayed before event details.
# url: url for your your Slack incoming-webhook. modify the token.
# channel: name of Slack channel that event is sent to.
# Following settings are supported.
# url: (required) Url for your Slack incoming-webhook. Modify the token.
# pretex: (optional) text to be displayed before event details.
# default value: "New Event Arrived!"
# channel: (optional) name of Slack channel that event is sent to.
# default value: "#event-notify"
# short: if true, event details are displayed side-by-side.
# default value: false
# interval: interval in second to send event to Slack.
# This prevent reaching rate limit when many events are registered in a short period.
# default value: 3
#
slack:
pretext: "New Event Arrived!"
url: https://hooks.slack.com/services/YOUR/TOKEN/HERE
url: "https://hooks.slack.com/services/YOUR/TOKEN/HERE"
channel: "#event-notify"
short: false
interval: 3

# timezone
# The time of event sent to Slack is shown as time in this time zone.
# default value: "America/Los_Angeles"
#
timezone: "America/Los_Angeles"

# db file configuration.
# This usually does not need to be modified.
boltdb:
dbfile: enotify-slack.db
bucketname: enotify-slack
# default value: "enotify-slack.db" for dbfile, "enotify-slack" for bucketname
#
#boltdb:
# dbfile: enotify-slack.db
# bucketname: enotify-slack

# log file name.
# This usually does not need to be modified.
logfile: enotify-slack.log
# default value: "enotify-slack.log"
#
#logfile: enotify-slack.log

# If 'error_to_slack' is true, error messages are sent to Slack when error occurs.
# Recommended to leave this false since lots of messages are sent when network error occurs.
error_to_slack: false
# default value: false
#
#error_to_slack: false
2 changes: 1 addition & 1 deletion event/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// Api is an interface to get a slice of Event
type Api interface {
// Get gets a slice of Event using API depending on api providers.
Get(baseurl, keyword, nickname string) ([]Event, error)
Get(baseurl, keyword, nickname string, places []string) ([]Event, error)
}

// timeFormat holds time format.
Expand Down
11 changes: 11 additions & 0 deletions event/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
nickname = "nickname1"
)

var place = []string{"San Jose", "東京", "渋谷"}

var (
eventok = Event{
Id: "123",
Expand All @@ -26,6 +28,15 @@ var (
Place: "address123\nplace123",
Description: "summary123",
}
eventbriteok = Event{
Id: "123",
Title: "example#1",
Summary: "summary123",
Url: "http://example.connpass.com/event/123/",
Started_at: "2015-09-30 19:00",
Place: "San Jose",
Description: "summary123",
}
eventoklong = Event{
Id: "123",
Title: "example#1",
Expand Down
Loading

0 comments on commit 6fa6872

Please sign in to comment.