Himalayan-Academy / Siva-Siva-App

Code Repository for the Siva Siva Mobile App
11 stars 3 forks source link

Create "books.json" file from server dbase -- jnanam #324

Open Brahmanathaswami opened 2 years ago

Brahmanathaswami commented 2 years ago

Where: /media/books/

it should be active in devhap and HAP

soapdog commented 2 years ago

@Brahmanathaswami

I don't know how or why that file is generated. Our website has access to the jnanam database, so it can simply query it, it doesn't need a JSON. SivaSiva app has a copy of the database as well, it can use that instead of a long JSON.

That JSON looks really strange, it is not designed in the way people often design JSONs. For example, there is a part of it that reads:

  " ": {
    "\"My Friend, Lord Ganesha\"": {
      "allowed_groups": "All",
      "approved_for_public": "YES",

Why are book titles quoted? Why is there an empty space as a key? Why is that an object and not an array?

Can you point me to where this JSON is used?

I can't generate it as I don't understand it.

bwmilby commented 2 years ago

@soapdog I will upload a stack that creates a template JSON file. This is going to be used in a module on Siva Siva hence the export.

If the full database is available inside the app, there may be a better way than creating the JSON file.

Look at the “book-bwm” branch to see where it will be used.

bwmilby commented 2 years ago

Also, the format will change slightly from what is there. If we use JSON then it will be similar to the stories.json file in structure (the first level). That existing file would be under the “books” key.

bwmilby commented 2 years ago

Here is the stack that will parse the tab delimited export into the file format that I'm currently using inside the module. Create_Books_JSON.livecode.zip

Here's a link to the current file: https://github.com/Himalayan-Academy/Siva-Siva-App/blob/book-bwm/modules/books/books.json

Book titles being quoted probably means that that is how they were exported from the database. They should not be quoted. Also there are other quoting issues within the current export that would hopefully be addressed by pulling the data directly from the database.

bwmilby commented 2 years ago

This might be a start of a query that could be used: select * from item where "media_type" is "text/book" and "approved_for_public" is "YES" I would structure it a little differently though. I would get the item_id, language, and title in one query to build the nav tree. Then, on the detail page I would use another query to get the data to populate that screen from the item_id.

Brahmanathaswami commented 2 years ago

I would do this:

SELECT * FROM item WHERE ( (media_type = 'text/book') OR (media_type = 'text/booklet') ) And (approved_for_public = 'YES')

232 publications

You will want to do

{ "lastUpdate": { "theTime": "1647909800" }, "books": { "Arabic": { "Our Daily Journey In Consciousness": { "allowed_groups": "All", "approved_for_public": "Y

soapdog commented 2 years ago

@bwmilby SivaSiva app has a copy of Jnanam database in it as a SQLite file and it has my old DB Lib ORM to query it (or you can use plain old RevDB calls). The database is open when the app is running, you can get the connection id to it using jnanamDB():

https://github.com/Himalayan-Academy/Siva-Siva-App/blob/nightly/models/jnanam.livecodescript#L86-L91

It is much easier than iterating over JSON when dealing with books.

bwmilby commented 2 years ago

@soapdog I spoke with @Brahmanathaswami yesterday and he does not think that is a viable solution long term. I will use that database to create the code to build the JSON file that we want and then turn it over to you to adapt it to a script that can be run via cron to pull from the actual database. My goal is to have the stack ready tonight and I will attach it to this thread.

soapdog commented 2 years ago

@bwmilby I just messaged @Brahmanathaswami on Slack. I don't think I can work on this app anymore. You both will need to implement that.

Let me say that using a JSON for that is a really bad decision. The SQLite database is faster, already there and is even already opened. There is even an ORM available that you can get an array of books in couple lines.

soapdog commented 2 years ago

The instructions to update janam.sqlite.gz are on the repo at https://github.com/Himalayan-Academy/Siva-Siva-App/blob/nightly/models/updating_jnanam.md

It is a single terminal command and it creates an up to date version of the sqlite file.

soapdog commented 2 years ago

jnanam.sqlite.gz

Here is an up to date file.