Implementing Conditions?

When I used Notion Databases I loved that I was able to set conditions to automate certain things. For example I am learning sth and have problems understanding it, so I want to see it again tomorrow - I set the hashtag to “bad” or sth then the targeted date would be tomorrow.
This could be also used for spaced repetition based on the created date.

2 Likes

Hey isaiur,
you could definitely write something like this using the API (just saying)…
But the easier approach is to just filter by the date and then add a tag to all cards you’d want to revise.
I hope that helps in someway.
Johannes

1 Like

Hi Johannes,
thanks for the advice. Good idea with the API - I’m currently learning how to use APIs and how to code with Python. I will definitely look into this - on my to do list is also learning how a script or API can run automatically on a specific time. I started using the iOS Shortcuts for that and last week I managed it to call the API via Python so I think that could be the next step of practicing.

1 Like

Hey isaiur,
love to hear that you’re also getting into the API.
If you want to do that approach I would suggest you’d make a cards/get/select to get all the cards made yesterday. Then iterate with the cards/get/specified request and using the cards/update patch add a certain tag. I that would probably be the easiest.

1 Like

Thanks. That would be my approach, too. I think it is necessary to put it in a for loop I guess? Like “go through all cards that fits into the filter ‘created yesterday’ and having a specific tag.
For automation I stumbled upon the datetime package but I think I need sth additional - last week I started a little test server (Apache) on my raspberry pi at home.

1 Like

Before figuring out how to automate this I could apply a parent on each of that cards and run the script manually every morning and maybe open the parents card url as a last step of this script.

1 Like

I think it would be easier if you’d user the built in iter() function of python.

mylist = [1, 2, 3, 4]
myiterator = iter(mylist)
print(next(myiterator)) # prints 1
print(next(myiterator)) # prints 2

or you do just use for loops

mylist = [1, 2, 3, 4]
for i in mylist:
  print(i) # 1, 2, 3

Also just asking why an Apache server?

1 Like

Thanks!
The Apache was more as a side note. I want to start with Django and for automated API Calls I think that I have to store the script on a server or a device which is on for 24/7 … but I don’t know - this is something I don’t have any knowledge so far.

1 Like

For that use case server-less functions are also very interesting since they are free if you look at the scope of the project and you’d never have to host anything. But they are also a bit more advanced.

1 Like

Do you have something in mind or could recommend a server-less service? Is it Heroku for example?

1 Like

You’d probably want to use either netlify or google cloud because both have a free tier that is more then enough for the project (once a day running the service to check). But there are way more just choose the one you like the interface and library the most.

1 Like

I’ll have a look! Thank you so much for the advice and help :slight_smile:

1 Like

Yesterday I wrote a Python script that first filters all cards with a specific tag and updates each targeted date via for-loop.
However, I have problems regarding the targeted date.
First I had imported the datetime module from Python and created variables for yesterday, today and tomorrow. Then I filter for cards with the tag created in a period of yesterday and update the targeted date with tomorrow’s variable.

data_last = {
  "filter_group": {
    "operator": "and",
    "filters": [
      {
        "type": "tag",
        "operator": "equals",
        "arg": "🔴 - bad"
      }
    ],
  },
  "created_when": {
    "from_when": (f'{yesterday}T00:00:00'),
    "to_when": (f'{yesterday}T22:00:00')
  },
  "as_list": True
}
for card in response_json:
    card_id = card['data']['id']
    # status = card['data']['tags'] 
    data_next = {
    card_id: {
        "data": {
            "targeted_when" : (f'{today}T07:00:00')
            }
        }
    }
    response = requests.patch(url_next, data=json.dumps(data_next), headers=headers)

First, the time is not taken over from the targeted date and furthermore, the filter also outputs cards that have the tag but were created far before the date.

Are you getting any errors in your responses? It would probably be helpful to see what {yesterday} and {today} look like, to help debug.

Also, this probably won’t fix anything, but something else that would be worth doing is sending this all as one request instead of once for every card, like this:

card_patches = {}
for card in response_json:
    card_id = card['data']['id']
    card_patches[card_id] = {
        "data": { "targeted_when" : (f'{today}T07:00:00') }
    }
response = requests.patch(url_next, data=json.dumps(card_patches), headers=headers)

This should run faster and is nicer to our servers at the same time :slight_smile:

Thanks @connor

The post request gives 200 back, the patch request 207.

This is what the variables look like:

from datetime import date, timedelta


t = date.today()
l = t - timedelta(days=1)
n = t + timedelta(days=1)

yesterday = l.isoformat()
today = t.isoformat()
tomorrow = n.isoformat()