|
|
|
@ -20,6 +20,7 @@ load_dotenv(dotenv_path=dotenv_path)
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
|
|
# prefix to add /soupboat/padliography to all the routes
|
|
|
|
|
|
|
|
|
|
class PrefixMiddleware(object):
|
|
|
|
|
def __init__(self, app, prefix=""):
|
|
|
|
|
self.app = app
|
|
|
|
@ -45,10 +46,10 @@ base_url = os.environ.get('BASE_URL', '')
|
|
|
|
|
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=base_url)
|
|
|
|
|
|
|
|
|
|
# Page of the wiki with the pads
|
|
|
|
|
padliography = os.environ.get('PAGE', '')
|
|
|
|
|
# padliography = os.environ.get('PAGE', '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_pad(link, title, overview, categories, date):
|
|
|
|
|
def add_pad(padliography, link, title, overview, categories, date):
|
|
|
|
|
'''Add a new pad to the wiki page'''
|
|
|
|
|
|
|
|
|
|
# 1. Connect to the wiki
|
|
|
|
@ -73,7 +74,7 @@ def add_pad(link, title, overview, categories, date):
|
|
|
|
|
page.edit(text, f'New pad in the {padliography}: {title}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_pads():
|
|
|
|
|
def get_pads(padliography):
|
|
|
|
|
'''Retrieve pads from the wiki'''
|
|
|
|
|
|
|
|
|
|
# 1. Connect to the wiki
|
|
|
|
@ -107,6 +108,41 @@ def get_pads():
|
|
|
|
|
|
|
|
|
|
return pads
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_page(padliography, description):
|
|
|
|
|
'''Initialize a new instance of the padliography a the given page'''
|
|
|
|
|
|
|
|
|
|
# 1. Connect to the wiki
|
|
|
|
|
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
|
|
|
|
|
site.login(
|
|
|
|
|
username=os.environ.get('MW_BOT'),
|
|
|
|
|
password=os.environ.get('MW_KEY')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 3. Select the page and get the contents
|
|
|
|
|
page = site.pages[padliography]
|
|
|
|
|
|
|
|
|
|
# 4. Insert the table template and a user-provided description
|
|
|
|
|
|
|
|
|
|
text = '''
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
== Padliography ==
|
|
|
|
|
|
|
|
|
|
{| class = "wikitable sortable padliography"
|
|
|
|
|
|-
|
|
|
|
|
!link !! title !! overview !! categories !! date
|
|
|
|
|
|-
|
|
|
|
|
|}
|
|
|
|
|
'''.format(description)
|
|
|
|
|
|
|
|
|
|
# 5. Apply the edit
|
|
|
|
|
page.edit(text, f'New padliographish page created: {padliography}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Routes
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
@ -115,8 +151,8 @@ def home():
|
|
|
|
|
return render_template('home.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/api', methods=['GET', 'POST'])
|
|
|
|
|
def api():
|
|
|
|
|
@app.route('/api/<padliography>', methods=['GET', 'POST'])
|
|
|
|
|
def api(padliography):
|
|
|
|
|
'''Manage the interaction with the MediaWiki API'''
|
|
|
|
|
|
|
|
|
|
# Add a new pad
|
|
|
|
@ -127,13 +163,12 @@ def api():
|
|
|
|
|
categories = request.json.get('categories', '')
|
|
|
|
|
date = request.json.get('date', None)
|
|
|
|
|
|
|
|
|
|
add_pad(link, title, overview, categories, date)
|
|
|
|
|
add_pad(padliography, link, title, overview, categories, date)
|
|
|
|
|
redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
|
# Return the pad list
|
|
|
|
|
response = jsonify({
|
|
|
|
|
'page': padliography,
|
|
|
|
|
'pads': get_pads()
|
|
|
|
|
'pads': get_pads(padliography)
|
|
|
|
|
})
|
|
|
|
|
response.headers.add('Access-Control-Allow-Origin', '*')
|
|
|
|
|
|
|
|
|
|