Browse Source

nicolib

ai-migration
みてるぞ 1 month ago
parent
commit
658b15ac52
1 changed files with 1 additions and 25 deletions
  1. +1
    -25
      nico.py

+ 1
- 25
nico.py View File

@@ -13,6 +13,7 @@ from bs4 import BeautifulSoup
from requests.exceptions import Timeout from requests.exceptions import Timeout
from eloquent import DatabaseManager, Model from eloquent import DatabaseManager, Model


import nicolib
from db.models import Comment, Tag, Video, VideoHistory, VideoTag from db.models import Comment, Tag, Video, VideoHistory, VideoTag


CONFIG: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql', CONFIG: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql',
@@ -97,31 +98,6 @@ def get_bs_from_url (
return BeautifulSoup (req.text, 'html.parser') return BeautifulSoup (req.text, 'html.parser')




def get_video_info (
video_code: str,
) -> VideoInfo | None:
video_info: dict[str, str | list[str]] = { 'contentId': video_code }

bs = get_bs_from_url (f"https://www.nicovideo.jp/watch/{ video_code }")
if bs is None:
return None

try:
title = bs.find ('title')
if title is None:
return None
video_info['title'] = '-'.join (title.text.split ('-')[:(-1)])[:(-1)]

tags: str = bs.find ('meta', attrs = { 'name': 'keywords' }).get ('content') # type: ignore
video_info['tags'] = tags.split (',')

video_info['description'] = bs.find ('meta', attrs = { 'name': 'description' }).get ('content') # type: ignore
except Exception:
return None

return cast (VideoInfo, video_info)


def get_kiriban_list ( def get_kiriban_list (
base_date: date, base_date: date,
) -> list[tuple[int, VideoInfo, datetime]]: ) -> list[tuple[int, VideoInfo, datetime]]:


Loading…
Cancel
Save