During last years of increased Telegram adoption among contacts, the low learning curve to write bots for it as well as the capacity of bigger group chats and ‘channels’ for one-way publishing of information has helped the proliferation of ‘bargain’ groups.
In those groups, there are ‘discounts’, ‘sales’, about any range of products you can imagine (clothing, shoes, toys, mobiles, tv’s, beauty, etc).
From those groups I was able to get good deals, even sometimes, some elements were ‘for free’ via usage of coupon codes, etc.
Bad side, is that number of channels have evolved beyond control, and made the telegram client become a source of ‘noise’ versus a source of information.
Of course, the biggest issue is that many of those channels are providing the same ‘information’ sometimes but not always the same, and even if there are some ‘theme’ channels, it’s not uncommon to see offers that might not suite your needs in the biggest categories (for example you want a mobile but you’re getting all offers about ‘tech’ stuff, or you want ‘lego’ and you get lot of other toys or kids-things).
Python to the rescue¶
Using python we can come to approach this in several steps:
- First we can expand the url to longer one (those channels tend to use url shorteners)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
- Second, restrict the links we process to the ones in amazon, as it’s ‘easy’ to catch the product ID and perform a search. This leaves out lot of offers, but makes it easier to locate them as there’s an API to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
- Now that we get product id an domain, we can use a database to store when was received (if before) and store as ‘seen’ to not repeat it.
Telegram bot API can help sending the messages or receiving them from a chat, so now it is our chance to code in the way we want it.
Additionally, python packages like python-amazon-simple-product-api, with some simple steps, can help enhancing the database by querying additional details.
1 2 3
Above code with the
productid obtained in the previous code snippet, allows us to query several aspects via amazon api, like
Building the solution¶
Ok, we’ve seen what is needed to expand url, get product id from it and then how to use amazon to get product price, title, etc.
In my case, the next step was to get rid of unwanted offers, but once I had all the data above, it was not difficult to reuse the ‘highlight’ module in https://t.me/redken_bot to forward the products matching the words I wanted to track.
A global replace from
ofertas, adding a few comparisons for
gofertas and now redken supports the following syntax:
1 2 3 4 5 6 7 8 9
The difference between
ofertas, is that by default,
ofertas adds the tracking to your
userid, hence forwarding privately to you, while
gofertas, when used on a group, will forward to the
groupid, allowing for example that users interested in a topic, like let’s say
quadricopters, will receive as a group message any new listing published.
Enjoy and happy filtering!
Follow telegram channels managed by bot at: https://telegra.ph/Nuestros-canales-de-ofertas-06-21