Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/its-just-nans/go-calendar

Generate a calendar from a JSON file
https://github.com/its-just-nans/go-calendar

calendar calendar-generator generator go golang json

Last synced: about 1 month ago
JSON representation

Generate a calendar from a JSON file

Awesome Lists containing this project

README

        

# go-calendar

Generate a calendar from a JSON file.

![Example](./example.svg)

## Options with args

| Option | Description | Default |
| ------- | ------------------------------- | ---------- |
| -k KEY | Key of the date | date |
| -c KEY | Key of the counter | |
| -d | First day of the week | 1 (Monday) |
| -i FILE | Path to the JSON file | data.json |
| -o FILE | Path to the output file | out.svg |
| -q | Quiet mode | false |
| -h | Hexa color (alpha is optionnal) | 00C8C8FF |

## Usage

There are differents possible usages depending on your JSON file.

JSON file with dates

```json
[
{
"date": "2022-11-06",
},
{
"date": "2022-11-07",
},
]
```

You will need to specify the key of the date and the key of the counter

```sh
go run github.com/Its-Just-Nans/go-calendar -k date
```

JSON file with a counter

```json
[
{
"date": "2022-11-06",
"num": 9
},
{
"date": "2022-11-06",
"num": 1
},
]
```

You will need to specify the key of the date and the key of the counter

```sh
go run github.com/Its-Just-Nans/go-calendar -k date -c num
```

## Example

Generate calendar from Github contributions

Using [gh api](https://cli.github.com/manual/gh) and [jq](https://github.com/jqlang/jq), you can get your contributions from Github with

```sh
gh api graphql -F owner='Its-Just-Nans' -f query='
query( $owner: String!) {
user(login: $owner) {
contributionsCollection {
contributionCalendar {
totalContributions
weeks {
contributionDays {
contributionCount
weekday
date
}
}
}
}
}}' | jq '[.data.user.contributionsCollection.contributionCalendar.weeks | .[].contributionDays |.[] | {date: (.date), num:(.contributionCount)}]' > out.json
```

Then you can generate the calendar with

```sh
go run github.com/Its-Just-Nans/go-calendar -k date -c num -i out.json -o contributions.svg
```

## License

[License MIT](./LICENSE)