Twitter has become a daily means of communication and information for many people. Personally, I open it every day several times from the phone, and on the desktop the client is constantly running.
There was an idea that it would be nice to receive some reminders through it, since I use it every day.
During the evening a small bot was written to remind you.
By itself, the first thought was to find analogues. Several of these services can be found after a short googling.
But they did not suit me for several reasons.
Some of these services offer to fill out a form on the site and almost create an account on it. Many are in English, which is not convenient for everyone (although it will seem like a plus to someone). Many offer to send a notification only on a certain day, without reference to time.
')
Of course, there are many ways to set up notifications and reminders for yourself - a lot of calendars, such as online services with SMS reminders, as well as programs for desktops and phones (for example, the calendar from Apple, which is synchronized between devices via iCloud). But all this makes doing extra actions - open a calendar, add an event, fill out ... But everything can be done much easier with a simple text line (lovers working in the console, I think, understand what I mean).
If the Twitter client is constantly open on the desktop, and the mobile client opens several times a day - why not just write a tweet that will be back at the right time. You do not need to open something else, or remember the site / look for it in the bookmarks, where you can make a reminder.
During the evening a bot was written, so to speak. I do not know what I wanted more - to make a convenient service for myself or to practice working with the Twitter API. I registered an account for him - the word “remind” on the translit, so that it was easy to remember.
It's easy to use it, you just need to send a format tweet:
@napominau day.month hour: minute reminder message
For example:
The bot is implemented as a php script on the server side. I’ll omit the Twitter API in PHP; a lot of articles are written about it. In general, everything looks like this:
- Once a minute, the script takes the last mentions through the Twitter API, while remembering the id of the last tweet previously received. This allows us in the request parameters to use the since_id parameter in order not to chase unnecessary data.
- Received tweets understand regular. If the format is incorrect, a sad tweet is sent to the sender.
If the format is correct, the tweet is stored in the database, waiting for his time. - Once a minute another script goes through the database in search of reminders, the time of which has come. If any, they are sent to the owner and erased from the base.
Thus, at a specified time, the user receives a reminder written by him:
In my opinion, the advantages of this "bot" include:
- convenience of creating reminders - just sending a tweet, no need to perform extra actions;
- binding reminders not only to the day, but to the time;
- reminders directly on Twitter, which is convenient if you watch the tape several times a day or do not close the client at all;
- creating reminders through your Twitter account eliminates the use of a bot for drawing :) (reminders are sent to the owner);
- Twitter clients are very much under different platforms and devices, even customers already build in TVs, that is, they can be used everywhere;
- Modern phones allow you to use notifications of new tweets, if the owner has authorized them. For example, iPhone owners can receive push notifications about new tweets with owner references. Owners of Android devices can also receive notifications from the client. This makes reminders even more convenient.
There were not many technical difficulties - requests are chased through CURL via the REST API, the data is in JSON format. There were problems when memorizing id tweets - on the server a large number was converted to a format like 1.0542197938321E-081, and since the last id is used for subsequent requests - this caused problems when sending a request with the
since_id parameter - the API returned an error. True, then in the returned data, the
id_str field was found - the same ID only as a text string, not a number, this solved the problem.
The Twitter API has
restrictions on the number of calls to the API - 150 unauthorized requests per hour, 350 authorized per hour. However, this does not apply to POST requests. Taking tweets once a minute, we use only 60 requests per hour, which is more than enough. And sending tweets without limit. Therefore, the bot should not rest against limits.
The server is Moscow time, so you need to specify it. If you specified the time before the current one - then the difference between the current and the specified time is checked - if it is less than 24 hours - then a tweet with a reminder will be sent immediately. If more than 24 hours - then transferred to the next year.
I would be glad if someone bot seemed useful. The method of use is in the description of the
@napominau account (time, you need to specify Moscow time).
PS I would be thinking of my bots at the site of many services - to take some applications / orders via Twitter - in my opinion, people are comfortable.