introduce search interface
This commit is contained in:
@@ -59,14 +59,8 @@ def download_file(url):
|
||||
return local_filename
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Chat(SaveFileObject):
|
||||
class BaseChat(SaveFileObject):
|
||||
"Basis für einen Telegram Chat"
|
||||
def __init__(self,id, bot):
|
||||
self.id=id
|
||||
#self.chat_id=chat_id
|
||||
@@ -84,8 +78,6 @@ class Chat(SaveFileObject):
|
||||
"type": self.type,
|
||||
"mode": self.mode
|
||||
}
|
||||
def asdict(self):
|
||||
return self.to_dict()
|
||||
@classmethod
|
||||
def from_dict(self, bot, d):
|
||||
c=Chat(d["id"],bot)
|
||||
@@ -94,20 +86,17 @@ class Chat(SaveFileObject):
|
||||
c.mode=d.get("mode","")
|
||||
return c
|
||||
|
||||
def inline(self, query):
|
||||
InlineQueryResultArticle
|
||||
r=solr.search("text_txt: %s" % query.query,sort="date_dt desc").docs
|
||||
r= [fet.find_one({"slug": rr["id"]}) for rr in r ]
|
||||
res=[ InlineQueryResultArticle(
|
||||
id=d["url"],
|
||||
title=d["title"],
|
||||
url=urljoin(TARGET,d["url"]),
|
||||
thumb_url = urljoin(TARGET,d["image"]),
|
||||
input_message_content = InputTextMessageContent(message_text=urljoin(TARGET,d["url"]))
|
||||
) for d in r]
|
||||
links=[p["title"]+": "+"(%s) "% p["public_date"] + urljoin(TARGET,p["url"]) for p in r]
|
||||
self.bot.answer_inline_query(inline_query_id=query.id,results=res )
|
||||
return
|
||||
def echo(self,update):
|
||||
self.reply_msg(yaml.dump(update._raw)+"\nfrom"+str(get_from_id(update)))
|
||||
def send_msg(self, text,**kwargs):
|
||||
self.bot.send_message(chat_id=self.id, text=text, **kwargs)
|
||||
def reply_msg(self, text, **kwargs):
|
||||
self.bot.send_message(chat_id=self.id, text=text, reply_to_message_id=self.last_message_id,**kwargs)
|
||||
def asdict(self):
|
||||
return self.to_dict()
|
||||
|
||||
def inline(self,query):
|
||||
pass
|
||||
|
||||
def process_update(self,update):
|
||||
|
||||
@@ -137,7 +126,7 @@ class Chat(SaveFileObject):
|
||||
text=update.callback_query.message.text+": "+update.callback_query.data)
|
||||
|
||||
if update.message and update.message.photo:
|
||||
ff=max(update.message.photo, key=lambda x: x.file_size)
|
||||
ff=max(update.message.photo, key=lambda x: x.file_size) # Foto mit bester Auflösung
|
||||
fff = self.bot.get_file(ff.file_id)
|
||||
url=fff.get_download_url(API_KEY)
|
||||
r = requests.get(url)
|
||||
@@ -150,19 +139,28 @@ class Chat(SaveFileObject):
|
||||
u=users[update]
|
||||
users.to_file()
|
||||
|
||||
def echo(self,update):
|
||||
self.reply_msg(yaml.dump(update._raw)+"\nfrom"+str(get_from_id(update)))
|
||||
def send_msg(self, text,**kwargs):
|
||||
self.bot.send_message(chat_id=self.id, text=text, **kwargs)
|
||||
def reply_msg(self, text, **kwargs):
|
||||
self.bot.send_message(chat_id=self.id, text=text, reply_to_message_id=self.last_message_id,**kwargs)
|
||||
|
||||
class Chat(BaseChat):
|
||||
|
||||
def inline(self, query):
|
||||
#r=solr.search("text_txt: %s" % ,sort="date_dt desc").docs
|
||||
links,hits=solr.search(query.query)
|
||||
r= links[0:6]
|
||||
res=[ InlineQueryResultArticle(
|
||||
id=d["url"],
|
||||
title=d["title"],
|
||||
url=urljoin(TARGET,d["url"]),
|
||||
thumb_url = urljoin(TARGET,d["image"]),
|
||||
input_message_content = InputTextMessageContent(message_text=urljoin(TARGET,d["url"]))
|
||||
) for d in r]
|
||||
#links=[p["title"]+": "+"(%s) "% p["public_date"] + urljoin(TARGET,p["url"]) for p in r]
|
||||
self.bot.answer_inline_query(inline_query_id=query.id,results=res )
|
||||
return
|
||||
|
||||
def process_command(self,cmd,txt,update):
|
||||
self.last_message_id=get_message_id(update)
|
||||
|
||||
u=users[update]
|
||||
|
||||
print("--\ndict: %s" % str(users.asdict()))
|
||||
# print("--\ndict: %s" % str(users.asdict()))
|
||||
|
||||
#users[get_from_id(update)]=u
|
||||
if cmd == "/s" or cmd =="/search":
|
||||
@@ -179,12 +177,16 @@ class Chat(SaveFileObject):
|
||||
self.reply_msg("Mode: %s" % txt)
|
||||
return True
|
||||
elif cmd == "/debug":
|
||||
if not u.fet_user:
|
||||
self.reply_msg("bitte vorher /auth ausführen wenn du ein FET Mitglied bist")
|
||||
return True
|
||||
if self.debug:
|
||||
self.debug = False
|
||||
else:
|
||||
self.debug = True #not self.debug
|
||||
self.reply_msg("Debug: %s" % str(self.debug))
|
||||
return True
|
||||
|
||||
elif cmd =="/post":
|
||||
if not u.fet_user:
|
||||
self.reply_msg("bitte vorher /auth ausführen wenn du ein FET Mitglied bist")
|
||||
@@ -192,6 +194,9 @@ class Chat(SaveFileObject):
|
||||
self.workflows[get_from_id(update)]=CreatePostWorkflow(chat=self)
|
||||
return True
|
||||
elif cmd == "/reindex":
|
||||
if not u.fet_user:
|
||||
self.reply_msg("bitte vorher /auth ausführen wenn du ein FET Mitglied bist")
|
||||
return True
|
||||
self.reply_msg("Das kann ein bissl dauern...")
|
||||
solr.reindex()
|
||||
self.send_msg("Fertig mit dem neuen Index")
|
||||
@@ -221,6 +226,7 @@ def get_command_from_update(update):
|
||||
|
||||
|
||||
|
||||
|
||||
class ChatManager(SaveFileMapping):
|
||||
|
||||
def __init__(self,bot):
|
||||
|
||||
Reference in New Issue
Block a user