SqlText = NewType('SqlText', str)
AmountDownloads = NewType('AmountDownloads', int)
PlayerUpdateId = NewType('PlayerUpdateId', str)
-QuotaLog: TypeAlias = dict[DatetimeStr, QuotaCost]
DownloadsDb: TypeAlias = dict[VideoId, PathStr]
TemplateContext: TypeAlias = dict[
str, None | bool | PlayerUpdateId | PathStr | VideoId | QueryText
(query_id, self.id_))
-class DbQuotaCost(DbData):
+class QuotaLog(DbData):
"""Collects API access quota costs."""
_table_name = 'quota_costs'
_cols = ('id_', 'timestamp', 'cost')
def collect_results(query_txt: QueryText) -> list[VideoData]:
youtube = googleapiclient.discovery.build('youtube', 'v3',
developerKey=API_KEY)
- DbQuotaCost.update(conn, QUOTA_COST_YOUTUBE_SEARCH)
+ QuotaLog.update(conn, QUOTA_COST_YOUTUBE_SEARCH)
search_request = youtube.search().list(
q=query_txt,
part='snippet',
title=snippet['title'],
description=snippet['description'],
published_at=snippet['publishedAt'])]
- DbQuotaCost.update(conn, QUOTA_COST_YOUTUBE_DETAILS)
+ QuotaLog.update(conn, QUOTA_COST_YOUTUBE_DETAILS)
ids_for_details = ','.join([r.id_ for r in results])
videos_request = youtube.videos().list(id=ids_for_details,
part='content_details')
def _send_queries_index_and_search(self) -> None:
conn = DatabaseConnection()
- quota_count = DbQuotaCost.current(conn)
+ quota_count = QuotaLog.current(conn)
queries_data = QueryData.get_all(conn)
conn.commit_close()
queries_data.sort(key=lambda q: q.retrieved_at, reverse=True)