I'm trying to build a python script utilising a Telegram bot to enable the following process:
- Get the details of a potential bet on a sport event from a database
- Notify me of the bet details via a Telegram message
- Place a corresponding bet through a bookmaker's website (manual step)
- Input the details of the bet I place into the bot
- Extract the bet details from the bot and store them in a database
Below is the main function that will use the bot to enable the process above:
def process_bets():
updater = create_updater()
while True:
# There will be code here to query a database for a viable bet
# I've created some dummy variables to simulate a successfully returned query
dummy_bet_id = 123
dummy_bookie_name = "Pinnacle"
dummy_target_odds = 1.18
dummy_target_stake = 50
msg = (
"You have a new bet:\n"
f"bet_id: {dummy_bet_id}\n"
f"bookie_name: {dummy_bookie_name}\n"
f"target_odds: {dummy_target_odds}\n"
f"target_stake: {dummy_target_stake}\n"
)
updater.bot.send_message(chat_id=<MY_USER_ID>, text=msg)
while True:
# a. loop checking that the user has entered *complete* bet details into bot - assume 3 variables: 'bookmaker', 'odds' and 'stake'
# b. extract bet details from bot into a variable, say a dictionary
# c. store bet details in database
# d. wipe the bet details inside the bot ready for the next bet
# e. break out of this inner loop
time.sleep(5)
To save space in this post I've not included all the details of the updater
I've created but it follows pretty much the same format as this example on GitHub.
I need help on points a
and b
above as I can't work out how to extract the bet details from the bot as a variable that I can further process. All the posts I've seen on how to deal with user input provide solutions that sit inside the bot's message handling functions. However, bets can only be processed consecutively so I need to store the details of any bet I place before querying the database again for another bet.
Thanks in advance!
Oh and bonus points if you're able to give me a hint on how to do d
or if it is even necessary!