Subj : JSON database To : Kirkman From : echicken Date : Fri Sep 26 2014 05:32 pm Re: JSON database By: Kirkman to All on Fri Sep 26 2014 14:59:39 Ki> Right now I'm just having the Python script overwrite the .json file. Ki> Problem is, it doesn't seem like this is enough. In my tests, when the Ki> door requests data from the json service, the data it gets is old. I believe that the JSON service only reads from that file when loading a DB module (which happens when the service is started/restarted, possibly when a given module is reloaded via json-svc-ctrl.js.) Ki> So do I need to make my Python script somehow tell Synchronet to re-fetch Ki> the data from the .json file once it has written a new version? If so, how Ki> do I do this? There may be an easier way to do this, however I would suggest the following: Create a script named "service.js" residing in the path for this module that you specified in json-service.ini. This script will be loaded automatically by the JSON service when it loads this module. Instead of having your Python script overwrite the JSON DB file, have it save its JSON output to some other file. The following would monitor that file for a change in timestamp: load("json-client.js"); var jsonClient = new JSONClient("localhost", 10088); // adjust accordingly var theFile = "/path/to/json/file/from/python/script"; var utime = file_date(theFile); while(!js.terminated) { mswait(5); if(file_date(theFile) == utime) continue; utime = file_date(theFile); var f = new File(theFile); f.open("r"); var stuff = JSON.parse(f.read()); f.close(); /* The next part depends on how your DB is laid out, but at this point you can copy values from 'stuff' into your DB */ } jsonClient.disconnect(); Obviously this could be improved in various ways, but that should get you started. (Checking that the file exists and is openable / opened, etc. would be suggested improvements.) --- echicken electronic chicken bbs - bbs.electronicchicken.com - 416-273-7230 þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com .