Yota-script or save with Yota cross-platform
Good day, dear harazhiteli.
A couple of months ago, civilization in the form of Yota reached our city. After a quick inspection of your personal account and finding out that the tariffing works up to a minute, an automated itch appeared :) There was another topic that turned up. We saved Internet costs from Yota and started. The main problem that I wanted to solve was to allow me to manage my tariff from the command line (for example, using crontab) cross-platform since I myself have been living under Arch Linux for a long time as the main operating system.
Having some experience with various frameworks for testing web-pages, I rushed for the familiar Selenium, but I thought that it would be desirable to do something simpler and more interesting. I wanted to try something new.
So, we need a headless browser with some kind of API. Candidates:
Strictly speaking, the first two are nodejs bindings for Selenium, but they were worth a try. As a result, the prototype of the application was written, but it turned out too complicated and cumbersome. Then Zombie.JS was tested, but alas, something went wrong after successful authorization - the cabinet page did not want to render at all. As a result, the choice fell on PhantomJS.
After a little analysis of the personal account page, it turns out that the speed slider is very simple. We open the extensive documentation on PhantomJS, take the first example that comes across and modify it for ourselves:
The result was a modest script that is conveniently located here https://github.com/linx56/yota-script .
PhantomJS is cross-platform software, so the proposed solution should work wherever it can run.
The yota-script call looks something like this:
Example:
From time to time, tariff switching falls off over time. The bug is unstable, it goes away by itself. You can use the parameter for debugging
At the moment, this script just works on crontab since I have a very predictable internet usage schedule. However, there is no limit to perfection and I'm thinking of writing a simple analyzer of the occupied band in order to switch the speed based on the need for it. Suggestions and comments on how best to implement this are accepted with pleasure.
A couple of months ago, civilization in the form of Yota reached our city. After a quick inspection of your personal account and finding out that the tariffing works up to a minute, an automated itch appeared :) There was another topic that turned up. We saved Internet costs from Yota and started. The main problem that I wanted to solve was to allow me to manage my tariff from the command line (for example, using crontab) cross-platform since I myself have been living under Arch Linux for a long time as the main operating system.
We select the ingredients
Having some experience with various frameworks for testing web-pages, I rushed for the familiar Selenium, but I thought that it would be desirable to do something simpler and more interesting. I wanted to try something new.
So, we need a headless browser with some kind of API. Candidates:
Strictly speaking, the first two are nodejs bindings for Selenium, but they were worth a try. As a result, the prototype of the application was written, but it turned out too complicated and cumbersome. Then Zombie.JS was tested, but alas, something went wrong after successful authorization - the cabinet page did not want to render at all. As a result, the choice fell on PhantomJS.
Work algorithm
After a little analysis of the personal account page, it turns out that the speed slider is very simple. We open the extensive documentation on PhantomJS, take the first example that comes across and modify it for ourselves:
- load login page
- fill in the username / password fields
- click on the login button and wait until authorization occurs
- we get a list of tariffs
- looking for the desired tariff
- submit form.
The result was a modest script that is conveniently located here https://github.com/linx56/yota-script .
Yota-script features
PhantomJS is cross-platform software, so the proposed solution should work wherever it can run.
The yota-script call looks something like this:
phantomjs yota.js your_login your_password [command] [parameter]
Available commands:
check
- the default command, which can be omitted, will show the current conditions and the remainder in days switch
- activate the tariff, the required parameter is speed, one of the results of the command list
list
is a list of parameters switch
with descriptions Example:
phantomjs yota.js your_login your_password switch 5.0
Switch the tariff to 5 MbpsLimitations and Known Issues
From time to time, tariff switching falls off over time. The bug is unstable, it goes away by itself. You can use the parameter for debugging
--debug=yes
. I also think that it will not be amiss to warn that the actions performed by this script are completely legal, however, at any moment, the position of Yota may change.Development plans
At the moment, this script just works on crontab since I have a very predictable internet usage schedule. However, there is no limit to perfection and I'm thinking of writing a simple analyzer of the occupied band in order to switch the speed based on the need for it. Suggestions and comments on how best to implement this are accepted with pleasure.