Last active
May 28, 2023 13:20
-
-
Save tejavarma-aln/306db4fbbd33465130c23ce3061d0011 to your computer and use it in GitHub Desktop.
Fetch Ledgers with python from tally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ENVELOPE> | |
<HEADER> | |
<VERSION>1</VERSION> | |
<TALLYREQUEST>EXPORT</TALLYREQUEST> | |
<TYPE>COLLECTION</TYPE> | |
<ID>List of Ledgers</ID> | |
</HEADER> | |
<BODY> | |
<DESC> | |
<STATICVARIABLES> | |
<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT> | |
</STATICVARIABLES> | |
</DESC> | |
</BODY> | |
</ENVELOPE> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import request package | |
#import package to parse xml response | |
import xml.etree.ElementTree as Et | |
#tally ip and port | |
url = "http://localhost:9000" | |
#XML body to send - Payload | |
data = "<ENVELOPE><HEADER><VERSION>1</VERSION><TALLYREQUEST>EXPORT</TALLYREQUEST><TYPE>COLLECTION</TYPE><ID>List of Ledgers</ID>" | |
data += "</HEADER><BODY><DESC><STATICVARIABLES><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT></STATICVARIABLES></DESC></BODY></ENVELOPE>" | |
#make request | |
request = requests.post(url = url,data=data) | |
#parse response | |
response = request.text.strip().replace("&","and") #replace special char & | |
responseXML = Et.fromstring(response) | |
#loop through xmlnodes and get ledger names using Xpath | |
for data in responseXML.findall('./BODY/DATA/COLLECTION/LEDGER'): | |
print(data.get('NAME')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment