Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb as dbapi
- import sys
- import csv
- import json
- import requests
- import urllib2
- # dbServer='localhost'
- # dbPass='supersecretpassword'
- # dbSchema='dbTest'
- # dbUser='root'
- api_endpoint = 'http://puja_api.sportskeeda.com/v1/author/'
- dbServer='localhost'
- dbPass=''
- dbSchema='sportskeeda'
- dbUser='sportskeeda'
- database_location="/var/lib/mysql/sportskeeda"
- conn = dbapi.connect(host=dbServer,user=dbUser,passwd=dbPass,db="sportskeeda")
- c = conn.cursor()
- # print "done"
- dbQuery = "SELECT distinct author_id FROM keeda_author_fact ORDER BY author_post_count DESC LIMIT 2;"
- c.execute(dbQuery)
- results = c.fetchall()
- authors = []
- authors_final = []
- api_array = []
- for result in results:
- authors.append(result)
- for author in authors:
- author1 = str(author)
- auth = author1.split(',')
- auth2 = auth[0].split('(')[1]
- # print auth2
- authors_final.append(auth2)
- print authors_final
- for ids in authors_final:
- url_to_hit = api_endpoint + ids
- print url_to_hit
- # response = urllib2.urlopen('api.sportskeeda.com/v1/author/4390L')
- # data = json.load(response)
- response = requests.get(url_to_hit)
- json_data = (response.text)
- print json_data
- user_email = json_data[0]["user_email"]
- author_url = json_data["author_url"]
- posts_published = json_data["posts_published"]
- editors_pick = json_data["editors_pick"]
- reads_received = json_data["reads_received"]
- print user_email, author_url, posts_published, editors_pick, reads_received
- # print url_to_hit
- # api_array.append(url_to_hit)
- # response = requests.get(url_to_hit)
- # print "foo"
- # json_data = (response.text)
- # print json_data
- # outfile = open( "/home/puja/Documents/fb-api-test", "w" )
- # writer = csv.writer( outfile )
- # write header
- # with open('/home/puja/Documents/fb-api-test/test.csv', 'w') as outfile:
- # # fields = ['Author Id', 'post count','total reads', 'points(includes editors picks)', 'author name', 'author email']
- # # writer = csv.DictWriter(outfile)
- # writer = csv.writer(outfile)
- # writer.writerow(['Author Id', 'post count','total reads', 'points(includes editors picks)', 'author name', 'author email'])
- # # writer.writeheader()
- # for x in result:
- # writer.writerow(x)
- # print "done"
Add Comment
Please, Sign In to add comment