پرش به محتوا

ویکی‌پدیا:درخواست‌های ربات/ربات مختصات جغرافیا/ویرایش 2

از ویکی‌پدیا، دانشنامهٔ آزاد

<syntaxhighlight lang="python">

  1. !/usr/bin/python
  2. coding: utf-8 --

import wikipedia,re,codecs,category,catlib,codecs wikipedia.config.put_throttle = 0 wikipedia.put_throttle.setDelay() cat = catlib.Category(wikipedia.getSite('fa'), u"آثار ملی ایران") listOfArticles = cat.articlesList() api_key='ABQIAAAAj2LZM6YmUOC843HIhQkaHRQhLHx8djKJ6K7ZJ1oK_CgKu24-eRRfC4rnqqDkMvsw4H-BpD3OqYr4fw' from googlemaps import GoogleMaps gmaps = GoogleMaps(api_key) types='مترو',

for rpage in listOfArticles:

   coord=False
   rpage=str(rpage).replace( '','' ).replace( '', ).strip()
   site = wikipedia.getSite('fa') 
  # aa=1
  # if aa==1:
   try:
       rpage=unicode(rpage,'UTF-8')
       pagefa = wikipedia.Page( site,rpage )
       textfa=pagefa.get()
       if textfa.find('{{coord')!=-1 or textfa.find('{{Coord')!=-1:
           continue
       try:
           citys=textfa.split(u'| شهرستان          =')[1].split('|')[0].replace(u'',u'').replace(u'',u).strip()
           citys=', '+citys+u', ايران '
       except:
           citys=u', ايران '
       citys=citys.replace(u'شهرستان ',u)
       adress=rpage.replace(u'(',u).replace(u')',u)+citys
       print adress
       lat,lan = gmaps.address_to_latlng(adress)
       if str(rpage).find(u'ایستگاه')!=-1:
           types='|type:railwaystation'
       elif str(rpage).find(u'دانشگاه')!=-1:
           types='|type:edu'
       elif str(rpage).find(u'دانشکده')!=-1:
           types='|type:edu'
       elif str(rpage).find(u'مدرسه')!=-1:
           types='|type:edu'
       elif str(rpage).find(u'دبیرستان')!=-1:
           types='|type:edu'
       elif str(rpage).find(u'دبستان')!=-1:
           types=u'|type:edu'
       else:
           types=u'|type:landmark'

       coord=u
   except Exception,e:
       print e
       coord=False
       continue

   if coord!=False:
       try:
               textfa=coord+'\n'+textfa.replace(u'',).strip()+u'\n'
               pager=pagefa.put(textfa,u'ربات:افزودن مختصات برگرفته از گوگل مپ')      
               print str(rpage)+'done' 
       except wikipedia.IsRedirectPage:
           continue
       except Exception,e:
           print e
           continue