API:Article ideas generator

Overview
In this tutorial, you will get a demo of an article ideas generator app that suggests articles from various categories that don't yet exist on English Wikipedia. Download the code from Github This tutorial will teach you how to do this using:


 * Python and Flask framework
 * MediaWiki Action API’s Parse and Links module

Building this application will be a four-step process:

Step 1: Set up Python and Flask development environment
To set up the Python development environment for a Flask application, you will need to install Python, create a virtual environment and install Flask.

Note: This application uses Python3, the recommended version for new Python projects. Learn more about the differences between Python2 and Python3 here. To install Python3 on your local machine, follow step-by-step instructions in these installation guides.

Here is how to set up the development environment for building the application:

Render a simple static page
Place the following code in Drop this one line of code   in a HTML file inside the   folder:

Note: In this simple application, we are using  method which renders the template named   from the   directory.

Next run your flask app with the command  and open   to view your app in the browser. You should be able to see "Article ideas generator" in your browser window.

Style your app
Let's do some app styling. To do so, add link tags to load an external and internal stylesheet. External stylesheet, in this case, is the URL of a CSS file for a Google Font.

Replace the existing code in  with the following: Place the following code in

Application layout
$HOME/article-ideas-generator ├── templates/ │  └── articles.html ├── static/ │  └── static.css ├── articles.py └── venv/

Step 3: Fetch page sections from Wikipedia:Requested_articles
Let's write some code in a  function in   to fetch page sections from Wikipedia:Requested_articles. This function takes page name as an argument and makes a  request to the Action API to parse sections of the page. API call consists of an endpoint  and query string parameters. Some of the key parameters are:


 * module to parse content on a page
 * page title to parse
 * tells which piece of information to retrieve, in this example it is sections

Note: For more information on the parse module visit API:Parse. Next, extend the Python Flask route  in   to call the function defined above and also pass the results returned by the function to. Place the following Jinjatemplate code in. It dynamically renders an array of buttons with help from page sections data obtained via the API above.