📜 ⬆️ ⬇️

A simple way to track the activity of Mail.Ru Agent users

Good day, dear habrapayazhety.

I do not think that this post will pull on any serious "cover failure", but, nevertheless, it can help someone faced with my problem. So, given the task. It is necessary to track how often a particular user of the mail.ru portal logs into the agent.

A bit of history

Once upon a time I solved this problem in the only way available to me at that time. A small program was written (to call the utility the language will not turn) on Delphi, which constantly monitored the headers of the open windows. Actually, for the program to function correctly, it was necessary that the window of dialogue with the user be present in the list of windows. The program followed him and took some action when the title “Vasily Pupkin - Disabled” disappeared, and “Vasily Pupkin - Online” appeared.
')
Despite all the simplicity, the program worked flawlessly, waking me up with a melody from the speakers when the person I needed appeared online, and notifying him with a message in the open window that he was needed. In principle, the program could be refined and adapted for any needs, such as recording the I / O log.

However, such a solution to the problem is categorically not correct, as it requires the user to add the desired user to the contact list, keep the dialogue with him open, and generally assembled on his knee for half an hour from matches and acorns.

Today, faced with such a problem, I came up with a new simple way to solve it, which I spread to your judgment.

So, the task remains the same.

Training

To begin with, we will think about where the status of the user somehow “burns”. Climbing the mail.ru site, and briefly reviewing the specification of the mrim protocol, I came up with the following options:

1) Actually, the status in the mail.ru agent.
2) Status in the web-agent, displayed on the pages of mail and "My World".
3) Status on the “My World” page.

Paragraph 1 is rejected because of the need for incineration of manuals using the mrim protocol. It will take too long to figure out how to log in under a certain account, do a search for an address, and get status. In addition, the user will need to create some kind of account on behalf of which this will be done. For the latter reason, point 2 is discarded, plus the need to understand the web agent device. But point 3 I was seriously interested, you can deal with it in more detail.

As you know, the address of the user's page with the address “address@mail.ru” is formed as “my.mail.ru/mail/address”. We go to the page, and we see a green or a red "@" sign next to the username, indicating, in fact, the desired person is present in the agent or not.

image

It seems that this is the solution, but not everything is so simple. If my memory serves me, some time ago it was so, but now, if you log out of your account, and see the page as an unauthorized user sees it, it is easy to see that the icon near the name disappears.

However, back to your account, and take a closer look at what this icon represents. More precisely, let's look at its attribute “style”.

image

Following the link “status.mail.ru?address@mail.ru” you can see the same 13x13 icon in the GIF format, which does not depend on authorization, and shows exactly whether a person is online or not. So, the goal is defined, let's start working.

Actually, coding

To work, I chose PHP with the included GDLib library.

function check_status($mail) { $image = imagecreatefromgif("http://status.mail.ru/?".$mail); //   ,  .  ,     $x=10; //   ,    . $y=10; //  ,    ,     . $rgb = imagecolorsforindex($image,imagecolorat($image, $x, $y)); //  RGB   . $color = dechex($rgb[red]).dechex($rgb[green]).dechex($rgb[blue]); //     RGB  HEX  . if ($color == 'd3f0dc') return 'online'; //      ,   . if ($color == 'f8dddd') return 'offline'; if ($color == 'd8e9d8') return 'away'; //  - ,        ,  " ", "  "  " ,  ".   ""      ,     . } 


That's all. The input of the function is the e-mail address of the desired user, and at the output we get the status in the text version. If desired, you can force the function to return true / false, depending on the situation.

Of course, the decision is the most elementary. But, nevertheless, at no extra cost, we got the desired result. The resulting function can be applied extremely widely. For example, set a task on Cron, and record the results in a database for further processing, or navigate a small widget in JavaScript that will track the appearance of people of interest on the network, and inform about this alert.

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


All Articles