couch_update.py
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
# couch_update.py
#
# Jul/27/2020
#
# ----------------------------------------------------------------
import sys
import json
import datetime
import requests
#
# ----------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
key_in = sys.argv[1]
population_in = int(sys.argv[2])
print("%s\t%d" % (key_in, population_in))
#
url_json = 'http://localhost:5984/nagano'
url_key = url_json + '/' + key_in
#
rr=requests.get(url_key)
#
unit_aa = json.loads(rr.text)
print(unit_aa['name'])
unit_aa['population'] = population_in
unit_aa['date_mod'] = '%s' % datetime.date.today()
#
out_str = json.dumps(unit_aa)
#
try:
rr=requests.put(url_key,out_str)
except Exception as ee:
sys.stderr.write(str(ee) + '\n')
#
sys.stderr.write("*** 終了 ***\n")
#
# ----------------------------------------------------------------
実行
./couch_update.py t2028 81954200