Я новичок в питоне.Я разрабатываю приложение для цитат, используя pythonЯ получаю цитаты дня с мозговитых цитат, использующих BeautifulSoup.Я бы добавил его в текстовый файл.Здесь, если цитаты дня уже добавлены, при повторном запуске программы она должна быть пропущена.Как сделать возможным
Вот код:
from bs4 import BeautifulSoup
import socket
import requests
import subprocess
import datetime
def quotenotify():
timestamp = datetime.datetime.now().strftime("%b %d")
res = requests.get('https://www.brainyquote.com/quote_of_the_day')
soup = BeautifulSoup(res.text, 'lxml')
image_quote = soup.find('img', {'class': 'p-qotd bqPhotoDefault bqPhotoDefaultFw img-responsive delayedPhotoLoad'})
quoteday=image_quote['alt']
text_file = open("quotes.log", "a+")
text_file.write("%s"%timestamp+"\t"+"%s"% quoteday)
text_file.write("\n")
text_file.close()
return
quotenotify()
вывод в файл:
Mar 29 Where there is a great love, there are always wishes. - Willa Cather
Mar 29 Where there is great love, there are always wishes. - Willa Cather