Coder Social home page Coder Social logo

seanbreckenridge / calcurse-load Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 110 KB

Hooks/scripts for calcurse. Sources events for calcurse from Google Calendar and todo.txt

Home Page: https://pypi.org/project/calcurse-load

License: MIT License

Python 94.38% Shell 5.62%
calcurse todotxt googlecalendar calendar google-calendar appointments hook cli

calcurse-load's Introduction

Hooks/scripts for loading data for calcurse. This integrates calcurse with Google Calendar, and todo.txt.

  • pre-load:
    • Looks at the locally indexed Google Calendar JSON dump, adds events as calcurse appointments; adds summary/HTML links as appointment notes.
    • Replace calcurses todos with my current todo.txt, converting priorities accordingly.
  • post-save
    • If any new todos are added, write those back to my todo.txt file.

This doesn't write back to Google Calendar, its only used to source events.

Should be mentioned that deleting a todo in calcurse does nothing, because the corresponding todotxt still exists. Only reason for me to load my todos into calcurse is to remind me what they are, and to possibly add new ones. I have other ways I mark todos as done.

Other than the extensions provided here, you can also define completely custom behaviour by creating your own extensions, see extension reference

As a general warning, if theres any output from the hooks, calcurse fails to load, so you could do something like this in your pre-load script:

python3 -m calcurse_load --pre-load gcal >>/tmp/calcurse_load.log 2>&1

Setup

git clone https://github.com/seanbreckenridge/calcurse-load && cd ./calcurse-load
# copy over calcurse hooks
# assuming its not overwriting any hooks, else youd have to manually copy in parts of the scripts
cp ./hooks/* ~/.config/calcurse/hooks/
pip install .  # install current directory with pip

This installs 2 python scripts/modules, gcal_index, and calcurse_load.

gcal_index has nothing to do with calcurse inherently, it could be used on its own to export all your current data from Google Calendar.

The data for calcurse is typically kept in $XDG_DATA_HOME/calcurse ($HOME/.local/share/calcurse). If you want to override that for some reason, this allows you to set the $CALCURSE_DIR environment variable. That's not something calcurse recognizes, but you could setup an alias:

export CALCURSE_DIR="$HOME/Documents/calcurse"
alias calcurse='calcurse --datadir "$CALCURSE_DIR" --confdir ~/.config/calcurse "$@"'

In addition to that, this maintains a data directory in $XDG_DATA_HOME/calcurse_load (you can overwrite this with $CALCURSE_LOAD_DIR), where it stores data for gcal_index.

About

If you wanted to disable one of the todotxt or gcal extensions, you could remove or rename the corresponding scripts in the hooks directory.

gcal pre-load

The gcal calcurse hook tries to read any gcal_index-created JSON files in the $XDG_DATA_HOME/calcurse_load/gcal/ directory. If there's description/extra information for events from Google Calendar, this attaches corresponding notes to each calcurse event. Specifically, it:

  • Loads the calcurse appointments file
  • Removes any Google Calendar events (which are tagged with [gcal])
  • Generates Google Calendar events from the JSON
  • Adds the newly created events and writes back to the appointments file.

gcal update example

gcal_index saves an index of Google Calendar events for a Google Account locally as a JSON file.

To setup credentials, see here.

Put the downloaded credentials in ~/.credentials/, and specify the location with the --credential-file. I'd recommend wrapping in a script, and then setting up a job to run in the background, to update the local JSON index of Google Calendar events.

Its possible to put the command to update the local JSON index in your pre-load hook as well, before the call to python3 -m calcurse_load, but that would cause some noticeable lag on calcurse start-up.

Usage: python -m gcal_index [OPTIONS]

  Export Google Calendar events

Options:
  --email TEXT            Google Email to export  [required]
  --credential-file TEXT  Google credential file  [required]
  --end-days INTEGER      Specify how many days into the future to get events
                          for (if we went forever, repeating events would be
                          there in 2050)  [default: 90]
  --calendar TEXT         Specify which calendar to export from  [default:
                          primary]
  --help                  Show this message and exit.

Prints the JSON dump to STDOUT; example:

python3 -m gcal_index --email <your_email> --credential-file ~/.credentials/<credential>.json

For an example script one might put under cron, see example_update_google_cal

todotxt

The pre-load/post-save todotxt hook converts the calcurse todos back to todotxt todos, and updates the todotxt file if any todos were added. A todo.txt is searched for in one of the common locations:

  • $TODOTXT_FILE
  • $TODO_DIR/todo.txt
  • $XDG_CONFIG/todo/todo.txt
  • ~/.config/todo/todo.txt
  • ~/.todo/todo.txt

Todo.txt Priority Conversion

Todo.txt Calcurse
(A) 1 - 3
(B) 4 - 6
(C) 7 - 9
None 0

calcurse_load reference

calcurse_load accepts one, or multiple pre/post hooks, with an extension name. There are individual hooks for for each extension (gcal/todotxt)

You could instead just add the single line you want into your pre-load script, like: python3 -m calcurse_load --pre-load todotxt --pre-load gcal

Usage: calcurse_load [OPTIONS]

  A CLI for loading data for calcurse

Options:
  --pre-load gcal|todotxt|custom.module.name.Extension
                                  Execute the preload action for the extension
  --post-save gcal|todotxt|custom.module.name.Extension
                                  Execute the postsave action for the
                                  extension
  --help                          Show this message and exit.

If you want to use this for other purposes; there is a Extension base class in calcurse_load.ext.abstract.

To load a custom extension, you can point this at the fully qualified path to an Extension (module name + class name). This works with both absolute and relative imports.

Relative

With relative paths, the easiest way is to put the extension in a myextension.py file in your hooks directory:

.
├── gcal.enabled
├── myextension.py
├── post-save
├── pre-load
└── todotxt.enabled

1 directory, 5 files

As an example:

import os
from calcurse_load.ext.abstract import Extension


class Notifier(Extension):
    """
    Sends a notification letting you know how many appointments were loaded
    """

    def pre_load(self):
        appointments = self.config.calcurse_dir / "apts"
        with open(appointments, "r") as f:
            lines = [l for l in f.readlines() if l.strip()]

        os.system(f"notify-send 'Loaded {len(lines)} appointments'")

    def post_save(self):
        # do nothing
        pass

Then, for example, at the top of your pre-load, just be sure to change the directory to the current one, and call your custom extension:

#!/bin/sh

cd "$(dirname "$0")" || exit 1

python3 -m calcurse_load --pre-load myextension.Notifier

Absolute

If you had a wrote your own package and like my_custom_calcurse installed into your python environment, and inside that file you have a class called MyCustomExtension, you can load that extension by passing my_custom_calcurse.MyCustomExtension to the --pre-load or --post-save options.

As another example, to use it with the gcal extension, you could also provide the fully qualified path:

python3 -m calcurse_load --pre-load calcurse_load.ext.gcal.gcal_ext

calcurse-load's People

Contributors

seanbreckenridge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

haze-sh

calcurse-load's Issues

move gcal JSON files

this should be kept in $XDG_DATA_HOME/.local/share/calcurse_load/gcal instead of $XDG_DATA_HOME/.local/share/calcurse_load, so its easier to extend and other events to source from

parse summary as todotxt lines

Use some version of a todotxt priority system which lets me time block more effectively

[gcal] or (A) - appointments, meetings, these are inflexible
(B) - bottlenecks (things I should get done, they affect other tasks)
(C) - critical (no other tasks depend on these, but theyre important to do)
(D) - daily stuff (things I need to do everyday)
(F) - flexible (in an ideal world I'd get these done, but they're not super important)

should have some ability to mark these complete (using the todotxt 'x')

should be able to parse these out using -G, and pass it through some python to filter by different prios/print what I've done today/what I have left, as well as modify the apt file directly and write changes without opening calcurse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.