~kkissling/python-snippets/testzweig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
#
# [SNIPPET_NAME: Delete Records]
# [SNIPPET_CATEGORIES: DesktopCouch]
# [SNIPPET_DESCRIPTION: Delete records from the desktop couch database]
# [SNIPPET_AUTHOR: Andy Breiner <breinera@gmail.com>]
# [SNIPPET_DOCS: http://www.freedesktop.org/wiki/Specifications/desktopcouch/Documentation/SimpleGuide]
# [SNIPPET_LICENSE: GPL]

from desktopcouch.records.server import CouchDatabase
from desktopcouch.records.record import Record

#Similar to the fetchrecord.py by Huntly Cameron
#See fetchrecord.py for additional information

db = CouchDatabase("deleterecordsexample", create=True)
record_type = "http://example.com/delete-record-type.html"
record = Record({"first" : "Andy", 
                 "last"  : "Breiner"}, record_type)
db.put_record(record)

record = Record({"first" : "Jono", 
                 "last"  : "Bacon"}, record_type)
db.put_record(record)

results = db.get_records(record_type = record_type, create_view = True)

for records in results:
    record = records.value
    print "First: %s" % record["first"]
    print "Last : %s" % record["last"]
    if record["first"] == "Andy":
      db.delete_record(record["_id"])