def home(): if not 'username' in session: return redirect("/") posts = get_posts(session['username']) return render_template("home.html", posts=posts)
def main(ignore_list, extra_args): file_list = helpers.get_posts() html_strings = dict() non_centered = dict() errCount = 0 if 'skip-html' not in extra_args: print(COLOR.colorize('Checking for errant HTML tags', 'info'), end=' ') for filename in file_list: (html_found, errs) = get_html(filename, ignore_list) html_strings = helpers.merge_dicts(html_strings, html_found) errCount += errs if errs > 0: print(PRINT_FAIL) for key, entry in html_strings.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}: {}'.format(element[0], element[1])) print('') if errs == 0: print(PRINT_OK) if 'center-image' in extra_args: print(COLOR.colorize('\nVerifying images are centered', 'info'), end=' ') for filename in file_list: (found, errs) = check_image_centering(filename) non_centered = helpers.merge_dicts(found, non_centered) errCount += errs if errs > 0: print(PRINT_FAIL) for key, entry in non_centered.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}: {}'.format(element[0], element[1]), end='') if errs == 0: print(PRINT_OK) if 'center-eqs' in extra_args: non_centered = dict() print(COLOR.colorize('\nVerifying equations are centered', 'info'), end=' ') for filename in file_list: (found, errs) = check_eq_centering(filename) non_centered = helpers.merge_dicts(found, non_centered) errCount += errs if errs > 0: print(PRINT_FAIL) for key, entry in non_centered.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}: {}'.format(element[0], element[1], end='')) if errs == 0: print(PRINT_OK) print('\n') ERRPRINT(errCount, completion=True) return(0)
def main(test_args, skip_list): errCount = 0 file_list = helpers.get_posts() for filename in file_list: if re.sub(helpers.PATH, '', filename) not in skip_list: test_array = list() PRINT_FILE_STRING = COLOR.colorize(filename, 'text') print(PRINT_FILE_STRING, end=" - ") test_err_list = list() for arg in test_args: (test_errs, test_err_list) = run_test(filename, arg) errCount += test_errs test_array.append(test_err_list) print('') for error in test_err_list: print(error) ERRPRINT(errCount, completion=True) return (0)
def main(extra_args): file_list = helpers.get_posts() errCount = 0 tag = extra_args["tag"] skip_diff = extra_args["skip_diff"] print(COLOR.colorize(f"\nLooking for {tag}\n", "warn")) for filename in file_list: entries = find_tags(filename, tag) if not entries: msg = COLOR.colorize("No image tags found", "error") print(f"{filename}: {msg}") continue msg = COLOR.colorize(f"{len(entries)} tags found!", "warn") msg2 = COLOR.colorize(f" lines: {list(entries.keys())}", "linenum") print(f"{filename}: {msg} {msg2}") replace_tags(filename, entries) errCount += diff_before_continue(filename, skip_diff) print('\n') ERRPRINT(errCount, completion=True) return(errCount)
def main(ignore_list, extra_args): file_list = helpers.get_posts() html_strings = dict() non_centered = dict() found_tags = dict() errCount = 0 if not extra_args['skip-html']: print(COLOR.colorize('Checking for errant HTML tags', 'info'), end=' ') errs_here = 0 for filename in file_list: (html_found, errs) = get_html(filename, ignore_list) html_strings = helpers.merge_dicts(html_strings, html_found) errs_here += errs errCount += errs if errs_here > 0: print(PRINT_FAIL) for key, entry in html_strings.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}: {}'.format(element[0], element[1])) print('') if errs_here == 0: print(PRINT_OK) if extra_args['img-tag']: tag = extra_args['img-tag'] print(COLOR.colorize('\nVerifying all image tags have been updated', 'info'), end=' ') errs_here = 0 for filename in file_list: (found, errs) = check_image_tags(filename, tag) found_tags = helpers.merge_dicts(found, found_tags) errs_here += errs errCount += errs if errs_here > 0: print(PRINT_FAIL) for key, entry in found_tags.items(): if entry: print(f"{key}\n{PRINT_ERROR}") for element in entry: print(f"{element[0]}: {element[1]}", end='') if errs_here == 0: print(PRINT_OK) else: print(COLOR.colorize('Must run ./script/gen_img!', 'warn')) if extra_args['center-image']: print(COLOR.colorize('\nVerifying images are centered', 'info'), end=' ') errs_here = 0 for filename in file_list: (found, errs) = check_image_centering(filename) non_centered = helpers.merge_dicts(found, non_centered) errs_here += errs errCount += errs if errs_here > 0: print(PRINT_FAIL) for key, entry in non_centered.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}: {}'.format(element[0], element[1]), end='') if errs_here == 0: print(PRINT_OK) if extra_args['center-eqs']: non_centered = dict() errs_here = 0 print(COLOR.colorize('\nVerifying equations are centered', 'info'), end=' ') for filename in file_list: (found, errs) = check_eq_centering(filename) non_centered = helpers.merge_dicts(found, non_centered) errs_here += errs errCount += errs if errs_here > 0: print(PRINT_FAIL) for key, entry in non_centered.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}: {}'.format(element[0], element[1], end='')) if errs_here == 0: print(PRINT_OK) if not extra_args['skip-eq-tags']: bad_tags = dict() errs_here = 0 print(COLOR.colorize('\nVerifying equation tags', 'info'), end=' ') for filename in file_list: (found, errs) = check_old_eq_delim(filename) bad_tags = helpers.merge_dicts(found, bad_tags) errs_here += errs errCount += errs if errs_here > 0: print(PRINT_FAIL) for key, entry in bad_tags.items(): if entry: print('{}\n{}'.format(key, PRINT_ERROR)) for element in entry: print('{}, '.format(element[0]), end='') print() if errs_here == 0: print(PRINT_OK) print('\n') ERRPRINT(errCount, completion=True) return (0)
def get_auth_headers(): return {"Authorization": "Basic admin:admin"} # datetime.strptime(ps[0].get("created"), "%d/%m/%Y %H:%M:%S") def create_posts(posts): data = [] for post in posts: data = { "username": post["author"], "ups": post["ups"], "downs": post["downs"], "subreddit": post["subreddit"], "title": post["title"], "url": post["url"] } r = requests.post(create_post_url, data=data) for comment in post["comments"]: data = {"comment": comment, "title": post["title"]} r = requests.post(create_comments_url, data=data) if __name__ == "__main__": posts = get_posts("Python", write_json=True) create_posts(posts)
def index(): posts = helpers.get_posts() return render_template("index.html", posts=posts)