-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (59 loc) · 3.53 KB
/
Copy pathapp.py
File metadata and controls
65 lines (59 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pyrogram import filters, Client, idle
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from pyrogram.enums import ChatAction
from pyrogram import *
from configs.telegram import api_id,api_hash,bot_token,bot_name
from core.drugload import load_products_from_csv
from configs.dataset import drug_data
from core.search_drug import search_product
from core.close_match import find_closest_match
import csv
import difflib
products = load_products_from_csv(drug_data)
app = Client(bot_name,api_id=api_id,api_hash=api_hash,bot_token=bot_token)
@app.on_message(filters.command('start'))
async def start_msg(client,message):
name=str(message.from_user.first_name)
try:
user_id = str(message.from_user.id)
first_name = str(message.from_user.first_name)
user_name = str(message.from_user.username)
language_code = str(message.from_user.language_code)
await message.reply(f"__Hey {name}__!\n\nI'm **DrugInfo bot** with an extensive database of medicines helps you to retrieve the vital informations of an medicine such as product name, salt composition, price, manufacturer, description, side effects.\n\nJust let me know the medicine you want to search ?")
except:
pass
@app.on_message(filters.text)
async def drug(client,message):
user_id = str(message.from_user.id)
product_name = str(message.text)
print(user_id)
result = search_product(products, product_name)
if result == "Product not found.":
closest_match = find_closest_match(products, product_name)
if closest_match:
print(f"\nDid you mean: {closest_match}?")
result = search_product(products, closest_match)
if result != "Product not found.":
product_info = dict(result.items())
sub_catagory = product_info['sub_category']
medicine_desc = product_info['medicine_desc']
salt_composition = product_info['salt_composition']
product_price = product_info['product_price']
product_manufactured = product_info['product_manufactured']
side_effects = product_info['side_effects']
drug_interactions = product_info['drug_interactions']
await message.reply(f"\n__Did you mean: {closest_match}?__\n\n**Category :**\n__{sub_catagory}__\n\n**Salt Composition :\n**__{salt_composition}__\n\n**Price : **__{product_price}__\n\n**Manufacture : **\n__{product_manufactured}__\n\n**Description : **\n\n__{medicine_desc}__\n\n**Side Effects :**\n\n__{side_effects}__\n\n")
else:
await message.reply("Drug not found.")
else:
print("\nProduct Information:")
product_info = dict(result.items())
sub_catagory = product_info['sub_category']
medicine_desc = product_info['medicine_desc']
salt_composition = product_info['salt_composition']
product_price = product_info['product_price']
product_manufactured = product_info['product_manufactured']
side_effects = product_info['side_effects']
drug_interactions = product_info['drug_interactions']
await message.reply(f"\n__Did you mean: {product_info['product_name']}?__\n\n**Category :**\n__{sub_catagory}__\n\n**Salt Composition :\n**__{salt_composition}__\n\n**Price : **__{product_price}__\n\n**Manufacture : **\n__{product_manufactured}__\n\n**Description : **\n\n__{medicine_desc}__\n\n**Side Effects :**\n\n__{side_effects}__\n\n")
app.run()