diff --git a/yamabiko.py b/yamabiko.py new file mode 100644 index 0000000..5a942c2 --- /dev/null +++ b/yamabiko.py @@ -0,0 +1,95 @@ +import json +import argparse + +from datetime import datetime + + +def get_arguments(): + all_args = argparse.ArgumentParser() + + all_args.add_argument("-i", "--Json", required=True, + help="Choose the JSON file with the comment data") + all_args.add_argument("-v", "--Video", required=False, + help="OPTIONAL: Choose the video file") + + args = vars(all_args.parse_args()) + + return args + + +def view_json_video(cli_args): + with open(cli_args['Json']) as f: + json_load = json.load(f) + data = json_load['comments'] + + video = cli_args['Video'] + + return data, video + + +def create_html(data_comments, data_video): + # Beginning of the html file + with open('index.html', 'w') as index: + index.write(f""" + + +CommentViewer + + + +

Yamabiko

+

yt-dlp CommentViewer

+ +""") + + # Loading all the comments + for i in data_comments: + with open('index.html', 'a') as index: + index.write(f""" +
+
+

{i['author']} {i['time_text']}

+

{i['text']}

+

Date commented: {datetime.fromtimestamp(i['timestamp']).strftime('%d-%m-%Y')}

+

👍 {i['like_count']}

+
+""") + + # Closing the html file + with open('index.html', 'a') as index: + index.write(f""" +""") + + +if __name__ == '__main__': + arguments = get_arguments() + comments, video_file = view_json_video(arguments) + create_html(comments, video_file)