Skip to content

Commit

Permalink
feat(Clockify): Add Send Daily Activity Brief to Slack
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentLvr committed Oct 11, 2023
1 parent 3b1647f commit 80ad698
Showing 1 changed file with 274 additions and 0 deletions.
274 changes: 274 additions & 0 deletions Clockify/Clockify_Send_Daily_Activity_Brief_to_Slack.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "389e6be9-1a6e-4fcb-b091-e31607ec8da6",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"cell_type": "markdown",
"id": "36722081-8746-486c-a539-6a65f45732bb",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Clockify - Send Daily Activity Brief to Slack"
]
},
{
"cell_type": "markdown",
"id": "933b1463-8fc8-40a3-ba4f-19db5253599b",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #clockify #slack #activity #brief #daily #automation"
]
},
{
"cell_type": "markdown",
"id": "e0beb301-9271-41a4-b16a-ce2fee7db1c9",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)"
]
},
{
"cell_type": "markdown",
"id": "61596618-5ddf-4f83-8b0a-239e72060930",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2023-10-11 (Created: 2023-10-11)"
]
},
{
"cell_type": "markdown",
"id": "80cd984b-9345-452c-ad44-72dcdc8b26e1",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Description:** This notebook automates the process of sending a daily activity brief from Clockify to Slack. It is usefull for organizations to keep track of their team's daily activities."
]
},
{
"cell_type": "markdown",
"id": "951332ed-d0a6-4930-b9ff-69a66f3bbcfd",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n- [Clockify API Documentation](https://clockify.github.io/clockify_api_docs/)\n- [Slack API Documentation](https://api.slack.com/docs)"
]
},
{
"cell_type": "markdown",
"id": "855b70c1-9f73-4cba-bd43-6a8773e494f1",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "ce51e72d-4b4a-4a33-8619-cc02cdcf238b",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c821e4c-54c3-40a5-b1fe-c8f3d986f9c5",
"metadata": {
"papermill": {},
"tags": []
},
"source": "import requests\nimport json",
"outputs": []
},
{
"cell_type": "markdown",
"id": "1a6aa89f-f3c1-4d96-8ecc-fa7921ea3ee8",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Setup variables\n- `clockify_api_key`: Clockify API key. [Get your API key here](https://clockify.me/user/settings).\n- `slack_token`: Slack token. [Get your token here](https://api.slack.com/custom-integrations/legacy-tokens).\n- `slack_channel`: Slack channel to post the daily activity brief."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "48c0a7d3-cbe8-4508-849c-9aee7bbf9960",
"metadata": {
"papermill": {},
"tags": []
},
"source": "clockify_api_key = \"<YOUR_CLOCKIFY_API_KEY>\"\nslack_token = \"<YOUR_SLACK_TOKEN>\"\nslack_channel = \"<YOUR_SLACK_CHANNEL>\"",
"outputs": []
},
{
"cell_type": "markdown",
"id": "851b98ee-d339-4d4d-8eab-1e008e8a2590",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "beb8d3b5-8be3-4a74-9cab-f9466dd0dc8d",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Get daily activity brief"
]
},
{
"cell_type": "markdown",
"id": "f6fe61c4-4262-4405-a40d-6646bf1362e4",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"Retrieve the daily activity brief from Clockify API and store it in a variable."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f084002a-cd76-4ba9-9c19-b0a527320835",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Set the request headers\nheaders = {\"Content-Type\": \"application/json\", \"X-Api-Key\": clockify_api_key}\n# Set the request parameters\nparams = {\n \"workspace\": \"<YOUR_WORKSPACE_ID>\",\n \"user\": \"<YOUR_USER_ID>\",\n \"start\": \"<START_DATE>\",\n \"end\": \"<END_DATE>\",\n}\n# Make the request\nresponse = requests.get(\n \"https://api.clockify.me/api/v1/reports/summary\", headers=headers, params=params\n)\n# Store the response in a variable\ndaily_activity_brief = response.json()",
"outputs": []
},
{
"cell_type": "markdown",
"id": "00f4e125-3d1b-450c-9836-b72022b7c9f6",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Post daily activity brief to Slack"
]
},
{
"cell_type": "markdown",
"id": "4bd2bad1-237f-4a9b-95a9-650a1d141565",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"Post the daily activity brief to Slack."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2eb3b92c-3ae5-4806-9239-092b72b053ed",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Set the request headers\nheaders = {\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"Authorization\": \"Bearer \" + slack_token,\n}\n# Set the request body\nbody = {\n \"channel\": slack_channel,\n \"text\": \"Daily activity brief:\",\n \"attachments\": [{\"text\": json.dumps(daily_activity_brief, indent=4)}],\n}\n# Make the request\nresponse = requests.post(\n \"https://slack.com/api/chat.postMessage\", headers=headers, data=json.dumps(body)\n)",
"outputs": []
},
{
"cell_type": "markdown",
"id": "d943244f-dc15-44ca-98a9-c00df3976124",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "327dca23-43d6-40e4-a7f1-fda12179c445",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a87fb89-698f-41c0-b2eb-c8d622bc965e",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Print the response\nprint(response.text)",
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 80ad698

Please sign in to comment.