From Wikipedia, the free encyclopedia
import sys
import datetime
import urllib.request as request
import re

WIKI_FEATURED_ARTICLE_START_YEAR = 2003

def update_wbfan():
    today = datetime.date.today()
    total_noms_list = []
    for year in range(today.year, WIKI_FEATURED_ARTICLE_START_YEAR - 1, -1):
        fa_nom_file = "FAnoms." + str(year)
        print ('Reading file: ' + fa_nom_file)
        with open(fa_nom_file) as file:
            file_lines = file.readlines()
            total_noms_list.extend(file_lines)

    noms_by_user_dict = {}
    user_compare_alias_dict = {}

    for entry in total_noms_list:
        if ('|| ' in entry):
            split_entry = entry.strip().split('||')
            # Gets article name from list that can be either len 3 or 4 due to unclean data
            article_name = split_entry[-3].replace(' [[', '').replace(']] ', '')
            if (re.search(r'\[+', article_name) and '<s>' not in article_name):
                if (article_name.rfind('[') > -1):
                    article_name = article_name[article_name.rfind('[') + 1:article_name.index(']')]
            if (re.search(r'\|', article_name)):
                article_name = article_name[:article_name.index('|')]
                if ('<s>' in article_name):
                    article_name += ']]</s>'
            if (re.search(r'\'\'', article_name)):
                article_name = article_name.replace('\'\'', '')
            # Gets usernames from list that can be either len 3 or 4 due to unclean data
            user_string = split_entry[-1]
            username_list = []
            if (user_string):
                username_list.append(user_string[user_string.index('['):user_string.index(']') + 2])

            if (']] &' in user_string):
                multinom = re.split('\s&', user_string)
                for nom in multinom:
                    nom = nom[nom.index('['):nom.index(']') + 2]
                    if (nom not in username_list):
                        username_list.append(nom)

            for name in username_list:
                stripped_name = name[name.index(':') + 1:name.index('|')]
                case_sensisitive_name_part = stripped_name[1:]
                case_insensitive_name_part = stripped_name[0]
                lowercase_name = case_insensitive_name_part.lower() + case_sensisitive_name_part
                uppercase_name = case_insensitive_name_part.upper() + case_sensisitive_name_part
                if (lowercase_name not in noms_by_user_dict and uppercase_name not in noms_by_user_dict):
                    noms_by_user_dict[stripped_name] = {'article': [], 'count': 0, 'fullUsername': name}
                if (stripped_name not in noms_by_user_dict):
                    if (stripped_name == lowercase_name):
                        stripped_name = uppercase_name
                    elif (stripped_name == uppercase_name):
                        stripped_name = lowercase_name
                    else:
                        print ('Name is not in noms_by_user_dict: ' + stripped_name)
                        return -1
                noms_by_user_dict[stripped_name]['article'].append(article_name)
                noms_by_user_dict[stripped_name]['count'] += 1

    with open('WBFAN.table', 'w') as wbfan:
        for user in sorted(noms_by_user_dict, key = lambda key: (-noms_by_user_dict[key]['count'], noms_by_user_dict[key]['fullUsername'].upper())):
            if (user and 'Sasata' not in user):
                print ('|-', file=wbfan)
                print ('| ' + noms_by_user_dict[user]['fullUsername'], file=wbfan)
                counted_articles = 0
                for article in noms_by_user_dict[user]['article']:
                    if ('<s>' in article):
                        article_to_add = article.replace('<s>', '').replace('</s>', '').replace('[[', '').replace(']]', '')
                        print ('| [[' + article_to_add.strip() + '|☆]]', file=wbfan)
                    else:
                        print ('| [[' + article + '|★]]', file=wbfan)
                    counted_articles += 1
                    if ((counted_articles % 20) == 0 and noms_by_user_dict[user]['count'] - counted_articles > 0):
                        print ('|-', file=wbfan)
                        print ('||', file=wbfan)
    wbfan.close()
    write_wbfan_page()

def write_wbfan_page():
    with open('WBFAN', 'w') as wbfan, open('testWBFANintro.txt') as intro, open('WBFAN.table') as table, open('testWBFANoutro.txt') as outro:
        for line in intro:
            print (line.strip(), file=wbfan)
        for entry in table:
            print (entry.strip(), file=wbfan)
        for string in outro:
            print (string.strip(), file=wbfan)
    wbfan.close()

if __name__ == '__main__':
    update_wbfan()

From Wikipedia, the free encyclopedia
import sys
import datetime
import urllib.request as request
import re

WIKI_FEATURED_ARTICLE_START_YEAR = 2003

def update_wbfan():
    today = datetime.date.today()
    total_noms_list = []
    for year in range(today.year, WIKI_FEATURED_ARTICLE_START_YEAR - 1, -1):
        fa_nom_file = "FAnoms." + str(year)
        print ('Reading file: ' + fa_nom_file)
        with open(fa_nom_file) as file:
            file_lines = file.readlines()
            total_noms_list.extend(file_lines)

    noms_by_user_dict = {}
    user_compare_alias_dict = {}

    for entry in total_noms_list:
        if ('|| ' in entry):
            split_entry = entry.strip().split('||')
            # Gets article name from list that can be either len 3 or 4 due to unclean data
            article_name = split_entry[-3].replace(' [[', '').replace(']] ', '')
            if (re.search(r'\[+', article_name) and '<s>' not in article_name):
                if (article_name.rfind('[') > -1):
                    article_name = article_name[article_name.rfind('[') + 1:article_name.index(']')]
            if (re.search(r'\|', article_name)):
                article_name = article_name[:article_name.index('|')]
                if ('<s>' in article_name):
                    article_name += ']]</s>'
            if (re.search(r'\'\'', article_name)):
                article_name = article_name.replace('\'\'', '')
            # Gets usernames from list that can be either len 3 or 4 due to unclean data
            user_string = split_entry[-1]
            username_list = []
            if (user_string):
                username_list.append(user_string[user_string.index('['):user_string.index(']') + 2])

            if (']] &' in user_string):
                multinom = re.split('\s&', user_string)
                for nom in multinom:
                    nom = nom[nom.index('['):nom.index(']') + 2]
                    if (nom not in username_list):
                        username_list.append(nom)

            for name in username_list:
                stripped_name = name[name.index(':') + 1:name.index('|')]
                case_sensisitive_name_part = stripped_name[1:]
                case_insensitive_name_part = stripped_name[0]
                lowercase_name = case_insensitive_name_part.lower() + case_sensisitive_name_part
                uppercase_name = case_insensitive_name_part.upper() + case_sensisitive_name_part
                if (lowercase_name not in noms_by_user_dict and uppercase_name not in noms_by_user_dict):
                    noms_by_user_dict[stripped_name] = {'article': [], 'count': 0, 'fullUsername': name}
                if (stripped_name not in noms_by_user_dict):
                    if (stripped_name == lowercase_name):
                        stripped_name = uppercase_name
                    elif (stripped_name == uppercase_name):
                        stripped_name = lowercase_name
                    else:
                        print ('Name is not in noms_by_user_dict: ' + stripped_name)
                        return -1
                noms_by_user_dict[stripped_name]['article'].append(article_name)
                noms_by_user_dict[stripped_name]['count'] += 1

    with open('WBFAN.table', 'w') as wbfan:
        for user in sorted(noms_by_user_dict, key = lambda key: (-noms_by_user_dict[key]['count'], noms_by_user_dict[key]['fullUsername'].upper())):
            if (user and 'Sasata' not in user):
                print ('|-', file=wbfan)
                print ('| ' + noms_by_user_dict[user]['fullUsername'], file=wbfan)
                counted_articles = 0
                for article in noms_by_user_dict[user]['article']:
                    if ('<s>' in article):
                        article_to_add = article.replace('<s>', '').replace('</s>', '').replace('[[', '').replace(']]', '')
                        print ('| [[' + article_to_add.strip() + '|☆]]', file=wbfan)
                    else:
                        print ('| [[' + article + '|★]]', file=wbfan)
                    counted_articles += 1
                    if ((counted_articles % 20) == 0 and noms_by_user_dict[user]['count'] - counted_articles > 0):
                        print ('|-', file=wbfan)
                        print ('||', file=wbfan)
    wbfan.close()
    write_wbfan_page()

def write_wbfan_page():
    with open('WBFAN', 'w') as wbfan, open('testWBFANintro.txt') as intro, open('WBFAN.table') as table, open('testWBFANoutro.txt') as outro:
        for line in intro:
            print (line.strip(), file=wbfan)
        for entry in table:
            print (entry.strip(), file=wbfan)
        for string in outro:
            print (string.strip(), file=wbfan)
    wbfan.close()

if __name__ == '__main__':
    update_wbfan()


Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook