import pywikibot
import sys
from difflib import context_diff
from pywikibot import pagegenerators
import re

site = pywikibot.Site('zh', 'wikipedia')
ensite = pywikibot.Site('en', 'wikipedia')
repo = site.data_repository() 
def stripstr(s):
    result = re.sub("[\(\[].*?[\)\]]", "", s)
    return result
denmarklist = [
    "Venstre (Denmark)",
    "Danish People's Party",
    "Danish Social Liberal Party",
    "Socialist People's Party (Denmark)",
    "Red–Green Alliance (Denmark)",
    "Conservative People's Party (Denmark)",
    "The Alternative (Denmark)",
    "The New Right (Denmark)",
    "Liberal Alliance (Denmark)",
]

greenlandList = [
    "Siumut"
]

faroeislandsList = [
    "Union Party (Faroe Islands)",
    "Social Democratic Party (Faroe Islands)",
    "Inuit Ataqatigiit",
]

partylist = {
    "denmark": denmarklist,
    "greenland": greenlandList,
    "faroislands": faroislandList
}

namelist = {
    "denmark": "丹麦",
    "greenland": "格陵兰",
    "faroislands": "法罗群岛"
}

def getFinalPage(site, pagename):
    page = pywikibot.Page(site, pagename)
    if(page.isRedirectPage()):
        page=page.getRedirectTarget()
    return page

for entry in list:
    zhpagetitle=None
    zhlabel=None
    page = getFinalPage(ensite, entry)
    item = pywikibot.ItemPage.fromPage(page)
    zhpagetitle = item.sitelinks.get('zhwiki')
    if 'zh-hans' in item.labels:
        zhlabel=item.labels['zh-hans']
    elif 'zh' in item.labels:
        zhlabel=item.labels['zh']
    else:
        zhlabel=zhpagetitle
    zhlabel = stripstr(zhlabel)
    
    print("====")
    print(f"pagename-en: {page.title()}")
    if(zhlabel):
        print(f"label-zh: {zhlabel}")
    else:
        print("label-zh: N/A")
    
    metacolor = getFinalPage(ensite, f"Template:{entry}/meta/color")
    metashortname = getFinalPage(ensite, f"Template:{entry}/meta/shortname")

    print(f"shortname: {metashortname.text}")
    print(f"color: {metacolor.text}")
====
pagename-en: Venstre (Denmark)
label-zh: 丹麦自由党
shortname: Venstre<noinclude>

[[Category:Venstre (Denmark) shortname templates|{{PAGENAME}}]]
</noinclude>
color: <nowiki>#002883</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Venstre (Denmark) colour templates|{{PAGENAME}}]]
</noinclude>
====
pagename-en: Danish People's Party
label-zh: 丹麦人民党
shortname: DPP
color: <nowiki>#FCD03B</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}
[[Category:Denmark political party colour templates|{{PAGENAME}}]]</noinclude>
====
pagename-en: Danish Social Liberal Party
label-zh: 激进左翼党
shortname: Social Liberals<noinclude>

[[Category:Danish Social Liberal Party shortname templates|{{PAGENAME}}]]
</noinclude>
color: <nowiki>#E5007D</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}
[[Category:Danish Social Liberal Party colour templates|{{PAGENAME}}]]
</noinclude>
====
pagename-en: Socialist People's Party (Denmark)
label-zh: 社會人民黨
shortname: SF<noinclude>

[[Category:Socialist People's Party (Denmark) shortname templates|{{PAGENAME}}]]
</noinclude>
color: <nowiki>#BF031A</nowiki><noinclude>
== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}
[[Category:Socialist People's Party (Denmark) colour templates|{{PAGENAME}}]]
</noinclude>
====
pagename-en: Red–Green Alliance (Denmark)
label-zh: 紅綠聯盟
shortname: Red–Green
color: <nowiki>#D0004D</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}
[[Category:Denmark political party colour templates]]</noinclude>
====
pagename-en: Conservative People's Party (Denmark)
label-zh: 保守人民党
shortname: Conservative<noinclude>

[[Category:Conservative People's Party (Denmark) shortname templates|{{PAGENAME}}]]
</noinclude>
color: <nowiki>#004931</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Conservative People's Party (Denmark) colour templates|{{PAGENAME}}]]
</noinclude>
====
pagename-en: The Alternative (Denmark)
label-zh: 替代党
shortname: The Alternative<noinclude>

[[Category:Denmark political party shortname templates|{{PAGENAME}}]]
</noinclude>
color: <nowiki>#00FF00</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Denmark political party colour templates|Alternative]]
</noinclude>
====
pagename-en: The New Right (Denmark)
label-zh: 新右翼(丹麦)
shortname: New Right<noinclude>

[[Category:The New Right (Denmark) shortname templates|{{PAGENAME}}]]
</noinclude>
color: <nowiki>#004451</nowiki><noinclude> <!-- Color used by https://www.berlingske.dk/barometeret -->

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}
[[Category:Denmark political party colour templates|{{PAGENAME}}]]
</noinclude>
====
pagename-en: Liberal Alliance (Denmark)
label-zh: 自由聯盟
shortname: Liberal Alliance
color: <nowiki>#FA4A00</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Denmark political party colour templates|Liberal Alliance]]
</noinclude>
====
pagename-en: Union Party (Faroe Islands)
label-zh: 联合党 
shortname: Union
color: <nowiki>#0C6889</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Faroe Islands political party colour templates|Union Party (Faroe Islands)]]
</noinclude>
====
pagename-en: Social Democratic Party (Faroe Islands)
label-zh: 社会民主党
shortname: {{nowrap|Social Democratic}}
color: <nowiki>#A73033</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Faroe Islands political party colour templates|Social Democratic Party (Faroe Islands)]]
</noinclude>
====
pagename-en: Inuit Ataqatigiit
label-zh: 因纽特社区党
shortname: Inuit Ataqatigiit
color: <nowiki>#AC2429</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Greenland political party colour templates|{{PAGENAME}}]]</noinclude>
====
pagename-en: Siumut
label-zh: 前进党
shortname: Siumut
color: <nowiki>#BF8E00</nowiki><noinclude>

== Examples ==
{|
|- style="color:{{ {{PAGENAME}} }}"
| '''This color'''
|- style="background:{{ {{PAGENAME}} }}; color:white"
| '''White on this color'''
|- style="background:{{ {{PAGENAME}} }}; color:black"
| '''Black on this color'''
|}

[[Category:Greenland political party colour templates|{{PAGENAME}}]]</noinclude>