Countdown to Events / Exams addon [Official Thread]

I also updated to Anki 2.1.42, still same problem occurs.

I’m not exactly sure why that is happening, hopefully @dae can answer / fix that. (I think this is the problem most users were having rather than the one I made a post about a few days ago, and it is extremely confusing as I cannot see a reason for it. see:
Error thread 1
Error thread 2
Error thread 3

However, as a tempory fix, you should be able to get around it by doing the following:

  1. Navigate to tools->add-ons
  2. Select the add-on and click ‘view files’
  3. Navigate to user_files/events.db
  4. Copy / move file to a temporary location (e.g desktop)
  5. Delete add-on and redownload the add-on (remember to restart Anki)
  6. Navigate to user_files once again and replace the new events.db file with the file copied / moved earlier.
  7. Restart anki and it should be working
1 Like

Hi there,

Going to preface by stating that i’m a noob at code:

I was looking at the code for this add-on, and I was wondering if it were possible to assign a color to a range of numbers? For example, if an exam is <7 days away, those numbers would be assigned a color value (red), whereas an exam that was 7-14 days away would be assigned a different color value (blue), etc.

Hi there, is there any chance you can edit the code to make the add on appear below the review heatmap? I’ve tried to rearrange the order by re-uploading the add ons and i’m still not having any luck, thank you in advance!!

Hi, this add-on is cool. I just wanted to make some CSS tweaks and I did it except for one change.

image

See, I wanna change the colour and styling of the events.
I figured out I should make changes in the define and return functions, but I don’t know how to do it. Can you please help?

Hi,
Easiest way would be to delete the bold function, and replace where the arrow is pointing with the code in the following image:

From there you can do the CSS styling however you want. Let me know if you need more help :slight_smile:

Hi, unfortunately not sure how to do this.

Bumping this as hopefully someone else will know?

Hey, sorry for troubling you again.
This is what I get. (sorry, I don’t know much coding stuff). I wanna color the days like this and add some formatting to the ‘days until exam’ part.

image

This is the code I used for the above picture

def days_between(d1, d2):
    d1 = datetime.strptime(d1, "%Y-%m-%d")
    d2 = datetime.strptime(d2, "%Y-%m-%d")
    return (d1 - d2).days


def bold(s):
    return "<b>" + s + "</b>"

def display(deck_browser, content):
    content.stats += """<br><link rel="stylesheet" type="text/css" href="{}/styles.css"/><h3 style="color: #d3ba49;display: inline-block;margin 0px 20px" >Upcoming events </h3>
    <div class="settings-btn" onclick='pycmd(\"add-new-event\");'><img src="{}/icons/settings.png"></div>""".format(
        base_url, base_url)
    sortType = config['sort']
    data = cursor.execute(
        '''SELECT * FROM events ORDER by date(date) %s''' % sortType).fetchall()
    today = date.today().strftime("%Y-%m-%d")

    for row in data:
        eventID = row[0]
        due = row[1]
        exam = row[2]
        daysLeft = days_between(due, today)
        if daysLeft < 0:
            deleteEvent(eventID)
        else:
            content.stats += """<br><b style="color:#d3ba49 ">" + str(daysLeft) + "</b>""" + " days until " + exam

Hey happy to help, so to get the first bit to work you need to change the last line of your code to this:

content.stats += """<br><b style="color:#d3ba49 ">"""+ str(daysLeft) + """</b> days until """ + exam

To style the ‘days until exam’ part this will work:

content.stats += """<br><b style="color:#d3ba49 ">"""+ str(daysLeft) + """</b><span style="white-space:nowrap;color:blue":> days until </span>""" + exam

Works fine now, thank you!

Found this comment in your reviews and totally agree with the idea: “Although this works, something like countdowns should be pinned to the top, ideally top-right or top left! It serves little purpose when it is pinned to the bottom of the page. Please add functionality to pin countdown to the top of the page.”

Thank you!

1 Like

Hi @sam

I’ve been trying to append the settings button to the bottom of the reviewer, but had no success.
This is what I have in mind:

The main reason for this customization is that, while reviewing my cards, I often have ideas about things that I have to study more, or find more information from other sources, or make cross-references between cards, etc., so it’d be great if I had the option to easily create reminders while reviewing my cards.
As I said before, I’ve been trying to do it myself, however, as my Python skills are very introductory, I wasn’t able to succeed.
So, could you, please, give directions on how I should modify the source code of the add-on so it displays the settings button both on the deckbrowser and on the reviewer?

Or maybe a button in the toolbar (like Amboss’ addon does):

I put it among the editor’s top buttons, but it returns an error message whenever I click on it.

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeat until you discover the add-on that is causing the problem.
When you’ve discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site.
Debug info:
Anki 2.1.44 (b2b3275f) Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2021-09-19 21:05:22
Caught exception:
Traceback (most recent call last):
File “aqt\webview.py”, line 36, in cmd
File “aqt\webview.py”, line 135, in _onCmd
File “aqt\webview.py”, line 580, in _onBridgeCmd
File “”, line 2, in onBridgeCmd
File “anki\hooks.py”, line 89, in decorator_wrapper
File “anki\hooks.py”, line 86, in repl
File “C:\Users\Gabriel\AppData\Roaming\Anki2\addons21\1423933177\view.py”, line 22, in myLinkHandler
return _old(self, url)
File “aqt\editor.py”, line 466, in onBridgeCmd
TypeError: init() takes 1 positional argument but 2 were given

Do you think these modifications are doable?