How to Run A Python Script from tally using tdl and get result

Discussion in 'Requests' started by sattam, Apr 9, 2023.

    
  1. sattam

    sattam Active Member


    Dear experts please solve this issue

    [Button:SatRetStat]
    Title: "Return Status"
    Key: Alt + S
    Action: Call: DownloadFile and Display Report

    [Function:DownloadFile and Display Report]

    Local Formula:isExeExist: $$IsFileExists:"E:\TallyPrime\Get Return Status in xml.py"
    090: IF:mad:isExeExist
    ;100: Exec Command Ex: "C:\Windows\py.exe"
    105: Exec Command Ex: "E:\TallyPrime\Get Return Status in xml.py"
    ;110: Display:Return Filling Stat Report
    150: Else
    160: Msg Box:ERR:"Supported File Does not exist "
    170: ENDIF
     


  2. Himanshu-2002

    Himanshu-2002 Active Member


    I think you can use DLL instead of Python but You can't make dll out of Python So, either make code in c#/c/c++ or maybe you can use Cython to compile Python code as dll

    Note: I haven't compiled Python into dll but As per my understanding, It'll work
     


  3. sattam

    sattam Active Member


    0% knowledge in dll and 1% knowledge in python :););):(:(:(:):):):):)
     


  4. Himanshu-2002

    Himanshu-2002 Active Member


    Can you tell me what you do in py.exe or Like what exact result you expect from it?
     


  5. Himanshu-2002

    Himanshu-2002 Active Member


    If you are expecting some file from py.exe then You can do it like this

    For your Python app:

    1. In your Python code, ensure that the expected file does not exist and delete it if it does.
    2. Complete your task and write the result into the file.

    For your TDL code:

    1. Use a while loop to wait until the Python app generates the file.
    2. Once the file exists, you can perform tasks with the file using TDL code.
    3. You can use the $$IsFileExists function to check for the existence of the file in the while loop.

    Example:
    [function:dotaskafterfileexist]
    000:While:NOT ($$IsFileExists:"C:\1.txt")
    010:End while
    ;;;After this line, you can perform tasks with the file
    020:Exec Command Ex: "E:\TallyPrime\Get Return Status in xml.py"
     


  6. Himanshu-2002

    Himanshu-2002 Active Member


    BTW DLL is very simple...just think of it like an exe...just that you can't run it directly like exe.

    Most Probably Above thing will resolve your issue but if it doesn't then you can ping me...will help you
     


  7. Sai Vineeth

    Sai Vineeth Active Member



  8. sattam

    sattam Active Member


    ***I have python script which convert an api json response into a xml file successfully which store in my desctop location.
    ***now from tally I want to run that py script by using of tdl code.
    ***while successfully run that py script from tally its create a xml file which contains data of that api json responce and then I show this into tally report
     


  9. sattam

    sattam Active Member


    please correct this tdl code to run my py script from tally

    [Button:SatRetStat]
    Title: "Return Status"
    Key: Alt + S
    Action: Call: DownloadFile and Display Report

    [Function:DownloadFile and Display Report]

    Local Formula:isExeExist: $$IsFileExists:"E:\TallyPrime\Get Return Status in xml.py"
    090: IF:mad:isExeExist
    ;100: Exec Command Ex: "C:\Windows\py.exe"
    105: EXEC COMMAND : C:\Windows\py.exe : E:\TallyPrime\Get Return Status in xml.py
    110: Display:Return Filling Stat Report
    150: Else
    160: Msg Box:ERR:"Supported File Does not exist "
    170: ENDIF
     


  10. Himanshu-2002

    Himanshu-2002 Active Member


    I think you should convert your py script into exe and then run exe from tdl... because In user machine python may not be installed which will create issue for you.

    You can just do a Google search for how to convert python to exe... you'll get it
     


  11. Himanshu-2002

    Himanshu-2002 Active Member



  12. sattam

    sattam Active Member


    it works fine

    105: EXEC COMMAND : "C:\Windows\py.exe" : "E:\TallyPrime\GetReturnStatusinxml.py"
     


  13. Himanshu-2002

    Himanshu-2002 Active Member


    Hmm, It works fine because you have Python installed but If it wasn't then it will create an issue

    Anyway, You can use the while loop to check for file and use it
     
    sattam likes this.


  14. sattam

    sattam Active Member


    but now the problem is in my py script there is gstin as variable every time I have to change the gstin in my script then run the script
    how can we pull the party gstin from tally into my script
    the button
    [Button:SatRetStat]
    Title: "Return Status"
    Key: Alt + S
    Action: Call: DownloadFile and Display Report

    this button is in ledger master
     


  15. Himanshu-2002

    Himanshu-2002 Active Member


    there is something known as arguments in Python...
     


  16. sattam

    sattam Active Member


    if this issue resolve then I have to convert the py script to .exe file
     


  17. sattam

    sattam Active Member


    this is my py script

    import requests
    import json
    import dicttoxml

    gstin = '08ABAPM2523R1ZE'
    url = f"http://sheet.gstincheck.co.in/check-return/my api key/{gstin}"

    response = requests.get(url)
    data_dict = json.loads(response.content)
    xml_data = dicttoxml.dicttoxml(data_dict)
    with open('data.xml', 'wb') as f:
    f.write(xml_data)
     


  18. sattam

    sattam Active Member


    please himanshu ji you can solve this.
    in variable gstin I want automatically tally ledger gstin
     


  19. Himanshu-2002

    Himanshu-2002 Active Member


    import sys
    import requests
    import json
    import dicttoxml

    gstin = sys.argv[1]
    url = f"http://sheet.gstincheck.co.in/check-return/my api key/{gstin}"

    response = requests.get(url)
    data_dict = json.loads(response.content)
    xml_data = dicttoxml.dicttoxml(data_dict)
    with open('data.xml', 'wb') as f:
    f.write(xml_data)

    You can do it like this
     


  20. Himanshu-2002

    Himanshu-2002 Active Member


    Post conversion of this script into exe, you can pass gstin like this

    1. Open CMD
    2. "path\to\script.exe" "gstin"
     


  21. Himanshu-2002

    Himanshu-2002 Active Member


    From TDL, Like this

    [Function:test]
    000:exec command:"c:\script.exe":"08ABAPM2523R1ZE"
     
    sattam likes this.


  22. sattam

    sattam Active Member


    please explane how to do this and what is sys.argv[1]
     


  23. Himanshu-2002

    Himanshu-2002 Active Member



  24. sattam

    sattam Active Member


    Many many thanks to Himanshu ji and Sai Vineeth ji for your help
    I have completed the .exe file and it works fine now
    learning new things is always pleasure
    thanks himanshu ji again
     


Share This Page