Everything starts with this timer, which gets recent activities by calling GitHub [Events API](https://developer.github.com/v3/activity/events/) and stores the response under /.cache/awmw/github-activity-widget/activity.json directory:
if stderr ~= '' then show_warning(stderr) return end
end)
end
}
```
There are several reasons to store output in a file and then use it as a source to build the widget, instead of calling it everytime the widget is opened:
- activity feed does not update that often
- events API doesn't provide filtering of fields, so the output is quite large (300 events)
- it's much faster to read file from filesystem
Next important part is **rebuild_widget** function, which is called when mouse button clicks on the widget on the wibar. It receives a json string which contains first n events from the cache file. Those events are processed by `jq` (get first n events, remove unused fields, slightly change the json structure to simplify serialization to lua table). And then it builds a widget, row by row in a loop. To display the text part of the row we already have all neccessary information in the json string which was converted to lua table. But to show an avatar we should download it first. This is done in the following snippet. First it creates a template and then checks if file already exists, and sets it in template, otherwise, downloads it asynchronously and only then sets in: