Telegram bot which sends posts from a list of Facebook Pages to a Telegram channel.
Every post has this structure:
[Media] (if present)
[Text] (if present)
[Signature] (with a name associated to the page by the user)
Just run setup.py
Insert telegram bot token and the channel tag in the config.py file.
Insert the FB pages you want to get posts from in a pages.csv file.
The first line is needed and must be page_name,page_tag,last_post_used
.
The first column is the page name, you can set it to whatever you want but it will be the signature of the posts in every comment.
The second name is the page tag, this must me the name of the page you can find in the URL with the broswer, this is what the bot actually needs to get posts from the pages.
The last column is the last post used, that is the id of the last post retrieved by the bot, and will be changed by it at runtime.
Be careful to set it properly the first time, because the bot will try to retrieve all the posts which were published after that one.
Follow these instructions to extract cookies and save them as cookies.txt
in the same folder of scraper.py
(set your language to english before exporting cookies to avoid getting low quality images)
- text posts
- image post *
- image galleries *
- video *
- shared posts
* if present text will be used as caption
python-telegram-bot
facebook-scraper
page_name,page_tag,last_post_used
Facebook Page,facebook,284507553110844
Scraper will return low quality images when using cookies if language on facebook is not set to english, that's because there is a regex looking for "View full size". Be sure to switch language to english before exporting cookies.
Since facebook-scraper is not able to return reliable timestamp for posts, this bot is currently relying on the assumption that posts ids always grow, if suddenly new posts will start having ids with values smaller then previous ones then the bot will stop forwarding posts to the channel.
This check should be probably done in a smarter way, any contribution is much appreciated.
Error handling is done in a sketchy way, should be improved