📜 ⬆️ ⬇️

Yota-script or save with Yota cross platform

Good day, dear habrazhiteli.
A couple of months ago, a civilization in the form of Yota reached our city. After a cursory examination of the personal account and finding out that the rating works up to a minute, an automated itch appeared :) Then the topic turned up. We save on Internet costs from Yota and rushed. The main problem I wanted to solve is to allow managing my tariff from the command line (for example, using crontab) cross-platform, since I myself live for a long time under Arch Linux as the main operating system.

We select the ingredients

Having some experience with various frameworks for testing web-pages, I was rushed for the familiar Selenium, but I thought that it would be desirable to get by with 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 binding nodes for Selenium, but it was 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 be rendered. 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 and modify it for yourself:

The result was a modest script that is comfortably located here https://github.com/linx56/yota-script .

Features yota-script

PhantomJS is cross-platform software, so the proposed solution should work wherever it can run.
The yota-script call looks like this:
phantomjs yota.js your_login your_password [command] [parameter] 

')
Available commands:

check - the default command that can be omitted will show the current conditions and the balance in days
switch - activates the tariff, the required parameter is speed, one of the results of the list command
list - list of parameters for switch with descriptions
Example:
 phantomjs yota.js your_login your_password switch 5.0 
Switch tariff to 5 Mbit / s

Limitations and Known Issues

Periodically falls off on timeout tariff switching. The bug is unstable, passes by itself. For debugging, you can use the - --debug=yes parameter. I also think it would not be superfluous to warn that the actions performed by this script are completely legal, but at any moment the position of the Yota company may change.

Development plans

At the moment, this script just works on crontab. I have a quite predictable schedule for using the Internet. However, there is no limit to perfection, and I’m thinking of writing a simple bandwidth analyzer in order to switch the speed based on the need for it. Suggestions and comments on how best to implement it are accepted with pleasure.

Source: https://habr.com/ru/post/166721/


All Articles