'
1045 | comment_html += '
'
1046 | comment_html += f'{comment_item.author_nickname}'
1047 | comment_html += f'{format_epoch(comment_item.created_at, "%Y-%m-%d %H:%M:%S")}'
1048 | comment_html += '
'
1049 | comment_html += f'
{comment_item.body}
'
1050 | comment_html += '
'
1051 |
1052 | os.makedirs(current_location, exist_ok=True)
1053 | post_filename = f"{current_location}/{current_date} {current_target.post_id}-post.html"
1054 | if opt_realname:
1055 | filename_safe_title = tool_regex_window_name(tool_remove_emoji(current_target.title, "_", True))
1056 | max_len_name = tool_max_len_filename(
1057 | current_location,
1058 | f"{current_date} {filename_safe_title}",
1059 | "html"
1060 | )
1061 | post_real_name = f"{current_location}/{max_len_name}.html"
1062 | try:
1063 | open(post_real_name, "w").close()
1064 | except OSError:
1065 | pass
1066 | else:
1067 | post_filename = post_real_name
1068 |
1069 | with open(post_filename, encoding="utf8", mode="w") as f:
1070 | f.write(str(soup))
1071 | f.write(comment_html)
1072 |
1073 | report_log(i18n.dn_done)
1074 |
1075 | # Write meta
1076 | tool_write_meta(
1077 | location=current_location,
1078 | post_id=current_target.post_id,
1079 | title=current_target.title,
1080 | content_type=current_target.content_type,
1081 | author_nickname=current_target.author_nickname,
1082 | created_at=current_target.created_at,
1083 | )
1084 | with open(f"cache/{channel_board_pair}.txt", encoding="utf8", mode="a") as f:
1085 | f.write(f"{current_target.post_id}\n")
1086 | time.sleep(0.2)
1087 |
1088 | # Download End
1089 | report_progress(100)
1090 |
1091 | progress_dialog(
1092 | title=i18n.dn_progress_tile,
1093 | text=i18n.dn_progress_text,
1094 | run_callback=callback_fn
1095 | ).run()
1096 |
1097 |
1098 | def main():
1099 | os.makedirs("downloaded", exist_ok=True)
1100 | os.makedirs("cache", exist_ok=True)
1101 | clear()
1102 | easy_mode = query_workflow_select()
1103 |
1104 | target_channel, target_board = query_download_url()
1105 |
1106 | membership = query_membership()
1107 |
1108 | # Select option on adv-mode
1109 | if easy_mode:
1110 | opt_ovp = True
1111 | opt_post = True
1112 | opt_amount = 0
1113 |
1114 | else:
1115 | opt_ovp, opt_post, opt_amount = query_options()
1116 |
1117 | if not opt_ovp and not opt_post:
1118 | return dialog_download_end()
1119 |
1120 | post_list = proc_load_post_list(
1121 | target_channel=target_channel,
1122 | target_board=target_board,
1123 | target_amount=opt_amount,
1124 | membership=membership,
1125 | )
1126 | if post_list is None:
1127 | dialog_error_message(i18n.permission_error)
1128 | return dialog_download_end()
1129 |
1130 | post_list = query_use_cache(target_channel, target_board, post_list)
1131 |
1132 | # Post select dialog on adv-mode
1133 | if not easy_mode:
1134 | post_list = query_post_select(post_list, opt_ovp, opt_post)
1135 |
1136 | if len(post_list) == 0:
1137 | message_dialog(i18n.post_list_title, i18n.no_post_error).run()
1138 |
1139 | else:
1140 | opt_realname = query_realname()
1141 |
1142 | # Downloader Query
1143 | proc_downloader(post_list, target_channel, target_board, opt_realname)
1144 |
1145 | return dialog_download_end()
1146 |
1147 |
1148 | if __name__ == '__main__':
1149 | select_lang()
1150 | query_update(dialog_splash())
1151 |
1152 | query_license_agreement()
1153 |
1154 | while True:
1155 | if main():
1156 | continue
1157 | else:
1158 | shutdown()
1159 |
--------------------------------------------------------------------------------