diff --git a/Padliography.egg-info/PKG-INFO b/Padliography.egg-info/PKG-INFO new file mode 100644 index 0000000..3e89f09 --- /dev/null +++ b/Padliography.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 2.1 +Name: Padliography +Version: 2.0.0 +Summary: UNKNOWN +Home-page: UNKNOWN +License: UNKNOWN +Platform: UNKNOWN + +UNKNOWN + diff --git a/Padliography.egg-info/SOURCES.txt b/Padliography.egg-info/SOURCES.txt new file mode 100644 index 0000000..af563eb --- /dev/null +++ b/Padliography.egg-info/SOURCES.txt @@ -0,0 +1,8 @@ +README.md +setup.py +Padliography.egg-info/PKG-INFO +Padliography.egg-info/SOURCES.txt +Padliography.egg-info/dependency_links.txt +Padliography.egg-info/not-zip-safe +Padliography.egg-info/requires.txt +Padliography.egg-info/top_level.txt \ No newline at end of file diff --git a/Padliography.egg-info/dependency_links.txt b/Padliography.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Padliography.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/Padliography.egg-info/not-zip-safe b/Padliography.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Padliography.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/Padliography.egg-info/requires.txt b/Padliography.egg-info/requires.txt new file mode 100644 index 0000000..17e1e46 --- /dev/null +++ b/Padliography.egg-info/requires.txt @@ -0,0 +1,4 @@ +flask +bs4 +mwclient +python-dotenv diff --git a/Padliography.egg-info/top_level.txt b/Padliography.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Padliography.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/pad-bis.py b/pad-bis.py index 26e2a13..f7ff2ed 100644 --- a/pad-bis.py +++ b/pad-bis.py @@ -18,6 +18,9 @@ load_dotenv(dotenv_path=dotenv_path) # load the configuration env load_dotenv() +DEFAULT_PAGE = os.environ.get("DEFAULT_PAGE", '') + + # prefix to add /soupboat/padliography to all the routes class PrefixMiddleware(object): def __init__(self, app, prefix=""): @@ -46,7 +49,7 @@ app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=base_url) def add_pad(padliography, link, title, overview, categories, date): '''Add a new pad to the wiki page''' - + # 1. Connect to the wiki site = mwclient.Site('pzwiki.wdka.nl', path='/mw-mediadesign/') @@ -58,6 +61,9 @@ def add_pad(padliography, link, title, overview, categories, date): ) # 3. Select the page and get the contents + # --> prefix the page title with Padliography/ + # so we dont erase eventual pages with the same title + padliography = f'Padliography/{padliography}' page = site.pages[padliography] text = page.text() @@ -83,6 +89,8 @@ def get_pads(padliography): ) # 3. Use the MediaWiki API to get the wikitext contents in HTML + # Pages in the padliography comes with the Padliography/ prefix + padliography = f'Padliography/{padliography}' html = site.api('parse', prop='text', page=padliography) # 4. Parse the HTML with BeautifulSoup to extract data from the table of pads @@ -111,22 +119,24 @@ def init_page(padliography, description): site = mwclient.Site('pzwiki.wdka.nl', path='/mw-mediadesign/') # 2. Authenticate using the credential of a bot user registered in the wiki - ### This is necesary the edit the contents of the page + # This is necesary the edit the contents of the page site.login( username=os.environ.get('MW_BOT'), password=os.environ.get('MW_KEY') ) # 3. Select the page and get the contents + # page in the padliography comes with the Padliography/ prefix + padliography = f'Padliography/{padliography}' page = site.pages[padliography] - # 4. Insert the table template and a user-provided description + # 4. Insert the table template and a user-provided description - text = f''' + text = f''' {description} == Padliography == - + {{| class = "wikitable sortable padliography" |- !link !! title !! overview !! categories !! date @@ -138,18 +148,24 @@ def init_page(padliography, description): ''' # 5. Apply the edit - page.edit(textwrap.dedent(text), f'New padliographish page created: {padliography}') - + page.edit(textwrap.dedent(text), f'New padliographish page created: Pads/{padliography}') + # Routes @app.route('/') def home(): '''Serve the homepage layout''' - return render_template('home.html') + return render_template('home.html', page=DEFAULT_PAGE) + +@app.route('//') +def page(padliography): + '''Serve a specific padliography''' + return render_template('home.html', page=padliography) -@app.route('/api/', methods=['GET', 'POST']) + +@app.route('/api//', methods=['GET', 'POST']) def api(padliography): '''Manage the interaction with the MediaWiki API''' @@ -171,15 +187,18 @@ def api(padliography): response.headers.add('Access-Control-Allow-Origin', '*') return response + @app.route('/api//init', methods=['GET', 'POST']) def init(padliography): if request.method == 'POST': description = request.json.get('description', None) - if padliography != None: + if padliography is not None: init_page(padliography, description) return redirect(url_for('home')) return 'ok' + # Get the port and mount the app port = os.environ.get('FLASK_RUN_PORT', '') -app.run(port=port) +debug = os.environ.get('DEBUG', False) +app.run(port=port, debug=debug) diff --git a/static/css/style.css b/static/css/style.css index 8a7c152..f9cce21 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -260,6 +260,10 @@ td.categories { opacity: 1; } +.hidden { +visibility: hidden; +} + @keyframes grow { from { transform: scale(100%); diff --git a/static/js/PadStore.js b/static/js/PadStore.js index 1a3b646..ac7318e 100644 --- a/static/js/PadStore.js +++ b/static/js/PadStore.js @@ -1,7 +1,7 @@ const { ref } = Vue; const padStore = ref([]); -const currentPage = ref("Padliography2"); +const currentPage = ref(""); export default function padliographyStore() { return { padStore, currentPage }; diff --git a/static/js/PadTable.js b/static/js/PadTable.js index 1499cfa..8dc3520 100644 --- a/static/js/PadTable.js +++ b/static/js/PadTable.js @@ -13,7 +13,7 @@ export default { const pageDescription = ref(""); const initialize = function () { - fetch(`api/${initPage.value}/init`, { + fetch(`/api/${initPage.value}/init`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -37,7 +37,7 @@ export default { }; watchEffect(() => { - fetch(`api/${currentPage.value}`) + fetch(`/api/${currentPage.value}`) .then((res) => res.json()) .then((data) => { pads.value = data.pads; @@ -151,7 +151,7 @@ export default { - {{currentPage}} + {{currentPage}}
diff --git a/templates/home.html b/templates/home.html index cdf606c..b0efc31 100644 --- a/templates/home.html +++ b/templates/home.html @@ -14,12 +14,16 @@ - +