From 31e3c5c7edd5f0f93d196d5bd82b89fcc8cd9a3a Mon Sep 17 00:00:00 2001 From: MrWaradana Date: Fri, 31 Jan 2025 16:36:50 +0700 Subject: [PATCH] feat: add prediction to update unit transaction API --- .../__pycache__/service.cpython-311.pyc | Bin 6890 -> 8055 bytes src/plant_transaction_data/service.py | 23 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/plant_transaction_data/__pycache__/service.cpython-311.pyc b/src/plant_transaction_data/__pycache__/service.cpython-311.pyc index 51e02e30757c8ca031360296790eb52282ad1d98..323bc828e3e3df88f351666e1259c88ccdfccc42 100644 GIT binary patch delta 981 zcmZXSOHUI~6oBuYX{Xb73zQBBqyY>d3B*KQ7~%u9K?wLjP#!8xr$H*V&FyUpaViTE zcW%530&3E@!1#y>=@Qmm=pQiM=+1;y)rF=j&zV}GdXn><_nCWdX8+{RGoDv&w}XIe zZ9ZSz4D5JL`QjDdz`)>xq@G!hr3X{Xkp!Z95rai8!tYm#meL!Nf8^8e7Xq3G6axaC{CsVO;|o$$t5L`d9xO^kKLu<_=D z%3qM6y%F|>+er(C9hMIT5!8?Zzr|03LIeX4wsBw2~OjqyY`w(`N zx7Tv;X}jUbdvSr-^9CBb>uL_e{v`yitpjDw{1`eBZ zK5{11s?E|YS&?T*mKt=D^tr@tQ~w$}5AAFiaRG4=f$zpf5SJ07fIdGP15>i4V?4q+ zW8+wvKwLpwMO;H%M@%AaAf^y_dp3=@iMWNBLAYmueJ{o9B;i0Y4r z-d#Z21qdAyb_5b7C6m%4JjNCwSi`n`Dnsic+47y!8hVu@Tp>+d_sH*eswND(p<~p;)B-iSb-QHIsLuxP1~Z! iduiJjUrX5vwycm~f7ynfN?K2p?dXwuOjEJjI`|v0jLC=q delta 449 zcmexv_sW!SIWI340}ymgo0FasLl5UUoonO0!5O67z~(!Bs&l{ z1M%leK*F1WkzqPR4by_j8#zQK*YomE78Y5=R>K&~pvf}XSzKFAlex$hsO}bfacW6o zNl8(WJCLWzRwMwVib5y<5?4|wW&^Snz@SJPq?WC;ASJORwI~tDsR!cXi42odBzn0Y za7$lckuH)23QbOA65HG&CBew(K6$RR7HbMfZ1NfDNo;;VR*}c#6q)BnQ6MJBkRp(D zkqU?aX$IT!i^B#Iu69L5Kru!jF8;W=R(2Mnfgq#I0|ChotU&q$8-uv^2X+vPgF(vV Q11E^ZfJ$gg_K?>H0I2DB2><{9 diff --git a/src/plant_transaction_data/service.py b/src/plant_transaction_data/service.py index fd7dfc6..5963534 100644 --- a/src/plant_transaction_data/service.py +++ b/src/plant_transaction_data/service.py @@ -141,6 +141,29 @@ async def update( await db_session.commit() + # Get the directory of the current file + # directory_path = "../modules/plant" + directory_path = os.path.abspath( + os.path.join(os.path.dirname(__file__), "../modules/plant") + ) + + # Construct path to the script + script_path = os.path.join(directory_path, "run.py") + + try: + process = await asyncio.create_subprocess_exec( + "python", script_path, stdout=PIPE, stderr=PIPE, cwd=directory_path + ) + stdout, stderr = await process.communicate() + + # Check if the script executed successfully + if process.returncode != 0: + print(f"Script execution error: {stderr.decode()}") + else: + print(f"Script output: {stdout.decode()}") + except Exception as e: + print(f"Error executing script: {e}") + return transaction_data