Материал из Википедии — свободной энциклопедии
# -*- coding: UTF-8 -*-
__version__='$Id:'
import wikipedia
import re, sys
import codecs
from zbib_tekst import *
def vivod(b):
wikipedia.output(b)
# otch.write(b)
# otch.flush()
def zapis(d):
if len(d)==0:
return
b=u''
for i in range(len(d)):
b+=d[i]
if i<len(d)-1:
b+=u';'
frez.write(b+u'\n')
frez.flush()
def main():
n=1
dpr=[]
for s in f.readlines():
if ord(s[0]) == 65279:
s=s[1:]
s=s.replace(u'\r',u'')
if s[len(s)-1]==u'\n':
s=s[:len(s)-1]
if n<3 or len(s)<4:
n+=1
continue
d=[]
td=[
0,5,
5,6, # C
7,8, # D
9,10, # X
10,12, # S
13,14, # P
15,18, # CON
20,22, # Rect
23,25, # Rect
26,30, # Rect
31,34, # Decl
35,37, # Decl
38,40, # Decl
43,47, # Bmag
50,54, # Vmag
56,60, # SB
61,67, # a
68,73, # b
74,77, # PA
78,87, # Type
87,94, # PGC
96,111, # ID1
112,127, # ID2
128,143, # ID3
144,200] # Remarks
i=0
while i+i<len(td):
t=s[td[i+i]:td[i+i+1]]
if i==16 and t[len(t)-1]==u'0':
t=t[:len(t)-1]
d.append(ubr_nk_prob(t))
if i+i+2<len(td) and ubr_nk_prob(s[td[i+i+1]:td[i+i+2]])!=u'':
vivod(u'!!! %d %d'%(n,i))
i+=1
if d[3]!=u'' and d[3]!=u'1':
dpr[21]+=u', '+d[21]
dpr[22]+=u', '+d[22]
dpr[23]+=u', '+d[23]
dpr[24]+=u', '+d[24]
else:
zapis(dpr)
dpr=d
n+=1
zapis(dpr)
#fi = wikipedia.argHandler(sys.argv[1], 'cht_cat')
#filename = fi+'.txt'
#fotch = fi+'_ot.txt'
#fotch2 = fi+'_op.txt'
#firez = fi+'_sk.txt'
filename = wikipedia.argHandler(sys.argv[1], 'cht_cat')
firez = wikipedia.argHandler(sys.argv[2], 'cht_cat')
#fotch2 = wikipedia.argHandler(sys.argv[3], 'cht_cat')
fliwi=1
if len(sys.argv)>=3 and sys.argv[2]==u'w':
fliwi=0
f=codecs.open(filename,'rb',encoding='utf-8')
#otch = codecs.open(fotch, 'w', 'utf-8')
#otch2 = codecs.open(fotch2, 'w', 'utf-8')
frez = codecs.open(firez, 'w', 'utf-8')
#mysite = wikipedia.getSite()
try:
main()
except:
wikipedia.stopme()
raise
else:
wikipedia.stopme()