首页 > 解决方案 > 将 python tweepy api.trends_place 列表值导出到 pygsheets 表

问题描述

我有两个功能代码片段:一个用于从 Twitter 中提取趋势,另一个用于连接到数据库(有关其他上下文,请参见下文)。我正在寻找的是从“趋势”中获取值并将其粘贴到工作表“趋势”中。我应该补充说trend_place返回一个 JSON 对象。

不用说,我刚刚开始使用 python,我的一般编码经验几乎不存在。

#This is the end of the Twitter trends code. Using tweepy amongst others libs, ATM it returns in console the trends via print
    # fetching the trends
    trends = api.trends_place(id=woeid)

    # printing the information
    print("The top trends for the location are :")

    for value in trends:
        for trend in value['trends']:
            print(trend['name'])

twTrends()

#This is the end of the code that links to my spreadsheet. Using pygsheets I have managed to reference down to the desired worksheet: "Trends".

sheet = client.open_by_key(id)

wks = sheet.worksheet('title','Trends')

标签: pythonpython-3.xlisttweepypygsheets

解决方案


推荐阅读