Browse Source

add a script for dumping contents

master
TA 4 years ago
parent
commit
32d5b6ed7c
3 changed files with 24 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +2
    -0
      app.py
  3. +20
    -0
      dump_contents.py

+ 2
- 0
.gitignore View File

@ -145,3 +145,5 @@ dmypy.json
# Cython debug symbols # Cython debug symbols
cython_debug/ cython_debug/
# custom generated files
tmp/

+ 2
- 0
app.py View File

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from functools import wraps from functools import wraps
from flask import Flask, request, render_template, send_from_directory, abort, redirect, session from flask import Flask, request, render_template, send_from_directory, abort, redirect, session
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy

+ 20
- 0
dump_contents.py View File

@ -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))

Loading…
Cancel
Save