cleaning static_html dir beefore creating new html

andre
Castro0o 5 years ago
parent 6337a577d5
commit 5d4edaaf23

@ -59,3 +59,6 @@ Run scripts together with `./run.sh`
## TODO ## TODO
* remove HTML files at each new query * remove HTML files at each new query
* revise `def unpack_response()` so that it returns the values of all properties printed out
* revise template so that they include the values of all properties printed out \
and do not break on missing values

@ -51,7 +51,7 @@ def unpack_response(response):
else: else:
val = list(prop_val.values())[0] val = list(prop_val.values())[0]
d[prop] = val d[prop] = val
return(d) return d
def update_json(imgsjson_fn, img_dict, img_fn): def update_json(imgsjson_fn, img_dict, img_fn):
@ -86,6 +86,14 @@ def update_json(imgsjson_fn, img_dict, img_fn):
return download return download
def clean_dir(dirfullpath):
for f in os.listdir(dirfullpath):
f = os.path.join(dirfullpath, f)
if os.path.isfile(f):
os.remove(f)
class Colors: class Colors:
HEADER = '\033[95m' HEADER = '\033[95m'
BLUE = '\033[94m' BLUE = '\033[94m'

@ -2,7 +2,7 @@ import os, json, sys, urllib
from mwclient import Site from mwclient import Site
from pprint import pprint from pprint import pprint
from jinja2 import Template from jinja2 import Template
from functions import pandoc, page_props, unpack_response from functions import pandoc, page_props, unpack_response, clean_dir
from functions import Colors from functions import Colors
import argparse import argparse
@ -48,13 +48,14 @@ if args.dry is True:
site = Site(host=args.host, path=args.path) site = Site(host=args.host, path=args.path)
wd = os.path.dirname(os.path.abspath(__file__)) # working directory wd = os.path.dirname(os.path.abspath(__file__)) # working directory
imgdir = os.path.join(wd, 'images') imgdir = os.path.join(wd, 'images')
imgsjson_fn = os.path.join(wd, 'images.json') imgsjson_fn = os.path.join(wd, 'images.json')
with open(imgsjson_fn, 'r') as imgsjson_file: with open(imgsjson_fn, 'r') as imgsjson_file:
images_info = json.load(imgsjson_file) images_info = json.load(imgsjson_file)
static_html = os.path.join(wd, 'static_html') static_html = os.path.join(wd, 'static_html')
os.makedirs(static_html, exist_ok=True) # create images/ dir os.makedirs(static_html, exist_ok=True) # create static_html/ dir
clean_dir(static_html) # if static_html exists and has files or dirs: clean it
with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
loginlines = login.read() loginlines = login.read()
@ -104,7 +105,6 @@ for answer in site.ask(query):
# print(pub_html, '\n') # print(pub_html, '\n')
pub_parts_html = '' # Reset pub_parts_html pub_parts_html = '' # Reset pub_parts_html
# TODO: queries without Part?
# TODO: include Creator Property value # TODO: include Creator Property value
# TODO: address Dates: # TODO: address Dates:

Loading…
Cancel
Save