Advertisement
dude7

blogun soap api

Oct 4th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #
  4. # soaptest.py v0.3 04/10/2011
  5. # Blogun API script sample ( http://blog.blogun.ru/2011/09/api-2/ )
  6. # http://seo-coding.ru/2011/10/03/primer-ispolzovaniya-blogun-api-na-python/
  7. #
  8.  
  9.  
  10. import sys
  11.  
  12. import logging
  13. import traceback as tb
  14. import suds.metrics as metrics
  15. from suds import WebFault
  16. from suds.client import Client
  17.  
  18. BLOGUN_LOGIN = "YOULOGIN"
  19. BLOGUN_PASS = "YOUPASS"
  20.  
  21. BLOGLOG_FILE = "blogs_cy10.csv"
  22.  
  23. DEBUG = 0
  24.  
  25.  
  26. def start(url):
  27. print '_____________________________'
  28. print 'Getting blogs'
  29. f = open(BLOGLOG_FILE,"w");
  30. s = "url,YandexTic,YIndexed,GooglePR,GIndexed,idBlog\n"
  31. f.write(s)
  32. f.close()
  33.  
  34.  
  35. def logtofile(blogs):
  36. f = open(BLOGLOG_FILE,"a");
  37.  
  38. arrBlogs = blogs.blogInfoArray[0]
  39. for b in arrBlogs:
  40. s = b.url+","+str(b.YandexTic)+","+str(b.YIndexed)+","
  41. s+= str(b.GooglePR)+","+str(b.GIndexed)+","+str(b.idBlog)+"\n"
  42. f.write(s)
  43.  
  44. f.close();
  45.  
  46. return
  47.  
  48.  
  49. try:
  50. url = 'http://blogun.ru/api/blogun_api.wsdl'
  51. start(url)
  52. client = Client(url)
  53. print client
  54. token = client.service.blogunApi_login(BLOGUN_LOGIN, BLOGUN_PASS, 0)
  55. print 'Auth token="%s"' % token
  56. if (token is None):
  57. print "Auth failed. Check login/pass values."
  58. exit(1)
  59.  
  60. # Get info about balance
  61. #user = client.service.blogunApi_getBalance(token)
  62. #print 'user="%s"' % user
  63.  
  64. blogFilter = client.factory.create('blogFilter')
  65. blogFilter.CyFrom = 10
  66. blogFilter.CyTo = 9999
  67. blogFilter.PrFrom = 0
  68. blogFilter.PrTo = 10
  69. blogFilter.YandexIndexFrom = 1
  70. blogFilter.YandexIndexTo = 50000
  71. blogFilter.GoogleIndexFrom = 1
  72. blogFilter.GoogleIndexTo = 50000
  73.  
  74. print blogFilter
  75.  
  76. blogs = client.service.blogunApi_getBlogs(token, blogFilter, 0)
  77. #print 'blogs="%s"' % blogs
  78. totalcnt = blogs.totalCount
  79. print "Total records: " + str(totalcnt)
  80.  
  81. # 100 records per query
  82. maxcnt=totalcnt/100+1
  83.  
  84. for i in range(1,maxcnt):
  85. blogs = client.service.blogunApi_getBlogs(token, blogFilter, i)
  86. if (DEBUG):
  87. print 'blogs="%s"' % blogs
  88. logtofile(blogs)
  89. del blogs
  90. sys.stderr.write("Running query %d of %d\n" % (i, maxcnt))
  91.  
  92.  
  93. # Logout
  94. #logout = client.service.blogunApi_logout(token)
  95. #print 'logout="%s"' % logout
  96.  
  97. except WebFault, f:
  98. errors += 1
  99. print f
  100. print f.fault
  101. except Exception, e:
  102. print e
  103. tb.print_exc()
  104.  
  105.  
  106. print 'Finished.'
  107.  
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement