Simple notification service via Twitter


Twitter for many people has become an everyday means of communication and information. Personally, every day I open it several times to the phone, and the desktop client running constantly.
The idea arose that it would be nice to obtain through him some reminders, since I use them every day.
The evening has been written a small bot for reminders.


Of course my first thought was to find analogues. Several of these services can be found after a short gugleniya.
But I was not satisfied for several reasons.

Some of these services offer to fill out a form on the website and almost to create an account. Many of the English language that not everyone is comfortable (although it seems a plus). Many offer to send the notification only to a specific day, without reference to time.

Of course, there are many ways to set yourself alerts and reminders — multiple calendars, as online services and SMS reminders, and software for desktop and phones (e.g., Apple's calendar, which syncs between devices via iCloud). But all it makes you do the extra steps to open the calendar, add event, fill in... But it can be done much easier, a simple text string (fans run in the console, I think you know what I mean).

So if a Twitter client permanently open on the desktop, and the mobile client opens several times a day — why not just write a tweet that will return at the right time. No need to open something else, or remember the website/look for it in the bookmarks, where you can make the reminder.

For the evening was written, so to speak, bot. I don't know what I wanted more — to make a convenient service or to practice working with the Twitter API. Checked his account the word "resemble" in transliteration to make it easy to remember.

Using them is simple, you just need to send a tweet in the format:
@napominau day.month hour: minute message reminder

For example:


The bot is implemented as a php script on the server side. Communication with the Twitter API in PHP I omitted many articles written about this. In General it looks like this:
the
    the
  • once a minute, the script takes the last mentions using the Twitter API, while remembering the last id received earlier tweet. It allows us in the request parameters to use since_id, not to send extra data.
  • the
  • Resulting tweets are parsed by the regular season. If the format is invalid — is sent to the sender of this sad tweet.

    If the format is correct — the tweet is stored in the database, waiting for his time will come.
  • the
  • Once a minute, another script runs through the database in search of reminders whose time has come. If any — they go to the owner and erased from the database.


Thus at a specified time, the user receives written them the same reminder:


In my opinion, the advantages of such a "bot" include:
the
    the
  • convenient way to create reminders just sending a tweet, it is not necessary to take superfluous action;
  • the
  • binding reminders not only the day, but at the time;
  • the
  • reminders directly to Twitter, which is handy if you watch the tape several times a day or not at all closing the client;
  • the
  • to create reminders using your Twitter account precludes the use of the bot for pranks :) (reminder sent to the owner) ;
  • the
  • Twitter-a lot of clients for different platforms and devices, even TVs embedded clients, it is possible to use everywhere;
  • the
  • modern phones allow you to use notifications on new tweets, if the owner allowed them. For example, iPhone owners can receive PUSH notifications for new tweets with mention of the owner. Owners of Android devices can also receive notifications from the client. It makes reminders more convenient.

  • Technical difficulties were not many requests chasing using CURL for REST API data in JSON format. Had problems with remembering the id of the tweets on the server a large number is converted to a format like 1.0542197938321 E-081, and since the last id is used for subsequent requests — this caused a problem when sending request with parameter since_id — the API should return an error. But then in the returned data was detected the id_str — the same IDs in a text string, not a number, it solved the problem.

    From the Twitter API has limitations the number of accesses to API — 150 unauthorized requests per hour and 350 authorized in the hour. However for POST requests it does not apply. Taking tweets every minute we use only 60 requests per hour, this is more than enough. And sending tweets without any restrictions. Therefore, pushing the limits on the idea of a bot should not.

    Server is in Moscow time, so you need to specify it. If you have the time before this it checks the difference between the current and the specified time — if it is less than 24 hours, then tweet a reminder will be sent immediately. If more than 24 hours, then transferred to the next year.

    I would be glad if someone bot seems useful. Method of use put in the description of the account @napominau (time, you need to specify Moscow).

    P. S. I would place many of the services have thought about their bots to accept any requests/orders via Twitter — I think people find it convenient.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Car navigation in detail

Multilateral exchange

PostgreSQL: Analytics for DBA