API:Article ideas generator/hu

Áttekintés
Ebben az útmutatóban egy változatos kategóriákból az angol Wikipédián még nem létező szócikkeket javasló szócikkötlet-generáló alkalmazás demonstrációját kapod.

Kód letöltése GitHubon Alkalmazás a Toolforge-on

Ez az útmutató abban segít, hogy tedd meg ezt az alábbiak használatával:


 * Python, Flask keretrendszer és az Requests könyvtár
 * A MediaWiki Action API Parse és Links modulja

Az alkalmazás telepítése lépésről lépésre:



1. lépés: A Python és Flask fejlesztőkörnyezet telepítése
To set up the Python development environment for a Flask application, you will need to install Python, create a virtual environment, and install Flask and Requests.

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 Article ideas generator in a HTML file inside the  folder:

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 the font.

Replace the existing code in  with the following:

Place the following code in

Application layout
$HOME/article-ideas-generator ├── templates/ │  └── articles.html ├── static/ │  └── style.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

Next, extend the Python Flask route  in   to call the function defined above and also pass the results returned by the function to.

Helyezd el az alábbi Jinja sablonkódot a -be. It dynamically renders an array of category buttons based on page sections obtained via the API above.

Helyezd el az alábbi kódot a -be a gombkinézet megváltoztatásához.

Step 4: Get more sections based on user selection
Based on a category or section selected by the user in the previous step, we want to fetch subsections from Wikipedia:Requested articles. Extend the Python Flask route  in   to handle POST requests. You can do so by adding both  and   in the   argument list in the route decorator. You can then obtain category selection available in a  format from the   object, which is passed to   function for further processing.



5. lépés: A hiányzó linkekkel rendelkező cikkek kigyűjtése és megjelenítése
Let's write some code in a  function in   to fetch around 20 articles with missing links on a page. This function takes page name as an argument, makes a  request to the Action API, and returns all links embedded on that page. From further extraction, you can obtain those links that are missing and don't yet exist on English Wikipedia. The API call consists of an endpoint  and query string parameters. Some of the key parameters are:


 * - module to query information
 * - oldalcím a linkek kigyűjtéséhez
 * - query module's submodule  used as a generator module to get a set of links embedded on a page
 * - kinyerendő linkek száma

Next, extend the  block for the   method in the   route in   to call the   function if the page from which the request is issued is of type.

Place the following Jinja template code in. It dynamically renders a list of links using data obtained via the API above.

View the complete Python, CSS, and HTML code.



Következő lépések

 * Contribute a demo app that you have developed using the MediaWiki API to this code samples repository.



Lásd még

 * Flask-oktatóanyagok
 * Flask-oktatóanyagok
 * Flask-oktatóanyagok