Exemplo n.º 1
0
def upload_rtf( db, filename ):
    """Upload the Real-Time Feed from a given filename.

    The following sequence of curl requests have the same effect.

    ::

        curl -X POST http://localhost:5984/couchdbkit_test/ -H "Content-Type: application/json" -d '{"timestamp":"2012-03-02T16:16:00Z", "status":"new", "doc_type":"Feed"}'

    The response is::

        {"ok":true,"id":"09833a88a1cbb06f64c555d0245f1af3","rev":"1-7750ef2dbce77303f957de17c754852a"}

    ::

        curl -X PUT http://localhost:5984/couchdbkit_test/09833a88a1cbb06f64c555d0245f1af3/feed/?rev=1-7750ef2dbce77303f957de17c754852a -H "Content-Type: text/csv" --data-ascii @201203022302.rpt

    The response is::

        {"ok":true,"id":"09833a88a1cbb06f64c555d0245f1af3","rev":"2-748151ff136b0001671fb0fa14eb886d"}
    """
    Feed.set_db(db)
    feed = Feed(
        timestamp= datetime.datetime.fromtimestamp(os.path.getmtime(filename)),
        status = "new",
    )
    feed.save()
    with open(filename,'r') as source:
        feed.put_attachment( source, name="feed", content_type="text/csv" )
    print( feed, feed._id )