Yes. In the json format that seemed to be the easiest to handle by myself because I got lost in various ways to do the title act.
test.json
[
{
"name":"mouse",
"date":"2013-10-22",
"last":24,
"avg":20.5,
"cnt":10
}
]
test.py
from urllib import urlencode
from datetime import date, timedelta
import datetime
import kino
import re
import json
time = datetime.datetime.now()
def demchi_cnt(filename):
f = open(filename)
data = json.load(f)
f.close()
d = datetime.datetime.strptime(data[0]["date"], "%Y-%m-%d")
s = time - d
message = "@xxx After replacing the mouse battery%d days have passed. Last life%Average in d days%It's s day.#demchi" % (s.days,data[0]["last"],"{0:0.1f}".format(data[0]["avg"]))
# kino.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': message}))
if __name__ == '__main__':
demchi_cnt(test.json)
At least the first time I need to prepare the data manually, so I checked here after inputting. http://jsonlint.com/
data[0]["last"]=20 After combing json.dump(a, open('test.json','w')) It seems that it will be reflected in the json file. Just like the elements are replaced in lexicographic order, trying a little more
Recommended Posts