Skip to content

Instantly share code, notes, and snippets.

@humzakhatri
Last active February 13, 2021 07:45
Show Gist options
  • Save humzakhatri/73695b0f3cc724b18f9b4e83ffbd2019 to your computer and use it in GitHub Desktop.
Save humzakhatri/73695b0f3cc724b18f9b4e83ffbd2019 to your computer and use it in GitHub Desktop.
This uses the Todoist REST API to fetch tasks and filters them by today.

Description

Simple widget to display today's tasks from Todoist.

##Dependencies

httparty

Add it to dashing's gemfile:

gem 'httparty'

and run bundle install. Everything should work now :)

##Usage

To use this widget, copy the todoist_tasks.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
  <div data-id="tasks" data-view="List" data-unordered="true" data-title="Tasks for today" data-moreinfo="Get these done!"></div>
</li>

##Settings

You'll need to add the token from todoist api Todoist API

The tasks are filtered by today's date, you can look and change to code in 'todoist_tasks.rb' if you so desire.

The data is updated every 30 seconds, this can again be changed in the 'todoist_tasks.rb' file.

This uses the standard widget for displaying lists.

Please leave a review and your feedback below, Thank you :)

require 'httparty'
tasks_with_ids = Hash.new({ value: 0 })
url = 'https://api.todoist.com/rest/v1/tasks'
SCHEDULER.every '30s' do
response = HTTParty.get(url, headers: {
"Authorization" => "Bearer <your token here>"
})
time = Time.new
today = time.strftime("%Y-%m-%d")
parsed = JSON.parse(response.body)
parsed.each{|n|
id = n['id']
content = n['content']
if n['due'] != nil && n['due']['date'] == today
date = n['due']['date']
tasks_with_ids[id] = { label: content}
end
}
send_event('tasks', { items: tasks_with_ids.values })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment