[英]Python: Appending API Calls to Spreadsheet
I'll start out by saying I'm very new to Python and programming in general but am very hands on in my learning style. 首先,我要说我对Python和编程领域还很陌生,但是对我的学习风格却非常了解。
I would like to use Python to: 我想使用Python来:
I have an API key, the spreadsheet data, Python, and the klout Python scripts 我有一个API密钥,电子表格数据,Python和klout Python脚本
Thanks for your help! 谢谢你的帮助!
UPDATE 更新
Thanks to Lonely for his help with getting me this far. 感谢Lonely对我的帮助。 Now I just need to write my score results to a spreadsheet.
现在,我只需要将分数结果写入电子表格即可。
from xlrd import open_workbook
from klout import *
k=Klout('my_API_key')
book=open_workbook('path_to_file')
sheet0=book.sheet_by_index(0)
List1=sheet0.col_values(0)
for screen_name in List1:
kloutId = k.identity.klout(screenName=screen_name).get('id')
score = k.user.score(kloutId=kloutId).get('score')
print screen_name, score
UPDATE 2 更新2
Have successfully put Twitter Screennames back into a new spreadsheet. 已成功将Twitter屏幕名称放回新的电子表格中。 Can't seem to get scores to display correctly.
似乎无法正确显示分数。 It's also stopping at 30 (which happens to be the request per second limit for Klout).
它也停止在30(恰好是Klout的每秒请求数限制)。 Here's what I have right now.
这就是我现在所拥有的。
from xlrd import open_workbook
import xlwt
from klout import *
k=Klout('My_API_Key')
book=open_workbook('Path_to_My_File')
sheet0=book.sheet_by_index(0)
List1=sheet0.col_values(0)
for screen_name in List1:
kloutId = k.identity.klout(screenName=screen_name).get('id')
score = k.user.score(kloutId=kloutId).get('score')
wbk = xlwt.Workbook()
sheet = wbk.add_sheet('sheet 1')
i = -1
for n in List1:
i = i+1
sheet.write(i,0,n)
b = 0
score1 = int(score)
for x in xrange(score1):
b = b+1
sheet.write(b,1,x)
wbk.save("KScores.xls")
FINAL WORKING VERSION 最终版本
With a ton of help from a personal contact who I credit most of the writing of this script too I now have a completed .py script. 在个人联系人的大量帮助下,我也将此脚本的大部分工作都归功于我,现在我已经完成了.py脚本。
from xlrd import open_workbook
import xlwt
from time import sleep
from klout import *
klout_con = Klout('API_KEY_HERE', secure=True)
book = open_workbook('PATH_TO_YOUR_FILE_HERE')
sheet0 = book.sheet_by_index(0)
List1 = sheet0.col_values(0)
wbk = xlwt.Workbook()
sheet = wbk.add_sheet('sheet 1')
row = 0
for screen_name in List1:
klout_id = klout_con.identity.klout(screenName=screen_name).get('id')
score = klout_con.user.score(kloutId=klout_id).get('score')
sheet.write(row, 0, screen_name)
sheet.write(row, 1, score)
row += 1
print screen_name
sleep(1)
wbk.save('KScores.xls')
Thanks to the community and Adam who both helped me put this thing together. 感谢社区和亚当,他们都帮助我将这件事整合在一起。 Was an excellent starter project.
是一个出色的入门项目。
To read excel... use XLRD 阅读excel ...使用XLRD
Take all id's in list format. 以列表格式获取所有ID。
Read each one of them by using iteration like for i in list with Klout_APi
like ... 通过使用像
for i in list with Klout_APi
类for i in list with Klout_APi
迭代for i in list with Klout_APi
读取其中的每一个, for i in list with Klout_APi
像...
score = k.user.score(kloutId=kloutId).get('score')
However a sample data would have been great... 但是样本数据会很棒...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.