-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
69 lines (50 loc) · 2.03 KB
/
app.py
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
66
67
68
69
#telegram api
from telegram.ext import *
#connecting to db
from connectToDB import lend
#importing pandas
# import pandas
# df=pandas.read_csv("https://raw.githubusercontent.com/vikasjha001/telegram/main/qna_chitchat_professional.tsv",sep='/t')
# print(df)
# print(df.loc[df['Question'].str.lower() == "Do you ever get hurt?"])
# Loading env
import os
from dotenv import load_dotenv
load_dotenv()
TELETOKEN = os.environ.get('TELETOKEN')
async def start(update,context):
await update.message.reply_text("hello")
async def list(update,context):
st=""
receivedData = lend.find({},{"_id":0})
for x in receivedData:
st+=f"{x['name']} - {x['amount']}\n"
if(len(st)==0):
st+="No Record Found"
await update.message.reply_text(st)
async def entry(update,context):
receivedData = update.message.text # 'Anshul 100'
receivedData = receivedData.replace("/entry","")
receivedData = receivedData.upper() # 'ANSHUL 100'
receivedData = receivedData.split() # ['ANSHUL','100']
if(len(receivedData)==0):
await update.message.reply_text("Provide Valid Entry")
return
receivedData[1]=int(receivedData[1]) # ['ANSHUL',100]
a=lend.find_one({"name":receivedData[0]},{"_id":0})
if(a):
finalAmount = a['amount'] + receivedData[1]
lend.find_one_and_update({"name":receivedData[0]},{'$set':{"amount":finalAmount}})
await update.message.reply_text("Record Updated")
else:
lend.insert_one({"name":receivedData[0],"amount":receivedData[1]})
await update.message.reply_text("Lender Created Or Updated")
async def message(update,context):
await update.message.reply_text("I Don't Know How To Respond to: "+str(update.message.text))
if(__name__=="__main__"):
app=Application.builder().token(TELETOKEN).build()
app.add_handler(CommandHandler("start",start))
app.add_handler(CommandHandler("list",list))
app.add_handler(CommandHandler("entry",entry))
app.add_handler(MessageHandler(filters.TEXT,message))
app.run_polling()