def random_message(user_id: str) -> TextSendMessage: """ Wikipediaのランダムなタイトルで検索 Args: user_id(str): LINEのユーザーID Returns: TextSendMessage """ user = get_user(user_id) wikipedia.set_lang(user.lang) random = wikipedia_random(show_url=user.show_url) title = random[0] text = random[1] candidates = random[2] if title: add_history(user_id, title) items = wikipedia_search(title) quick_reply = create_quick_reply(items) else: quick_reply = create_quick_reply(candidates) text += '\n\n' for c in candidates: text += f'・{c}\n' text = text.rstrip() return TextSendMessage(text=text, quick_reply=quick_reply)
def summary_message(user_id: str, message: str) -> TextSendMessage: """ メッセージに基づくWikipediaの要約メッセージを生成する Args: user_id(str): LINEのユーザーID message(srt): クライアントが送信したメッセージ Returns: TextSendMessage """ user = get_user(user_id) wikipedia.set_lang(user.lang) page = wikipedia_page(message, show_url=user.show_url) title = page[0] text = page[1] candidates = page[2] if title: add_history(user_id, title) items = wikipedia_search(title) quick_reply = create_quick_reply(items) else: quick_reply = create_quick_reply(candidates) text += '\n\n' for c in candidates: text += f'・{c}\n' text = text.rstrip() return TextSendMessage(text=text, quick_reply=quick_reply)
def set_show_url(user_id: str, message: str) -> TextSendMessage: """ ユーザーの要約メッセージにURLを含めるかの設定を行います Args: user_id(str): LINEのユーザーID message: クライアントが送信したメッセージ Returns: TextSendMessage """ user = get_user(user_id) text = 'Please enter :show_url=true or :show_url=false' if message == ':set_show_url=true': if user.show_url: text = 'The show_url is already set to true' else: update_user(user_id, show_url=True) text = 'show_url is set to true' elif message == ':set_show_url=false': if not user.show_url: text = 'The show_url is already set to false' else: update_user(user_id, show_url=False) text = 'show_url is set to false' return TextSendMessage(text=text)
def set_lang(user_id: str, message: str) -> TextSendMessage: """ ユーザーの言語情報を更新します Args: user_id(str): LINEのユーザーID message(str): クライアントが送信したメッセージ Returns: TextSendMessage """ user = get_user(user_id) text = 'Please enter the language code that exists' if message in [f':set_lang={lang}' for lang in languages.keys()]: lang = re.findall(':set_lang=(.+)', message)[0] if user.lang == lang: text = f'It is already set to "{languages[lang]}"' else: text = f'Changed the language setting to "{languages[lang]}"' update_user(user_id, lang=lang) return TextSendMessage(text=text)
import random import src.database as db names = ['Mark', 'Carlos', 'Jose', 'Laura', 'Susan', 'Angela', 'John', 'Jane'] last_names = ['Fernandez', 'Smith', 'Rodriguez', 'Doe', 'Brown', 'Davis'] for i in range(50): user_id = str(random.randint(10**6, 2 * 10**6)) user = db.get_user(user_id) user['id'] = user_id user['first_name'] = random.choice(names) user['last_name'] = random.choice(last_names) user['tester'] = True cards = ['1104', '1136', '1163'] random.shuffle(cards) db.add_wanted(user, cards[:1]) db.add_collection(user, cards[1:])
from src.connectors import messenger_sender from src import texts from src import nlg from src import database as db julian = '1760389324081001' quimey = '1664422086988784' if __name__ == '__main__': sender = db.get_user(quimey) # transaction_id = sender['transactions'][0]['id'] # transaction = db.get_transaction(sender['transactions'][0]['id']) # print(transaction['cycle'][1::2]) t = texts.get_texts(sender) messenger_sender.send_messages({'id': str(quimey)}, nlg.new_trade(t))