0
0

More than 3 years have passed since last update.

Python3: CouchDB のデータを更新 (Update)

Posted at
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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0