update title
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user