save file on couchdb with couchdbkit

 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
35
36
37
38
#!/usr/bin/env python

import os, sys, datetime, getpass
from couchdbkit import *

path = '/tmp/motion'

# model
class MotionCouchdb(Document):
        author = StringProperty()
        content = StringProperty()
        date = DateTimeProperty()

# server object
server = Server('http://127.0.0.1:5984/')

# create database
db = server.get_or_create_db("motion_couchdb")

# associate MotionCouchdb to the db
MotionCouchdb.set_db(db)

# create a new motion
motion = MotionCouchdb(
    author=getpass.getuser(),
    content="suck video",
    date=datetime.datetime.utcnow()
)

# save it.
motion.save()

# save files
files = os.listdir(path)
file = [f for f in files if f.endswith('.jpg')]
for f in file:
    read_image = open('%s/%s' % (path, f), 'r')
    motion.put_attachment(read_image, f)

More like this

  1. Get email and push on couchdb - utils by magik_cypress 2 years, 1 month ago
  2. Example usage of SimpleCouchPaginator by toke 5 years, 5 months ago
  3. Convert a Couchdb document into a Python object by davej 5 years, 4 months ago
  4. Basic CouchDB Paginator (Updated) by toke 5 years, 5 months ago
  5. Get email and push on couchdb - Model by magik_cypress 2 years, 1 month ago

Comments

(Forgotten your password?)