temp_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql_con = sqlite3.connect('medbot.db') | |
temp_regex = re.compile(r'[0-9]{2}[.][0-9]') | |
async def track_temp(ctx: ChatContext) -> None: | |
## or not is_med_group(ctx): | |
if ctx.message.empty(): | |
return | |
name = get_name(ctx) # No included, just a regex to pull out the childs name from the msg | |
temp = temp_regex.search(ctx.message.get_body().lower()).group() | |
print(f'Tracking temp for {name}, temp {temp}') | |
await ctx.message.typing_started() | |
cursor = sql_con.cursor() | |
cursor.execute("INSERT INTO temperatures('name', 'temperature', 'time') VALUES (?,?,?)", (name, temp, ctx.message.timestamp_iso)) | |
sql_con.commit() | |
await ctx.message.reply(body="🤒", reaction=True) | |
async def main(): | |
"""Start the bot.""" | |
# Connect the bot to number. | |
async with Bot("YOUR_HUMBER_HERE", socket_path="/signald/signald.sock") as bot: | |
# Track temps in DB | |
bot.register_handler(temp_regex, track_temp) | |
await ctx.message.typing_stopped() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment