-
Notifications
You must be signed in to change notification settings - Fork 1
/
export.py
39 lines (29 loc) · 1.08 KB
/
export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
import os
import sys
from typing import Optional
from data_access import DataAccess
class Export:
def __init__(self, root_dir: Optional[str] = None):
self.root_dir = root_dir or os.getcwd()
self.export_dir = os.path.join(self.root_dir, "exports")
def export_video_ids_tsv(self):
da = DataAccess()
videos = da.get_all_videos(sort=True)
with open(
os.path.join(self.export_dir, "vids.tsv"), mode="w", encoding="utf-8"
) as f:
f.write(f"video_id\tvideo_title\n")
for video in videos:
vtitle = video["snippet"]["title"]
f.write(f"{video['id']}\t{vtitle}\n")
def export_video_ids_json(self):
da = DataAccess()
videos = da.get_all_videos(sort=True)
vids = [video["id"] for video in videos]
with open(os.path.join(self.export_dir, "video_ids.txt"), mode="w") as f:
f.write(json.dumps(vids, indent=2))
if __name__ == "__main__":
export = Export()
export.export_video_ids_tsv()
export.export_video_ids_json()