Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Prerequisite: Python 3 above.

To run this script, CSV file is needed(parameters for the script/customers that will get the ontime)

  • Create a .csv file and put all the CustomersID that you need to add ontime.
    1. CSV file with the account id as the first column of each line. All other columns will be ignored.
    2. The first line will be processed as any other line (so it should not be a header containing the labels, but contain an account as the others).
    3. Sample .csv file here:

...

-You can get the list of CustomerId per shop on CRM>Application>AdvanceFilter, in this case, Goma shop

...

Important:
If all devices that receive time should be enabled, the NGU should be configured to enable devices with the specified time that's being added to the accounts. This will also affect other customers.(CRM>Settings>Payment and Gracetime>Minimum payment time)

  • To be configured before each execution

...

  • You will see if the script is working if it’s displaying the response code 201

...

  • If the file is too big ex. sample file contains 3000 customersID, what can we do is divide the file into 3
    Ex. sample1.csv, sample2.csv, and sample3.csv -each .csv file now contains 1000customer each, then you can run the script for the 3 .csv:
    python3 script.py sample1.csv
    python3 script.py sample2.csv
    python3 script.py sample3.csv

  • The script will create another generate two file once executed, .csv_error and .csv_success
    if there are errors you will see the errors on the .csv_error file and you see all success on .csv_successThe one with the errors can be used as an input for another execution.

...

Code Block
#!/usr/bin/env python3
import csv
import sys
import requests

# To be configured before each execution
amount = 5 * 3600 * 24
custapi_location = 'https://customerapi.bboxx.co.uk/v1/BDRC'
token = ''


input_fname = sys.argv[1]
input_file = open(input_fname, 'r')
success_data = open(f'{input_fname}_success', 'w', buffering=1)
error_data = open(f'{input_fname}_error', 'w', buffering=1)

input_data = csv.reader(input_file)
for i in input_data:
    payload = {
        'amount': amount,
        'type': 'manual',
        'reason': 'other'
    }
    account_id = i[0]
    headers = {'Authorization': f'Bearer {token}'}
    request_url = f'{custapi_location}/accounts/{account_id}/payg_transactions'
    r = requests.post(request_url, json=payload, headers=headers)
    print(account_id, r.status_code)
    if r.status_code >= 200 and r.status_code < 300:
        success_data.write(account_id+'\n')
    else:
        error_data.write(account_id+','+str(r.status_code)+'\n')
success_data.close()
error_data.close()

...