⬆️ ⬇️

Simple Twitter Notification Service



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:





Thus, at a specified time, the user receives a reminder written by him:





In my opinion, the advantages of this "bot" include:





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.

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



All Articles