Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- # soaptest.py v0.3 04/10/2011
- # Blogun API script sample ( http://blog.blogun.ru/2011/09/api-2/ )
- # http://seo-coding.ru/2011/10/03/primer-ispolzovaniya-blogun-api-na-python/
- #
- import sys
- import logging
- import traceback as tb
- import suds.metrics as metrics
- from suds import WebFault
- from suds.client import Client
- BLOGUN_LOGIN = "YOULOGIN"
- BLOGUN_PASS = "YOUPASS"
- BLOGLOG_FILE = "blogs_cy10.csv"
- DEBUG = 0
- def start(url):
- print '_____________________________'
- print 'Getting blogs'
- f = open(BLOGLOG_FILE,"w");
- s = "url,YandexTic,YIndexed,GooglePR,GIndexed,idBlog\n"
- f.write(s)
- f.close()
- def logtofile(blogs):
- f = open(BLOGLOG_FILE,"a");
- arrBlogs = blogs.blogInfoArray[0]
- for b in arrBlogs:
- s = b.url+","+str(b.YandexTic)+","+str(b.YIndexed)+","
- s+= str(b.GooglePR)+","+str(b.GIndexed)+","+str(b.idBlog)+"\n"
- f.write(s)
- f.close();
- return
- try:
- url = 'http://blogun.ru/api/blogun_api.wsdl'
- start(url)
- client = Client(url)
- print client
- token = client.service.blogunApi_login(BLOGUN_LOGIN, BLOGUN_PASS, 0)
- print 'Auth token="%s"' % token
- if (token is None):
- print "Auth failed. Check login/pass values."
- exit(1)
- # Get info about balance
- #user = client.service.blogunApi_getBalance(token)
- #print 'user="%s"' % user
- blogFilter = client.factory.create('blogFilter')
- blogFilter.CyFrom = 10
- blogFilter.CyTo = 9999
- blogFilter.PrFrom = 0
- blogFilter.PrTo = 10
- blogFilter.YandexIndexFrom = 1
- blogFilter.YandexIndexTo = 50000
- blogFilter.GoogleIndexFrom = 1
- blogFilter.GoogleIndexTo = 50000
- print blogFilter
- blogs = client.service.blogunApi_getBlogs(token, blogFilter, 0)
- #print 'blogs="%s"' % blogs
- totalcnt = blogs.totalCount
- print "Total records: " + str(totalcnt)
- # 100 records per query
- maxcnt=totalcnt/100+1
- for i in range(1,maxcnt):
- blogs = client.service.blogunApi_getBlogs(token, blogFilter, i)
- if (DEBUG):
- print 'blogs="%s"' % blogs
- logtofile(blogs)
- del blogs
- sys.stderr.write("Running query %d of %d\n" % (i, maxcnt))
- # Logout
- #logout = client.service.blogunApi_logout(token)
- #print 'logout="%s"' % logout
- except WebFault, f:
- errors += 1
- print f
- print f.fault
- except Exception, e:
- print e
- tb.print_exc()
- print 'Finished.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement