Skip to content

Commit

Permalink
refactored event code, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hawry committed Nov 9, 2016
1 parent 34ee886 commit cf9e4b8
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 212 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ events32
events-are-square
events-are-square.exe
coverage.out
eas
eas32
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

SquareSpace currently doesn't support export of entire event calendars to iCal/vCal format to use with i.e. Google Calendar. This little tool acts as a proxy between SquareSpace and an iCalendar provider. The project is still considered as a work in progress, but is currently working as intended - though the number of features are quite low.

Tested with GoLang v1.6 but should work on GoLang 1.4 and 1.5 as well, and should work on both 32-bit architectures as well as 64-bit.
Tested with GoLang v1.7 but should work on Go 1.4+, and should work on both 32 and 64-bit architectures.

### Current status
As of now, EaS only supports basic event-information and can convert SquareSpace event information to the following iCal tags:
Expand All @@ -18,7 +18,14 @@ Make sure you have all the dependencies installed on your system by changing dir
`go get -u`

### Build
`go build -o events`
Please use the supplied makefile if possible, since this will add a build version to your binary which will make it a lot easier to troubleshoot in the future. To use the makefile:

**64-bit architectures**: `make`

**32-bit architectures**: `make 32`

If you don't wish to use the makefile, or don't have the possibility due to other reasons, use the go compiler:
`go build -o eas` *Please note that this will not include a build version*

## Usage
The idea is that EaS will act as a proxy between Google (or the provider of your choice) and SquareSpace. Start the EaS-server on a publically available server and then import a webcalendar in Google by using the EaS-as proxy:
Expand All @@ -27,22 +34,23 @@ The idea is that EaS will act as a proxy between Google (or the provider of your

### Flags and runtime arguments
```
usage: events [<flags>]
usage: eas [<flags>]
Flags:
--help Show context-sensitive help (also try
--help-long and --help-man).
-a, --autoappend append 'format=json' to source URL
automatically
--help Show context-sensitive help (also try --help-long
and --help-man).
-p, --port=8080 port to listen for incoming requests on
-t, --topdomain=hawry.net restrict calendar requests to a specific
top-domain
-t, --topdomain=hawry.net restrict calendar requests to a specific top-domain
-z, --timezone=TIMEZONE add timezoneid to all events
-o, --offset=0 add number of hours as offset and (fake) UTC
```

#### Timezones
Unless otherwise specified, the timezone will be in UTC (Zulu-time). To change timezone append the flag `-z` or `--timezone=TIMEZONE` where TIMEZONE is the country code according to the [Zone.tab][1] file.

#### Offset
This flag should only be used when you experience weird time offsets in your Google Calendar vs SquareSpace and any other third-party application you might use. This will add an offset (negative or positive) to the time that SquareSpace are giving you. The reason for this might be that a third-party calendar/application might be poorly

## Planned features

*Please note that EaS is a work in progress and is developed during my free time, and therefore might take a while to be updated. You are very welcome to contribute to the project though!*
Expand Down
26 changes: 0 additions & 26 deletions coverage.out

This file was deleted.

104 changes: 104 additions & 0 deletions event/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package event

import (
"encoding/json"
"fmt"
"io"
"io/ioutil"

"github.com/hawry/events-are-square/helpers"
"github.com/hawry/events-are-square/strip"
)

//Author represents author info in a specific event
type Author struct {
ID string `json:"id"`
LastLoginOn int64 `json:"lastLoginOn"`
LastActiveOn int64 `json:"lastActiveOn"`
IsDeactivated bool `json:"isDeactivated"`
Deleted bool `json:"deleted"`
DisplayName string `json:"displayName"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
EmailVerified bool `json:"emailVerified"`
Bio string `json:"bio"`
RevalidateTimestamp int64 `json:"revalidateTimestamp"`
SystemGenerated bool `json:"systemGenerated"`
}

//StructuredContent conains information about the event startdate/enddate
type StructuredContent struct {
Type string `json:"_type"`
StartDate int64 `json:"startDate"`
EndDate int64 `json:"endDate"`
}

//Items is a dummy struct as of now
type Items struct{}

//Event represents a single event in the upcoming list
type Event struct {
ID string `json:"id"`
CollectionID string `json:"collectionId"`
RecordType int `json:"recordType"`
AddedOn int64 `json:"addedOn"`
UpdatedOn int64 `json:"updatedOn"`
PublishOn int64 `json:"publishOn"`
AuthorID string `json:"authorId"`
URLID string `json:"urlId"`
Title string `json:"title"`
SourceURL string `json:"sourceUrl"`
Body string `json:"body"`
Author Author `json:"author"`
FullURL string `json:"fullUrl"`
AssetURL string `json:"assetUrl"`
ContentType string `json:"contentType"`
StructuredContent StructuredContent `json:"structuredContent"`
StartDate int64 `json:"startDate"`
EndDate int64 `json:"endDate"`
Items []Items `json:"items"`
}

//List is a parent struct for all events (name because lint suggests stuttering otherwise)
type List struct {
Events []Event `json:"upcoming"`
Offset int
TimeZone string
}

//Parse will read the raw data, and unmarshal it into a List struct and return it
func Parse(r io.Reader) (*List, error) {
eventList := List{}
raw, err := ioutil.ReadAll(r)
if err != nil {
return &eventList, err
}
err = json.Unmarshal(raw, &eventList)
if err != nil {
return &eventList, err
}
return &eventList, nil
}

//VCal takes a List-struct and will return the VCAL-formatted string that it represents
func (eventList *List) VCal() string {
var sVal string

tz := eventList.TimeZone
offset := eventList.Offset

sVal += "BEGIN:VCALENDAR\r\n"
sVal += "VERSION:2.0\r\n"
for _, e := range eventList.Events {
sVal += "BEGIN:VEVENT\r\n"
uid := fmt.Sprintf("UID:%s\r\n", e.ID)
start := fmt.Sprintf("DTSTART%s\r\n", helpers.To8601(e.StartDate, tz, offset))
end := fmt.Sprintf("DTEND%s\r\n", helpers.To8601(e.EndDate, tz, offset))
summary := fmt.Sprintf("SUMMARY:%s\r\n", e.Title)
desc := fmt.Sprintf("DESCRIPTION:%s\r\n", strip.StripTags(e.Body))
sVal += uid + start + end + summary + desc
sVal += "END:VEVENT\r\n"
}
sVal += "END:VCALENDAR\r\n"
return sVal
}
Loading

0 comments on commit cf9e4b8

Please sign in to comment.