diff --git a/src/constants.py b/src/constants.py index c0e05e8..12a43e0 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,13 +1,7 @@ -import os - # Constants (The instructors said that we can use global constants here: # https://piazza.com/class/ksovzjrlsye72f?cid=1664 # They should not end with "/" -from pathlib import Path - DATA_DIR = './data' TWEETS_DIR = f'{DATA_DIR}/twitter/user-tweets' USER_DIR = f'{DATA_DIR}/twitter/user' REPORT_DIR = './report' -# Sources directory. This may be different from the data directory if the running -SRC_DIR = str(Path(os.path.realpath(__file__)).parent) diff --git a/src/report/report.py b/src/report/report.py index 5418339..4aa8ff8 100644 --- a/src/report/report.py +++ b/src/report/report.py @@ -1,19 +1,23 @@ import os.path +from pathlib import Path -import markdown +from flask import Flask, send_from_directory -from constants import SRC_DIR, REPORT_DIR +from constants import REPORT_DIR from utils import read +# Constants +src_dir = Path(os.path.realpath(__file__)).parent + def generate_report() -> str: """ - Do data visualization and generate a HTML report + Compile the report document and generate a markdown report - :return: HTML + :return: Markdown report """ # Load markdown - md = read(f'{SRC_DIR}/report_document.md').replace('\r\n', '\n').split('\n') + md = read(str(src_dir.joinpath('report_document.md'))).replace('\r\n', '\n').split('\n') # Process @include statements for i in range(len(md)): @@ -21,7 +25,10 @@ def generate_report() -> str: if line.startswith('@include'): line = line[line.index('`') + 1:] line = line[:line.index('`')] - md[i] = read(line) + md[i] = read(REPORT_DIR + line) + + return '\n'.join(md) + return markdown.markdown('\n'.join(md), extensions=['tables']) diff --git a/src/report/report_document.md b/src/report/report_document.md index 78e6ff6..0e4b5bc 100644 --- a/src/report/report_document.md +++ b/src/report/report_document.md @@ -3,8 +3,8 @@ Test Image: -![]({REPORT_DIR}/1-covid-tweet-frequency/500-pop.png) +![](/1-covid-tweet-frequency/500-pop.png) Test Include: -@include `{REPORT_DIR}/1-covid-tweet-frequency/500-pop.md` +@include `/1-covid-tweet-frequency/500-pop.md` diff --git a/src/report/report_page.html b/src/report/report_page.html index e31f038..45bb221 100644 --- a/src/report/report_page.html +++ b/src/report/report_page.html @@ -9,9 +9,16 @@ +