From 32d5b6ed7caa8d1d2a74442a0d5a12785c2d99db Mon Sep 17 00:00:00 2001 From: TA Date: Wed, 4 Nov 2020 23:19:08 +0800 Subject: [PATCH] add a script for dumping contents --- .gitignore | 2 ++ app.py | 2 ++ dump_contents.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 dump_contents.py diff --git a/.gitignore b/.gitignore index 41810c6..e52575b 100644 --- a/.gitignore +++ b/.gitignore @@ -145,3 +145,5 @@ dmypy.json # Cython debug symbols cython_debug/ +# custom generated files +tmp/ diff --git a/app.py b/app.py index 2f9ffbd..1fa8023 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from functools import wraps from flask import Flask, request, render_template, send_from_directory, abort, redirect, session from flask_sqlalchemy import SQLAlchemy diff --git a/dump_contents.py b/dump_contents.py new file mode 100644 index 0000000..4ee2f79 --- /dev/null +++ b/dump_contents.py @@ -0,0 +1,20 @@ +# This script should be runned in the root directory of the ordinary web +# This script will create contents.json and contents.txt in tmp/ +# the only difference of them is the format. + +import json, os +from app import * + +contents = Candidate.query.all() +contents = list(map(lambda x: x.content, Candidate.query.all())) +contents = list(map(lambda s: s.replace('/r', ''), contents)) + +os.makedirs('tmp/', exist_ok = True) + +with open('tmp/contents.json', 'w') as f: + json.dump(contents, f) + +for i in range(len(contents)): + contents[i] = 'No. ' + str(i + 1) + ':\n' + contents[i] +with open('tmp/contents.txt', 'w') as f: + f.write('\n\n\n\n'.join(contents))