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 )
Exemplo n.º 2
0
 def push_feed( self, timestamp, status='new', feed_file=None ):
     global db
     Feed.set_db(db)
     feed= Feed(
         timestamp= timestamp,
         status= status,
     )
     db.save_doc( feed )
     if feed_file is not None:
         feed.put_attachment( feed_file, name="feed", content_type="text/csv" )
     return feed
Exemplo n.º 3
0
def upload_feed( filename ):
    """Upload a specific feed file.

    This depends on a previous invocation of :func:`config` to set
    the global database variable, :data:`settings.db`.

    :param filename: a file to read and push.
    """
    Feed.set_db(settings.db)
    feed= Feed(
        timestamp= datetime.datetime.fromtimestamp(os.path.getmtime(filename)),
        status= "new",
    )
    settings.db.save_doc( feed )
    with open(filename,'r') as source:
        feed.put_attachment( source, name="feed", content_type="text/csv" )
    return feed