Created
June 6, 2018 22:32
-
-
Save toxicantidote/6f4996c3e30e7523c4f80729056395be to your computer and use it in GitHub Desktop.
Checks Nayax for VPOS serials not assigned to the current user
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
## Gets VPOS serials not owned by the current account. Copy in your auth | |
## parameters for an existing valid session below. | |
## Nayax preset ID | |
preset_id = '' | |
## Auth cookie value | |
auth_cookie = '' | |
## RVC cookie value | |
rvc_cookie = '' | |
## GA cookie value | |
ga_cookie = '' | |
## GID cookie value | |
gid_cookie = '' | |
## Validation token | |
validation_token = '' | |
### | |
import requests | |
import re | |
from multiprocessing.pool import ThreadPool | |
import time | |
cookies = {'Persist': '%3Croot%3E%3Cuser_data%20status_id%3D%221%22%20num_of_rows%3D%2220%22%2F%3E%3C%2Froot%3E', 'language_id': '7', '_ga': ga_cookie, '_gid': gid_cookie, 'NVAuthCookie': auth_cookie, '_RVC': rvc_cookie} | |
headers = {'X-Nayax-Validation-Token': validation_token} | |
url = 'https://my.nayax.com/dcs/public/facade.aspx?responseType=json&model=operations/machineDynamicStatus&action=Machines_Dynamic_Status&status_id=1&num_of_rows=10000&user_preset_id=' + preset_id | |
print('Making machine list request..') | |
request = requests.post(url, cookies = cookies, headers = headers) | |
print('Processing response..') | |
vpos_serials = [] | |
for line in request.text.split('\n'): | |
regex_name = re.search(r'\"operator_identifier\":\s\"(.+)\",', line) | |
regex_vpos = re.search(r'\"vpos_serial\":\s\"(.+)\",', line) | |
regex_dtu = re.search(r'\"device_number\":\s\"(.+)\",', line) | |
if regex_name: | |
print('-' * 10) | |
print('Name: ' + regex_name.group(1)) | |
if regex_vpos: | |
vpos = regex_vpos.group(1) | |
print('VPOS serial: ' + vpos) | |
vpos_serials.append(vpos) | |
if regex_dtu: | |
print('DTU serial: ' + regex_dtu.group(1)) | |
print('Found ' + str(len(vpos_serials)) + ' VPOS serials') | |
url_vpos_prefix = 'https://my.nayax.com/dcs/public/facade.aspx?model=administration/PresetsApplying&action=VPOS_Search_TO_Move&searchVPOS=' | |
vpos_transfer = [] | |
vpos_count = 0 | |
vpos_total = len(vpos_serials) | |
pool = ThreadPool(processes=25) | |
def check_serial(serial): | |
global url_vpos_prefix, vpos_transfer, vpos_count, vpos_total | |
request = requests.post(url_vpos_prefix + serial, cookies = cookies, headers = headers) | |
regex_info = re.search(r'result="SUCCESS">(.+)<\/metadata>', request.text) | |
info = '' | |
if regex_info: | |
regex_root = re.search(r'<root>', regex_info.group(1)) | |
info = regex_info.group(1) | |
if regex_root: | |
pass | |
else: | |
vpos_transfer.append(serial) | |
print(serial + ' needs transfer!') | |
else: | |
print(serial + ' could not check!') | |
vpos_count += 1 | |
print('Checked ' + str(vpos_count) + ' of ' + str(vpos_total) + ' (' + serial + ') [' + info + ']') | |
children = [] | |
for serial in vpos_serials: | |
children.append(pool.apply_async(check_serial, (serial, ))) | |
print('Waiting for children to finish..') | |
for child in children: | |
child.get() | |
print('VPOS serials we need transferred to us:') | |
for ser in vpos_transfer: | |
print(ser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment