Apply the extra days script
The purpose of this script is to Manually add ontime of hundreds of users using Bboxx API.
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
amount: Set the variable amount of the script to the desired time in seconds that would like to be given by this script.
custapi_location: Set the variable custapi_location to the base URL of customerAPI to be used. It should include domain, version and GEIC.
token: Obtain a token for the user that will be used to issue the time. Please note that the token should be issued by an authentication service of the specific stage (prod, staging, dev), and if using the docs to generate the token, you should ensure you're doing the request to the correct server (example: by specifying '/v1/' in servers)
Get your
Authorization
token in https://authapi.bboxx.co.uk/v1/docs/#/authentication/authenticateSet the token in the python script
Execute the script with the CSV file as a parameter: python3 script.py test1.csv
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.csvThe script will generate two file once executed, .csv_error and .csv_success
The one with the errors can be used as an input for another execution.
#!/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()
BBOXX