Answer the question
In order to leave comments, you need to log in
Why doesn't my Telegram bot want to parse this RSS?
Hello! I used a simple bot from here , slightly modified the code so that the bot would not post too much to the channel. Here is my code (replaced with xxxxxx all sorts of tokens and other things that do not need to be published, left the RSS address):
import pickle
import feedparser
import telegram
from time import sleep
feed_list =["http://baikalinform.ru/obyavki-rss",
]
last_feeds = pickle.load(open("/home/xxxxx/xxxxxx/db.p", 'rb'))
fee_links = []
bot = telegram.Bot(token='xxxxxxxxxxxxxxxx')
print(last_feeds)
print("-----Last feeds---")
def feederek():
for i in feed_list:
fee = feedparser.parse(i)
fee_title = fee.feed.title
for x in range(10):
fee_links.append(fee['entries'][x]['id'])
if fee['entries'][x]['id'] in last_feeds:
print("Nothing new - " + fee_title)
else:
sleep(5)
entry_title = fee['entries'][x]['title']
entry_id = fee['entries'][x]['id']
print("Updated - " + fee_title)
message = str(entry_title +"\n" + entry_id)
bot.sendMessage(chat_id="@xxxxxxxxxxx", text=message)
pickle.dump(fee_links, open("/home/xxxxx/xxxxxx/db.p", 'wb'))
return
feederek()
-----Last feeds---
Traceback (most recent call last):
File "feederek.py", line 38, in <module>
feederek()
File "feederek.py", line 22, in feederek
fee_links.append(fee['entries'][x]['id'])
File "/home/xxxxxx/.local/lib/python3.5/site-packages/feedparser.py", line 357, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'id'
certifi (2017.7.27.1)
chardet (2.3.0)
command-not-found (0.3)
feedparser (5.2.1)
future (0.16.0)
language-selector (0.1)
pip (8.1.1)
pycurl (7.43.0)
pygobject (3.20.0)
python-apt (1.1.0b1)
python-debian (0.1.27)
python-systemd (231)
python-telegram-bot (8.1.1)
requests (2.9.1)
setuptools (20.7.0)
six (1.10.0)
ssh-import-id (5.5)
telegram (0.0.1)
ufw (0.35)
unattended-upgrades (0.1)
urllib3 (1.13.1)
wheel (0.29.0)
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Answer the question
In order to leave comments, you need to log in
Problem solved. The tags recommended by the validator were missing in the RSS <guid>...</guid>
.
When I added these tags to the RSS, the parsing worked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question