import requests import json import telebot import os import pymysql def laenge(): datas = '{"sid":"' + id + '","op":"getHeadlines","feed_id":-1}' resp = requests.post(url, datas) data = resp.json() a=(len(data['content'])) return a TOKEN ='312534798:AAFbMjS-tfd2BiZ_j3NEZuQYKwzACMcioVo' chat_id ='322673713' tb = telebot.TeleBot(TOKEN) url = 'http://hubobel.de/tt-rss/api/' pfad = os.path.dirname(__file__) datas = '{"op":"login","user":"admin","password":"polier2003"}' resp = requests.post(url,datas) data = resp.json() #print(data) id= str(data['content']['session_id']) datas = '{"sid":"'+id+'","op":"getFeeds","cat_id":-4}' resp = requests.post(url,datas) data = resp.json() ids=[] print(data) gefunden=[] laenge_start=laenge() suchstring=[] fobj = open(pfad+"/toFind.txt") for line in fobj: if line.rstrip()!='': suchstring.append(line.rstrip()) fobj.close() for i in data['content']: print(i) if int(i['unread'])>0 and int(i['id'])>0: datas = '{"sid":"'+id+'","op":"getHeadlines","feed_id":'+str(i['id'])+'}' resp = requests.post(url,datas) feeds = resp.json() print(feeds) for headlines in feeds['content']: if headlines['unread']: a=0 b=len(suchstring) if headlines['feed_id'] == '46': article_id=str(headlines['id']) datas = '{"sid":"' + id + '","op":"getArticle","article_id":'+article_id+'}' resp = requests.post(url, datas) data = resp.json() antwort=str(data['content'][0]['content']) connection = pymysql.connect(db="hubobel", user="hubobel", passwd="polier2003", host='10.0.1.123', charset='utf8') cursor = connection.cursor() sql = "SELECT * FROM facts ORDER BY nr DESC" resp = cursor.execute(sql) x = int(resp) + 1 print(antwort) line = antwort.replace('
', '') line = line.replace('
', '') sql = "INSERT INTO `facts`(`nr`, `fact`) VALUES ('" + str(x) + "','" + line + "')" sql_q = "SELECT * FROM facts WHERE fact like '%" + line + "%'" resp = cursor.execute(sql_q) if resp == 0: try: resp = cursor.execute(sql) except: bericht='Es gab ein Problem beim Schreiben des facts in die DB' tb.send_message(chat_id, bericht) connection.commit() cursor.close() connection.close() while a