跳转到内容

User:Japanbot

维基百科,自由的百科全书

# -*- coding: utf-8  -*-
""" Script to create user files (user-config.py, user-fixes.py) """
__version__ = '$Id: generate_user_files.py 6869 2009-05-11 00:35:02Z cosoleto $'

import os, sys, codecs, re

base_dir = ''
console_encoding = sys.stdout.encoding

if console_encoding is None or sys.platform == 'cygwin':
    console_encoding = "iso-8859-1"

def listchoice(clist = [], message = None, default = None):

    if not message:
        message = "Select"

    if default:
        message += " (default: %s)" % default

    message += ": "

    for n, i in enumerate(clist):
        print ("%d: %s" % (n + 1, i))

    while True:
        choice = raw_input(message)

        if choice == '' and default:
            return default

        try:
            return clist[int(choice) - 1]
        except:
            print("Invalid response")
    return response

def file_exists(filename):
    if os.path.exists(filename):
        print("'%s' already exists." % filename)
        return True
    return False

def generate_township():
    _fnc = os.path.join(base_dir, "township")
    if not file_exists(_fnc):
        
        fdata = codecs.open("data", "r", "utf-8")
	row=[]
	for str in fdata.readlines():

	    column=[]
	    line=str.split()
	    for field in line: column.append(field)
	    row.append(column)

	for data in row:
            name=data[0]
            if name.find(u"乡")<>-1: level=u"乡"
            if name.find(u"镇")<>-1: level=u"镇"
            if name.find(u"街道")<>-1: level=u"街道"
            if data[1]<>"0": disam=' '+data[1]
            else: disam=''
            code=data[2]
            post=''
            num_villiage=data[3]
            villiage=data[4]
            county=data[5]

            f = codecs.open(_fnc, "a", "utf-8")
        
            f.write(u"""{{-start-}}
'''%s%s'''
{{Infobox Prefecture Japan
| Name         = %s
| Symbol       =
| SymbolName   = %s徽
| SymbolDescription =
| Japanese     = 県
| Hiragana     = 
| Romanization = 
| Number       = 
| Governor     = 
| Capital      =
| Region       = 
| Island       = 
| TotalArea    = 
| AreaRank     = 
| PCWater      = 
| PopDate      = 
| Population   = 
| PopRank      =
| Density      = 
| Districts    = 
| Municipalities = 
| ISOCode      = 
| Flower       = 
| Tree         = 
| Bird         = 
| Map          =
| Post         = 
| Address      = 
| Phone        = 
| Website      = 
|}}

'''%s'''是[[日本]]的一個縣。

== 行政区划 ==

%s共辖%s,分别是:

%s。

{{japan}}
{{日本小作品}}


[[Category:%s|*]]
{{-stop-}}
""" % (name, disam, name, county, level, code, post, name, county, level, name, num_villiage, villiage, county, county))
            f.close()
        
        fdata.close()
        print("'%s' written." % _fnc)

if __name__ == "__main__":
        generate_township()