Last active
June 14, 2016 06:38
-
-
Save Tronde/a34f7639bc5f92fa53e8cb8bc4d9305b to your computer and use it in GitHub Desktop.
UWR-ausbaufaehige-Artikel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- encoding: utf-8 -*- | |
# | |
# Beschreibung: | |
# Dieses Skript erstellt den Quelltext der ausbaufaehigen Wiki-Artikel | |
# fuer den UWR. Es muessen nur noch die Beschreibungen eingefuegt werden. | |
# | |
# Version: 0.4 (2016-06-14) | |
# Autor: Tronde (https://ubuntuusers.de/user/Tronde/) | |
# Lizenz: GPLv3 (http://www.gnu.de/documents/gpl.de.html) | |
import re | |
import random | |
from urllib.request import urlopen | |
from bs4 import BeautifulSoup | |
soup = BeautifulSoup(urlopen('https://wiki.ubuntuusers.de/Wiki/Vorlagen/Ausbauf%C3%A4hig/a/backlinks/')) | |
div_tag = BeautifulSoup(str(soup.find_all(class_=re.compile("content_tabbar")))) | |
link_list = [] | |
for link in div_tag.ul.find_all('a'): | |
link_list.append(link.text) | |
rand_list = [] | |
num_to_select = 5 | |
rand_list = random.sample(link_list, num_to_select) | |
# Erstellung Tabelle | |
table = """ | |
{{{#!vorlage Tabelle | |
<rowclass="kopf"; :>Artikel | |
<:>Beschreibung | |
""" | |
highlight = False | |
for i in rand_list: | |
if highlight: | |
table += "+++\n" | |
table += '<rowclass="highlight">[:' + i + ":]\n" | |
table += "ausbaufähig\n" | |
else: | |
table += "+++\n" | |
table += "[:" + i + ":]\n" | |
table += "ausbaufähig\n" | |
highlight = not(highlight) | |
table += "}}}" | |
print(table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment