- Author:
- magik_cypress
- Posted:
- March 9, 2012
- Language:
- Python
- Version:
- Not specified
- Score:
- 0 (after 0 ratings)
Save attachment on couchdb document
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
- Browser-native date input field by kytta 1 month ago
- Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
- My firs Snippets by GutemaG 1 month, 2 weeks ago
- FileField having auto upload_to path by junaidmgithub 2 months, 3 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 3 months ago
Comments
Please login first before commenting.