我是一个 Python 新手,我正在编写一段代码来收集来自两个邻居的推文,将它们保存为 JSON 格式并绘制一些数据。您对如何提取推文日期和时间或如何计算邻居的推文数量有任何建议吗?换句话说,将带有 JSON 数据的 .txt 的不同变量隔离到可绘制的东西中的最佳方法是什么?
非常感谢!
from twitter import *
import sys
import os.path
import simplejson as json
import tweepy
import csv
#log into Twitter
OAUTH_TOKEN = 'XXX'
OAUTH_SECRET = 'XXX'
CONSUMER_KEY = 'XXX'
CONSUMER_SECRET = 'XXX'
t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
#I consider A to be a 2km radius circle
result_A = t.search.tweets(query="kaffe",geocode="55.662610,12.604074,1.24mi",result_type='recent')
with open('data_A.txt', 'w') as outfile:
json.dump(result_A, outfile)
#Similarly, B is a 2km radius circle
result_B = t.search.tweets(query="kaffe",geocode="55.694700,12.548283,1.24mi",result_type='recent')
with open('data_B.txt', 'w') as outfile:
json.dump(result_B, outfile)