update title

This commit is contained in:
Thomas Peetz
2025-01-27 22:42:32 +01:00
parent d01489b1fa
commit c61e49720e
5 changed files with 53 additions and 33 deletions
@@ -1,3 +1,5 @@
import requests
from bs4 import BeautifulSoup
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.dialects.mysql import BIT
@@ -13,6 +15,21 @@ class MediaFile(Base, BaseMixin, BaseVideoMixin):
def __str__(self):
return f'{self.title}({self.id})'
def update_title(self):
print(f"update title for {self.url}")
try:
r = requests.get(self.url)
soup = BeautifulSoup(r.content, "html.parser")
title = soup.title.string
self.title = title
self.review = 0
except:
self.title = None
self.review = 1
def download_file(self, download_dir: str):
print(f"download file for {self.url}")
class MediaArticle(Base, BaseMixin):
__tablename__ = 'media_article'