Python

Common Stuff ››
Parent Previous Next

GlobalErrorID

"010000": No errors.

"010041": OTP has expired.

"010xxx": Other errors.




**NOTE: All functions listed below are put into a single file functions.p


Get Record:

The purpose of this function is to retrieve the number of items in a list. It is meant to be used on APIs where the JSON output returns a list


We will first import "request" and "json" module, as we need those module for calling the API.



We will create a function getRecord, which requires 'record' to be passed in. For this function, we assume 'record' is a list

Inside the function, we will use a try clause, where we will store the length of 'record' in variable 'recordCount'

Then we will use a for-loop to store the 'record' items in variable 'acc'. If there are no error, we will return recordCount.

If there is KeyError, we will check if KeyError is '0'. If KeyError is '0', we will declare 'recordCount' equals to '1', and return recordCount.

Else, we will return '0'.




API URL:

The purpose of the API URL function is to simply return the tbank's API URL. In future, if there are any changes to the API URL, we only have to edit the URL in the functions file.



Download functions.py


Created with the Personal Edition of HelpNDoc: Free EBook and documentation generator