H
H
haoiwi2022-04-19 11:36:29
Python
haoiwi, 2022-04-19 11:36:29

What is the best way to combine?

What is the best way to combine this part of the code

import requests
import json
answer = requests.get('api')
data = (json.loads(answer.text))
print(json.loads(answer.text)[0]['title'])
print(json.loads(answer.text)[0]['domain'])
print(json.loads(answer.text)[0]['conclusion'])
print(json.loads(answer.text)[0]['product']['price']['price'][17])

In this:
@bot.message_handler(content_types=["text"])
def lalala(message):
    text = message.text
    if 'amazon' in text:
        try:
            product_id = text.split('/', 6)[5]
            bot.send_message(message.chat.id, f'Amazon - {product_id}')
        except Exception:
            bot.send_message(message.chat.id, 'Не верная ссылка')
    text = message.text

In the second code, when receiving a link from a user, the bot responds with product id

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question