NaïveCalendar

naïf, naïve n. adj.

1. LITTERAIRE Qui est naturel, sans artifice, spontané. Art naïf, art populaire, folklorique. — Un peintre naïf.

2. COURANT Qui est plein de confiance et de simplicité par ignorance, par inexpérience. ➙ candide, ingénu, simple. — Qui exprime des choses simples que tout le monde sait. Remarque naïve. ➙ simpliste.

LeRobert

https://img.shields.io/badge/Source-git-success https://img.shields.io/badge/Download-script-yellow

A popup calendar with rofi and python3:

  • Cycle through calendar month by month

  • Create notes linked to days. Days with notes will appear colored

https://framagit.org/Daguhh/naivecalendar/-/raw/master/naivecalendar_screenshot.png

Dependancies

Usage

Run:

chmod +x naivecalendar.py
./naivecalendar.py

For more detail about commands, run the script, then, in the command prompt, type:

help

Documentation

Build the doc

cd docs/
python3 -m pip install -r requirements.txt
make html

Fonctions

A simple calendar made with rofi and python3.

Cycle through month and create linked note to days.

rofi theme by adi1090x : https://github.com/adi1090x/polybar-themes

naivecalendar.add_months(sourcedate, months)

Increment or decrement date by a number of month

Parameters
  • sourcedate (datetime.date) – Date to Increment

  • months (int) – number of month to add

Returns

Incremented date

Return type

datetime.date

naivecalendar.cal2rofi_ind(day, month, year)

Convert calendar date into coordinates for rofi

Parameters
  • day (int) – A day number (1-31)

  • month (int) – A month number (1-12)

  • year (int) – A year number

Returns

A rofi index

Return type

int

naivecalendar.display_help(head_txt='help:')

Show a rofi popup with help message

naivecalendar.gen_rofi_conf(text, urgent, day_ind)

Create a rofi command theme by adi1090x : https://github.com/adi1090x/polybar-themes

naivecalendar.get_arguments()

Parse command line arguments

naivecalendar.get_calendar_from_date(date)

Return a montly calendar given date

Calendar is a string formated to be shown by rofi (i.e. column bu column):

           L  M  M  J  V  S  D
                             1
           2  3  4  5  6  7  8
date  ->   9 10 11 12 13 14 15   ->   'L\n \n2\n9\n16\n23\n30\n<\nM\n \n3\n10\n17\n24\n...'
          16 17 18 19 20 21 22
          23 24 25 26 27 28 29
          30
Parameters

date (datetime.date) – Any day of the month to display

Returns

A str that contain chained columns of a calendar in a rofi format

Return type

str

naivecalendar.get_month_notes(date)

Return notes files paths that are attached to date’s month

Parameters

date (datetime.date) – Any day of the month displayed

Returns

list of files that belong to date.month

Return type

list

naivecalendar.get_month_notes_heads(date)

Return a list of file’s first line of a specific month

Parameters

date (datetime.date) – Any day of the month to display

Returns

A rofi formatted list of month’s notes first line

Return type

str

naivecalendar.get_month_notes_ind(date)

Return rofi-formatted index of days with attached note

Parameters

date (datetime.date) – Any day of the month displayed

Returns

Column index list formatted for rofi

Return type

str

naivecalendar.get_note_head(note_path)

Return first line of a text file

Parameters

note_path (str) – A text file path

Returns

First line of the text file

Return type

str

naivecalendar.intercept_rofi_error(func)

A decorator to capture sdtout after rofi being killed

naivecalendar.main()

Display a calendar with rofi Calendar is interactive :

  • switch between month

  • open {EDITOR} and create a note for selected day

naivecalendar.rofi2cal_ind(ind)

Convert coordinate from rofi to day number

naivecalendar.show_rofi(txt_body, txt_head)

Launch a rofi window

Parameters
  • txt_body (str) – Text to display in rofi window

  • txt_head (str) – Text to display in rofi prompt

Returns

Rofi selected cell content

Return type

str

naivecalendar.show_rofi_calendar(rofi, cal)

Launch a rofi window

Parameters
  • rofi (str) – Rofi command to be run in a shell

  • cal (str) – A column by column calendar list formatted for rofi

Returns

Rofi selected cell content

Return type

str

naivecalendar.weekly_transpose(cal, w=7)

Transpose (math) a line by line list into column by column list, given column number

Parameters
  • cal (list) – line by line elements of a calendar

  • w (int) – number of column in the calendar (usually 7)

Returns

A list that represent column by column elements of a calendar

Return type

list

Examples

With an hypothetic 3 day week

>>> my_list = [1,2,3,4,5,6]
>>> weekly_transpose(my_list, w=3)
[1,4,2,5,3,6]