Guest User

Untitled

a guest
Jan 18th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import MySQLdb as dbapi
  2. import sys
  3. import csv
  4. import json
  5. import requests
  6. import urllib2
  7.  
  8. # dbServer='localhost'
  9. # dbPass='supersecretpassword'
  10. # dbSchema='dbTest'
  11. # dbUser='root'
  12. api_endpoint = 'http://puja_api.sportskeeda.com/v1/author/'
  13. dbServer='localhost'
  14. dbPass=''
  15. dbSchema='sportskeeda'
  16. dbUser='sportskeeda'
  17. database_location="/var/lib/mysql/sportskeeda"
  18. conn = dbapi.connect(host=dbServer,user=dbUser,passwd=dbPass,db="sportskeeda")
  19. c = conn.cursor()
  20. # print "done"
  21.  
  22. dbQuery = "SELECT distinct author_id FROM keeda_author_fact ORDER BY author_post_count DESC LIMIT 2;"
  23. c.execute(dbQuery)
  24. results = c.fetchall()
  25.  
  26. authors = []
  27. authors_final = []
  28. api_array = []
  29. for result in results:
  30.  
  31. authors.append(result)
  32. for author in authors:
  33. author1 = str(author)
  34. auth = author1.split(',')
  35. auth2 = auth[0].split('(')[1]
  36. # print auth2
  37. authors_final.append(auth2)
  38. print authors_final
  39. for ids in authors_final:
  40. url_to_hit = api_endpoint + ids
  41. print url_to_hit
  42. # response = urllib2.urlopen('api.sportskeeda.com/v1/author/4390L')
  43. # data = json.load(response)
  44. response = requests.get(url_to_hit)
  45. json_data = (response.text)
  46. print json_data
  47. user_email = json_data[0]["user_email"]
  48. author_url = json_data["author_url"]
  49. posts_published = json_data["posts_published"]
  50. editors_pick = json_data["editors_pick"]
  51. reads_received = json_data["reads_received"]
  52. print user_email, author_url, posts_published, editors_pick, reads_received
  53. # print url_to_hit
  54. # api_array.append(url_to_hit)
  55. # response = requests.get(url_to_hit)
  56. # print "foo"
  57. # json_data = (response.text)
  58. # print json_data
  59.  
  60. # outfile = open( "/home/puja/Documents/fb-api-test", "w" )
  61.  
  62. # writer = csv.writer( outfile )
  63.  
  64. # write header
  65.  
  66.  
  67.  
  68. # with open('/home/puja/Documents/fb-api-test/test.csv', 'w') as outfile:
  69. # # fields = ['Author Id', 'post count','total reads', 'points(includes editors picks)', 'author name', 'author email']
  70. # # writer = csv.DictWriter(outfile)
  71. # writer = csv.writer(outfile)
  72. # writer.writerow(['Author Id', 'post count','total reads', 'points(includes editors picks)', 'author name', 'author email'])
  73. # # writer.writeheader()
  74. # for x in result:
  75. # writer.writerow(x)
  76. # print "done"
Add Comment
Please, Sign In to add comment