Can I set "for each number" or "while test do" or for each item in list" to fetch data from airtable and store it in TinyDB?

I am making a quiz app for my students. I have 8 tables in Airtable. Each table is a separate chapter and contains some questions. I want to fetch all the questions chapter-wise and stored in TinyDB tags. Can i do it using loops?

I have not worked with Airtable but I have used TinyDB. TinyDB is pretty easy to use once you get used to it. My suggestion is to move to just one database. You might be doing that and just didn’t say. Doesn’t make much sense to have two databases.

One of the short comings I see in TinyDB is that it isn’t a real relational database like SQLite is. But TinyDB’s Tag concept keeps things really simple and I like that.

Here’s what I do to have different classes or categories of items in TinyDB. You can do the same for chapters. I split the Tag string using the @ char as a separator. For your setup I’d do it like this with the Tags:

chapter1@question1
chapter1@question2
chapter2@question1
chapter2@question2

You get the idea. So now TinyDB contains all of your chapters and all of your questions.

In a loop, you get all the Tags and with each item (the full tag) in the loop, you do a text split on the @ char and then you can check index 1 (for chapter1) or check index 2 for question1, etc.

Here I’m using my code but commented over it using your chapter and question structure to show you how easy this is to do using TinyDB.

(1) using for each, you grab the Tag string.
(2) get the actual question the tag is associated with. In this case, get the actual question1.
(3) split the tag.
(4) now you can access any part of the tag using an index. So index 1 == chapter1, index 2 == question1. Once you get index1 you can check for chapter1 questions only. or chapter2 questions only, etc. The beauty here is that you can have other unrelated items and filter on them. In my app I have setup records and other categories so I can filter on anything in my TinyDB.
(5) is not so important to you but shows how to remove some text from the record value (in your case this would be the actual question text).

Thanks for your response @ralphfreshour. I am using two databases because i will change questions frequently from airtable. Students need not to be connected to the internet all the time so the app will get updated questions at the start. Hope I have cleared my idea?

@ralphfreshour could you please check the blocks and help me out?

I added my block example to help show you visually how to loop through TinyDB.

While I have not used Airtable, you should be able to loop through Airtable and write it’s data to TinyDB.

Maybe someone else can jump in and help with the Airtable part. Let us know how you get on with this.

Can you attach your Airtable file so I can see it’s data. I have not used Airtable but I will look at your data and try to help you.

Thanks dear @ralphfreshour. I am stuck at only one thing that how can i pause the loop until some condition is met? Looping using tinyDB is different from Airtable.

From what I can search for, delaying is not possible in a loop or would be very difficult/complex. Why do you need to delay? If your questions are up to date in Airtable, your students should be able to run your app and convert them into TinyDB, right? Why the need for a delay in the loop?

Another question for you: why do you need to convert into TinyDB? Why can’t you just use Airtable? Is it because Airtable is not an app component and is in the cloud?

No. Students are not always connected to the internet. They mostly use it offline

Delay is necessary as the loop will run again before the data is fetched. You can look the blocks

Questions are in my national language Urdu.

I’m building a small test app using Airtable and TinyDB to better understand what you are facing.

I think the delay request you are asking about is still not a reasonable solution. You can download the updated Airtable and import all of its records into a clean TinyDB without needing a delay. The question is: when to do the update?

The answer I’m suggesting is:

  1. Put a version number (best to make it an integer) in Airtable.
  2. In screen Initialize, fetch this version number from Airtable. Your app will already contain the last version number in TinyDB.
  3. If the app version is less than the Airtable version, then update the Text on an UpdateDatabase button: “New Database Available” else update the button Text with “Database is Current”. If there is no internet connection, simply disable this button.

Your students can then update when they have a connection, else use the question they have in TinyDB.

1 Like

I needed exactly this type of app. I am waiting…

It’s just a test app (not a polished production app) that imports Airtable data into TinyDB. I will be happy to upload it for anyone to look at. Give me a day or two to finish it up and I will upload here for you.

1 Like

I ran into the same problem you did regarding the need for a delay when loading Airtable data into TinyDB. Without actually trying to do this, I didn’t see or understand the need for the delay.

My test app uses a while test block to attempt to wait for the Airtable got cell method to finish, but the while test loop apparently consumes all of the cpu attention. I was not able to figure out how to break the loop using a change in variable values.

In addition, any UI painting isn’t done while in the loop because the loop consuming all of the cpu resources. In my code block below you can see I try to break the loop using another button click but that fails to break the loop. I was only successful in breaking the loop from changing the variable while inside the loop. That works but doesn’t solve my problem.

At this point I’m stumped. I do think if we had some kind of method call to the OS to give other resources a chance to run, this would work. We may have such a call but I am not aware it. Other languages such as C# under Visual Studio has such a call while in a loop so you can give some attention to other UI components that need to paint to show screen updates. My Text_Box_Debug doesn’t paint while inside the loop because the loop is consuming all the attention (so I have it disabled at the moment).

2019-05-10_093943