0
0

More than 3 years have passed since last update.

Python3: CouchDB のデータを削除 (Delete)

Last updated at Posted at 2020-07-27
couch_delete.py
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
#   couch_delete.py
#
#                   Jul/27/2020
# ----------------------------------------------------------------
import sys
import json
import requests
#
# ----------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
key_in = sys.argv[1]
print("%s" % key_in)
#
url_json = 'http://localhost:5984/nagano'
url_key = url_json + '/' + key_in
#
rr=requests.get(url_key)
#
unit_aa = json.loads(rr.text)
#
if ('_rev' in unit_aa):
    print(unit_aa['_rev'])
    url_del = url_key + '?rev=' + unit_aa['_rev']
    rr=requests.delete(url_del)
else:
    sys.stderr.write("*** not exist ***\n")
    print(unit_aa)
#
sys.stderr.write("*** 終了 ***\n")
# ----------------------------------------------------------------

実行

./couch_delete.py t2024
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