/birthdays-reminder

Shows a list of birthdays from the file containing birthdays information.

Primary LanguageCGNU General Public License v3.0GPL-3.0

Birthdays Reminder

About

This program simply scans a file with birthdays informations and then displays the list with number before the next birthday.

Extra utility bikram samvat date converter is included. Can be used as a tiny utility to show current date in BS as well as convert dates.

Extra utility numerical converter from 0-9 to ०-९ (devanagari numbers) is also included. The output from the date converter/current date can be piped to this program.

The image below shows the taskbar with the bikram samvat date in maroon color.

./screenshot.png

This is output using i3status-rust with following config:

[[block]]
block = "custom"
shell = "sh"
cycle = ["echo '[BS]'", "adbs-convert -", "adbs-convert - | devnagari-num"]
format = "$text"
[block.theme_overrides]
idle_bg = "#773456"

Compilation

You can just use the Makefile to compile the files if you are on Linux. Or you can use the gcc command.

Any of the following two is fine.

make
gcc -o birthdays bdays.c convertADBS.c

For tests, do make test and then run the ./test binary. The dates-sorted.txt file contains the dates from 2000-2089 BS that will be tested. Any mistakes will be printed with dates from test file and unmatched converted date along with line number in the test file.

There is dates.py file that can read the dates-sorted.txt file for some exploratory analysis of the test data.

Command Line Arguments

The available command line arguments can be seen using -h flag.

./birthdays -h

The output should show compilation details if needed:

Birthday reminders for Constant display
Options:
	-u val	 upper limit of days, val=(0-366)
	-l val	 lower limit of days, val=(0-366)
	-t	 Show today's birthdays only
	-d	 Show today's date in BS
	-r	 Print in remind file format.

Change the DEBUG value to 1 inside the bdays.c if you want to compile with the debug option. It’ll print out the inner mechanism while running.

Input

The input file is the birthdays file which has information in txt. Here the bdays.c has BIRTHDAYS_FILE defined which is used to read the birthdays, you can change the file in the code.

Right now the birthdays_dummy.txt has following data:

#mine #all are dummy
2051-07-14 BS:MINE

#Family members
1998-12-6 AD:Brother
2029-9-20 BS:Mom


#Friends
2052-1-29 BS:	Friend 1               
X-4-11 AD: 	Someone 1
XXXX-4-22 AD:	Someone 2
X090-5-6 AD:	Someone 3
2053-7-2 BS:	Friend 2
2051-1-04 BS:	Friend 3
2057-11-12 BS:	Friend 4

As you can see, you can input the data in variety of ways. Both AD and BS are supported. BS ones are assumed to celebrate on BS birthday and same for AD. You can skip the year with character X, like X-1-2 instead of 1990-1-2 if you don’t know or want to store the year.

Uses

Single time executable

The default program is one time executable, you can run the code to get the list of the birthdays listed in the birthdays.txt file. (Filename specified in the program itself).

./birthdays 

The output varies daily, but it can be like followings.

 -TODAY- Someone 3          (05-06 AD)
  5 days Friend 1           (01-29 BS)
165 days Friend 2           (07-02 BS)
177 days MINE               (07-14 BS)
214 days Brother            (12-06 AD)
243 days Mom                (09-20 BS)
294 days Friend 4           (11-12 BS)
340 days Someone 1          (04-11 AD)
346 days Friend 3           (01-04 BS)
351 days Someone 2          (04-22 AD)

As specified in the About Block, you can display only todays’ or put a limit. For example, display this week’s birthdays and put it in .bashrc so you can not miss it.

./birthdays -u 7

It will only show the birthdays in that limit. default upper limit is 366 days and lower is 0. Which means the limit are inclusive.

 -TODAY- Someone 3          (05-06 AD)
  5 days Friend 1           (01-29 BS)

You can just use the option -t if you want today’s birthdays only.

./birthdays -t

It will only show the birthdays in that limit. default upper limit is 366 days and lower is 0. Which means the limit are inclusive.

 -TODAY- Someone 3          (05-06 AD)

This can be set in .bashrc or .bashprofile so you’ll never miss.

Conky display wizard

Conky is a desktop monitor tool. It is excellent tool which can be informative and aesthetic at a sametime. I pesonally like it very much and have made this program primarily for this. My config for conky file contains following text part to display the birthdays in my desktop.

conky.text = [
${color e43526}BIRTHDAYS:$color
${color 00ff00}${execi 100000 ~/kool/Programming/C/birthdays/birthdays -t}$color
${color ffff00}${execi 100000 ~/kool/Programming/C/birthdays/birthdays -l 1 -u 7}$color
${color ffffff}${execi 100000 ~/kool/Programming/C/birthdays/birthdays -l 8 -u 30}$color
]

This displays the today’s birthdays in green, this week’s in yellow and this month’s in white. The birthdays are displayed in ascending order. You can’t miss a birthday as you’ll be seeing it for a month in advance.

Date conversion tool for Python

The functions inside this code can be used as date conversion tools, in C you can just use the functions. If you make a shared library, you can then use it from python. The .so file can be made like this.

gcc -shared -o libbdays.so -fPIC convertADBS.c

then you can load that file in python from ctypes. You have to go some extra length to make structure data type as used by the c code, so I’m planning to do this in my spare time. But it is definitely useful.

The syntax for loading the shared library is follows:

import ctypes

dl = ctypes.cdll.LoadLibrary("./libbdays.so")

Then make a Date class like the one from C, we can use this as the datatype to use in functions.

AD = 0
BS = 1
class Date(ctypes.Structure):
    _fields_ = [
	  ("year", ctypes.c_int),
	  ("month", ctypes.c_int),
	  ("day", ctypes.c_int),
	  ("type",ctypes.c_int)
    ]
    def __repr__(self):
	  return f'{self.year}-{self.month:02d}-{self.day:02d} ' + ('BS' if self.type else 'AD')

Now you can use that Date class to construct the date, and convert it.

d = Date(1997,10,20,AD)
dl.convertADBS.restype = Date
conv = dl.convertADBS(ctypes.byref(d),BS)
print("Converted: ",conv)
#You can also get current dat
dl.getCurrentDate.restype = Date
td = dl.getCurrentDate()
print("Today: ",td)
print("Today: ",dl.convertADBS(ctypes.byref(td),BS))
Converted:  2054-07-04 BS
Today:  2020-05-06 AD
Today:  2077-01-24 BS

Date conversion CLI

The program convert can convert between the dates in the CLI itself. Although it has limited functionality than the overall shared library would have. You can just pass the date in YYYY/mm/dd format with A for AD and B for BS and it’ll convert it to other.

Here is the usage instructions.

./adbs-convert

#+RESULTS[69f14a4dff7461671d5b113957b70d1ebfcbb209]:

Usage: ./adbs-convert YYYY-MM-DD {A|B}

YYYY-MM-DD is date in that format.
{A|B} AD or BS, automatically assumes conversion to another.

Pass - as argument if you want current date in BS.

So basically:

./adbs-convert 2022-5-8 AD

#+RESULTS[c4a15c393e683f9632922f55b0452c956c317229]:

2079-01-25 BS

Remind Input file

Remind is a program to manage your reminders, it has a really sophisticated syntax that I like. You can generate remind input files from birthdays that you have. Know that it’ll only generate the file for entries that you have for one year in advance. so if the events are already happened this year it’ll generate the entries for next year.

Just use -r flag in the program and you’ll get a remind input formatted output, you can redirect that to any file and pass that to remind.

Aknowledgement

The BS and AD conversion codes are copied and slightly modified from the Bibek Panthi’s Repository. Without it, I’d not have been able to support the BS date format.

As for the idea, I nearly forgot the birthday of my friend, so some credit goes to him.