I need some assistance on where to go next

Good day everyone,
I am trying to create an app that allows a user to create their custom reminders (they can give it a name, date, time, and choose a sound). I also have a button where they can choose to view their existing reminders when they are finished. I have figured out how to get the input of the user, but my problem is this, how do i store this information and :

  1. it can be added in a list in the view existing reminders window(listed by name)
  2. a list of the current reminders can be displayed to the user on startup
    1. if the user is on their computer at the time set for notification, a pop up will appear notifying them.

You can store it in file or in a database.

The latter is probably more suitable.

Sqlite comes to mind.

Karsten

I wrote a similar program a while ago. My program loads and saves the alarm settings from/to an XML file using the Python elementtree module.

Here is an example test file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated for AlarmClockApplication -->
<alarms>
  <alarm>
    <name>Start laundry</name>
    <time_due>08:00:00</time_due>
    <repeat_days>
      <day>Mon</day>
    </repeat_days>
    <enabled>True</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/alarm_1.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
  <alarm>
    <name>Formula 1</name>
    <time_due>13:55:00</time_due>
    <repeat_days>
      <day>Sun</day>
    </repeat_days>
    <enabled>False</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/the_chain.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
  <alarm>
    <name>Iron laundry</name>
    <time_due>15:45:00</time_due>
    <repeat_days>
      <day>Mon</day>
    </repeat_days>
    <enabled>True</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
  <alarm>
    <name>Start dinner</name>
    <time_due>16:35:00</time_due>
    <repeat_days>
      <day>Sun</day>
    </repeat_days>
    <enabled>False</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
  <alarm>
    <name>Blood Pressure</name>
    <time_due>16:50:00</time_due>
    <repeat_days>
      <day>Tue</day>
      <day>Thu</day>
      <day>Sun</day>
    </repeat_days>
    <enabled>False</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
  <alarm>
    <name>Bath</name>
    <time_due>18:55:00</time_due>
    <repeat_days>
      <day>Tue</day>
      <day>Thu</day>
      <day>Sun</day>
    </repeat_days>
    <enabled>True</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
  <alarm>
    <name>Blood Pressure</name>
    <time_due>19:55:00</time_due>
    <repeat_days>
      <day>Mon</day>
      <day>Wed</day>
      <day>Fri</day>
      <day>Sat</day>
    </repeat_days>
    <enabled>False</enabled>
    <sound_file>/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav</sound_file>
    <loop_sound>True</loop_sound>
  </alarm>
</alarms>

I guess you can try PREFS, a Python library to store settings (in a dictionary-like structure inside a text file).
It would be something like:

import prefs
 # Then you can fit the reminders in that dictionary the key being the reminder's name, the value could be another dictionary with more information.
reminders = prefs.Prefs({}, path="reminders.prefs")
reminders["Finish some work"] = {"hour": "14:34", "days": "monday", "notif": "notif.mp3"}

Then a new file will get created called reminders.prefs that looks like:

#PREFS
Finish some work=>
    hour="14:34"
    days="monday"
    notif="notif.mp3"

Read it’s documentation for more https://patitotective.github.io/PREFS/docs

1 Like

This answer in PREFS format would be:

#PREFS
Start laundry=>
    time_due="08:00:00"
    repeat_days=["Mon"]
    enabled=True
    sound_file="/home/richardt/Applications/alarm_clock/sounds/alarm_1.wav"
    loop_sound=True
Formula 1=>
    time_due="13:55:00"
    repeat_days=["Sun"]
    enabled=False
    sound_file="/home/richardt/Applications/alarm_clock/sounds/the_chain.wav"
    loop_sound=True
Iron laundry=>
    time_due="15:45:00"
    repeat_days=["Mon"]
    enabled=True
    sound_file="/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav"
    loop_sound=True
Start dinner=>
    time_due="16:35:00"
    repeat_days=["Sun"]
    enabled=False
    sound_file="/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav"
    loop_sound=True
Blood Pressure=>
    time_due="16:50:00"
    repeat_days=["Tue", "Thu", "Sun"]
    enabled=False
    sound_file="/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav"
    loop_sound=True
Bath=>
    time_due="18:55:00"
    repeat_days=["Tue", "Thu", "Sun"]
    enabled=True
    sound_file="/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav"
    loop_sound=True
Blood Pressure=>
    time_due="19:55:00"
    repeat_days=["Mon", "Wed", "Fri", "Sat"]
    enabled=False
    sound_file="/home/richardt/Applications/alarm_clock/sounds/alarm_2.wav"
    loop_sound=True
1 Like

I hadn’t come across prefs before, it looks pretty neat.

Another alternative would be to read and write JSON files using the jsonpickle package.

It allows you to pass it arbitrary objects and it saves the object’s attributes, including any other objects that it contains.

e.g.

        with open(pathname, 'w') as o_file:
            # Pass keys=True so that integer keys aren't coerced into strings
            o_file.write(jsonpickle.encode(journal_month, keys=True, indent=1))

…and…

        with open(pathname, 'r') as i_file:
            journal_month = jsonpickle.decode(i_file.read(), keys=True)

In this example, a JournalMonth object contains a year (int), a month (int) and a dictionary containing JournalDay objects, using day of month (int) as keys. Each JournalDay object contains a day of month (int), a text string and a string of style values.

The jsonpickle package is able to save and load these objects without the programmer needing to tell it any of the details. The resulting files are also quite easy to read.

More information on jsonpickle: https://jsonpickle.readthedocs.io/en/latest/

Thank you all for your responses. This is my first time coding (I had only dipped in Pascal in my high school days), but it is my first time with python. I have come a far way and I honestly appreciate your help. My goal is to make apps that are helpful to all and especially accessible to screen reader users. God bless you all.

2 Likes

I created PREFS because I saw so many people doing their own ‘preferences system’ using json and the code got sort of a mess because you needed to open the file so many times and some people forget to close the file. Also PREFS offers the possibility of reading datas (you can write your own PREFS file to save the color scheme) when your application was built with PyInstaller.

1 Like

If using text files rather than a database I would choose to stay with standard formats.

The yaml format (pyyaml: https://pyyaml.org/) is less verbose than json so it might be preferable in some cases to json for user-editable config-files.

1 Like