Можно купить розетку с двумя RJ45 и там развести по такой же схеме. Будет гораздо надежней, чем подобная лапша.
import requests
import pymysql.cursors
def add_book(title, authors, publishedDate, categories, thumbnail):
connection = pymysql.connect(host='localhost', user='root',password='пароль',
db='имяБД',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = "INSERT INTO book (`title`, `authors`, `published_date`, `categories`, `thumbnail`) VALUES (%s, %s, %s, %s, %s)"
cursor.execute(sql, (title, authors, publishedDate, categories, thumbnail))
connection.commit()
finally:
connection.close()
def run(book_name):
r = requests.get('https://www.googleapis.com/books/v1/volumes?q={book_name}').json()
for book in r['items']:
try:
title = book['volumeInfo']['title']
authors = ' '.join(book['volumeInfo']['authors'])
publishedDate = book['volumeInfo']['publishedDate']
categories = ' '.join(book['volumeInfo']['categories'])
thumbnail = book['volumeInfo']['imageLinks']['thumbnail']
print(f'Добавлена книга: \n{publishedDate} | {title} | {authors} | {categories} | {thumbnail}')
add_book(title, authors, publishedDate, categories, thumbnail)
except KeyError:
print('Не найдена категория')
run('Hobbit')
Условие не сработает
if message.text.lower() == 'Привет':