EvilFreelancer / rss-to-telegram-bot

Simple bot for reading posts from rss and
https://t.me/evilfreelancer
5 stars 3 forks source link

Issue with docker and php #1

Open semaf opened 4 months ago

semaf commented 4 months ago

Hey,

I am facing with some issue with the docker container running which end with some error in rss-to-telegram.php file.

ss-to-telegram-bot-1  | Fatal error: Uncaught TypeError: str_replace(): Argument #2 ($replace) must be of type string when argument #1 ($search) is a string in /app/rss-to-telegram.php:73
rss-to-telegram-bot-1  | Stack trace:
rss-to-telegram-bot-1  | #0 /app/rss-to-telegram.php(73): str_replace('{{title}}', Array, '<a href='https:...')
rss-to-telegram-bot-1  | #1 /app/rss-to-telegram.php(87): renderTemplate(Array)
rss-to-telegram-bot-1  | #2 {main}
rss-to-telegram-bot-1  |   thrown in /app/rss-to-telegram.php on line 73

Running it with the php command is it like below. Installed php-cli

root@docker:~/rss/rss-to-telegram-bot# php -f rss-to-telegram.php
Command 'php' not found, but can be installed with:
apt install php8.1-cli  # version 8.1.2-1ubuntu2.14, or
apt install php-cli     # version 2:8.1+92ubuntu1
root@docker:~/rss/rss-to-telegram-bot# apt install php-cli
root@docker:~/rss-to-telegram-bot# php -f rss-to-telegram.php
PHP Warning:  require_once(/root/rss-to-telegram-bot/vendor/autoload.php): Failed to open stream: No such file or directory in /root/rss-to-telegram-bot/rss-to-telegram.php on line 3
PHP Fatal error:  Uncaught Error: Failed opening required '/root/rss-to-telegram-bot/vendor/autoload.php' (include_path='.:/usr/share/php') in /root/rss-to-telegram-bot/rss-to-telegram.php:3
Stack trace:
#0 {main}
  thrown in /root/rss-to-telegram-bot/rss-to-telegram.php on line 3
EvilFreelancer commented 4 months ago

Hi @semaf

str_replace('{{title}}', Array, '<a href='https:...')

It looks like non-typical format of RSS feed, can you provide URL? I'll add extra tests for cases like yours.

Btw, you probably not set RSSREADER_SOURCES env variable https://github.com/EvilFreelancer/rss-to-telegram-bot/blob/main/.env.dist#L8

Command 'php' not found

This mean you've not installed php binary in your host system, or call it incoretcly, on some systems need to use something like php8.2 instead of php.

PHP Warning: require_once(/root/rss-to-telegram-bot/vendor/autoload.php)

This mean you've not executed composer install in root of project after installing php binary.

semaf commented 4 months ago

Thank for you reply.. I am not familiar with php and composer but managed to run it with some issues

root@docker:~/rss-to-telegram-bot$ php -f rss-to-telegram.php
PHP Fatal error:  Uncaught Symfony\Component\Dotenv\Exception\FormatException: Missing = in the environment variable declaration in "/rss/rss-to-telegram-bot/.env" at line 10.
...W_CATEGORIES_AS_TAGS: false\n\n# Telegram ...
                      ^ line 10 offset 437 in /rss/rss-to-telegram-bot/vendor/symfony/dotenv/Dotenv.php:546
Stack trace:
#0 /rss/rss-to-telegram-bot/vendor/symfony/dotenv/Dotenv.php(288): Symfony\Component\Dotenv\Dotenv->createFormatException()
#1 /rss/rss-to-telegram-bot/vendor/symfony/dotenv/Dotenv.php(244): Symfony\Component\Dotenv\Dotenv->lexVarname()
#2 /rss/rss-to-telegram-bot/vendor/symfony/dotenv/Dotenv.php(556): Symfony\Component\Dotenv\Dotenv->parse()
#3 /rss/rss-to-telegram-bot/vendor/symfony/dotenv/Dotenv.php(83): Symfony\Component\Dotenv\Dotenv->doLoad()
#4 /rss/rss-to-telegram-bot/rss-to-telegram.php(11): Symfony\Component\Dotenv\Dotenv->load()
#5 {main}
  thrown in /home/fatih/rss-to-telegram-bot/vendor/symfony/dotenv/Dotenv.php on line 546

Removing the line RSSREADER_SHOW_CATEGORIES_AS_TAGSlet me run it by php -f rss-to-telegram.php but with same PHP error like in the previous post.

That here is the RSS Feed https://feeds.feedburner.com/semaf/feed

EvilFreelancer commented 4 months ago

RSSREADER_SHOW_CATEGORIES_AS_TAGS variable is not required, but seems by code it was broken in .env.dist (but i've already fixed it).

EvilFreelancer commented 4 months ago

Hm, i've didn't see any problem with post rendering, probably you have some issues with your source.

Screenshot_20240702_080506