In the process of working on current projects, a situation arose when “suddenly” the site of the Russian Postings tracking site stopped being parsed. On the Internet, even a little bit brooded over the "terrible" new protection, etc. In the same Internet, information then surfaced, that Russian Post has the same API. Not quite human (ie, according to the SOAP protocol), but some exist and someone even supposedly uses it. I informed the chief, the chief wrote a letter to the Russian Post (electronic, surprisingly) and it turned out - yes. All this really is and seems to even work. Apparently created a service even
then .
Under the cut there will be a link to the client’s working class (in
python ) to the API of the Russian Post and some details of working with it.
For whom
So, you are tracking a lot of items and, of course, coped with the current problem of parsing the page for issuing tracking of the Russian Post site (hereinafter referred to as “mail”), but it is logical to assume that this was not the last attempt and could be worse next time. What to do? How to secure the future of your service / company?
You guessed it, but I will say out loud - You need to connect to the API!
')
This is where the fun begins. This service is not available to everyone, but if you (the company) have a contract with the mail, then the chances of getting the coveted access are very large. In the regulations of the service, which is sent to the happy sub-citizens, these very sub-partners are referred to as the “federal client.” I don’t know here - whether it is a special status, or so they call it all those who have an agreement with the mail ...
How to access
In general, take a soap (preferably more electronically) and in a free form write to
fc@russianpost.ru , who you are, that you need “access to track status of the RPO under the SOAP protocol” and why you need it. For this they will send you a regulation, in which there will be a questionnaire to be filled in,
in the house that Jack built to sign and supervise with the stamp of your office and send, in the form of a scan, backwards.
After that, you will be given ... a login and password (which do not activate until you complain that you are not plowing anything, well, or it is just that we are not so lucky ...).
How to work
So it's time to go on the attack. Forking / Cloning:
git://github.com/qnub/ru-post-soap-client.git
Configure (or do not configure,
see readme ). And rushed
from time import sleep from client import RuPostClient client = RuPostClient() tickets = client.make_ticket(all_my_track_numbers) sleep(900) track_statuses = client.get_tracks(tickets.keys())
Well, or something like that - further along the same readme.
Nuances
According to the regulations, requests for data on the same ticket can be made no more than once every 15 minutes and no earlier than 15 minutes after its creation.
A ticket cannot request data of more than 3000 (three thousand) tracks at a time (on the same ticket). See for yourself here. We, for example, have enough of 100 tracks, because for each track comes a lot of data in the end, depending on the conditions, it can load the system to someone ...
If you entered the authorization data correctly, and you receive an error 16 “Internal error of the data exchange service” - check if the tracking numbers are not entered correctly (clean from special characters, etc.). If it does not help, write a letter to the same address and ask to check what is wrong with them. In the end, we were simply told that the error was fixed and that's it. What was - I do not know, but it helped ...
Thank you
Thanks to the boss for allowing me to share this code with you. The technology itself has been worked out at his expense, well, I have already allocated it to the class for my own.
Enjoyable use (
apparently a couple more people are interested). Forks, pull requests, bug reports - all according to the classical github program (
link again, so as not to search).