ویکیپدیا:درخواستهای ربات/ربات مختصات جغرافیا/ویرایش ۱
ظاهر
!/usr/bin/python
# -*- coding: utf-8 -*-
#
#
import pagegenerators
import wikipedia
txtTmp = text
if not re.search(u'{{([Cc]oor|مختصات).*?}}', text):
try: # en wiki
sEnname = re.search(u'\[\[en\:(.*?)\]\]', text, re.S)
enpage=wikipedia.Page(wikipedia.getSite('en'), sEnname.group(1))
try:
entext=enpage.get()
except wikipedia.NoPage:
print u'ERROR: No EN page'
except wikipedia.IsRedirectPage:
enpage=enpage.getRedirectTarget()
entext=enpage.get()
try:
coordS = re.search(u'({{[Cc]oor.*?}})', entext, re.S)
coord = coordS.group(1)
print u'EN Coord: %s' % coord
noCoord=False
except AttributeError:
print u'ERROR: No EN {{Coord}}'
except AttributeError: # de wiki
sDename = re.search(u'\[\[de\:(.*?)\]\]', text, re.S)
depage=wikipedia.Page(wikipedia.getSite('de'), sDename.group(1))
try:
detext=depage.get()
except wikipedia.NoPage:
print u'ERROR: No DE page'
except wikipedia.IsRedirectPage:
depage=depage.getRedirectTarget()
detext=depage.get()
try:
coordS = re.search(u'({{[Cc]oor.*?}})', detext, re.S)
coord = coordS.group(1)
print u'DE Coord: %s' % coord
noCoord=False
except AttributeError:
print u'ERROR: No DE {{Coord}}'
if noCoord is False:
txtTmp=coord+ur'\n'+text
if txtTmp!=text:
text=txtTmp
pCoord=True
else:
print u'INFO: {{Coord}} exists'