views...

43 views
Skip to first unread message

Steve Ross

unread,
Nov 10, 2011, 8:53:31 PM11/10/11
to CouchDB-Python
forgive my lack of knowledge of python but I am writing a method to get a view and it works in javascript but in python it throws the following error:

TypeError: "'str' object is not callable"

function run in nightly_expiring.py at line 22

self.get_expiring(db)

function get_expiring in nightly_expiring.py at line 40

for row in db.view(view, params):

function __iter__ in untitled at line 984

return iter(self.rows)

function rows in untitled at line 1003

self._fetch()

function _fetch in untitled at line 992

self._rows = [wrapper(row) for row in data['rows']]



method:


def get_expiring(self, db_id):
db = self.server[db_id]
now = datetime.date.today()
startkey = "%.0f" % time.mktime(now.timetuple())
delta = datetime.timedelta(days=30)
nowplus30 = now + delta
endkey = "%.0f" % time.mktime(nowplus30.timetuple())
print startkey => 1320901200
print endkey => 1323493200
view = "_design/" + db_id + "/_view/certificate-by-date-list"
params =  "descending=false&startkey=["+ startkey +"]&endkey=[" + endkey + "]"
# url: cert_by_date_url + '?descending=false&startkey=[]&endkey=[' + todayPlus30 + ']',
for row in db.view(view, params):
print row.id

--
Steve Ross
web application & interface developer
http://blog.stevensross.com
[mobile] (912) 344-8113
[ AIM / Yahoo! : zeriumsteven ] [googleTalk : nowhiding ]

Alexander Shorin

unread,
Nov 11, 2011, 12:04:57 AM11/11/11
to couchdb...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To post to this group, send email to couchdb...@googlegroups.com.
To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.

Hi Steve

You should pass view params as keyword arguments, not string one.
http://packages.python.org/CouchDB/client.html#couchdb.client.Database.view



view = "_design/" + db_id + "/_view/certificate-by-date-list"
# params =  "descending=false&startkey=["+ startkey +"]&endkey=[" + endkey + "]"
# url: cert_by_date_url + '?descending=false&startkey=[]&endkey=[' + todayPlus30 + ']',
params = {
'descending': False,
'startkey': [startkey],
'endkey': [endkey]
}
for row in db.view(view, **params):
print row.id

--
,,,^..^,,,

Steve Ross

unread,
Nov 11, 2011, 8:22:04 AM11/11/11
to couchdb...@googlegroups.com

Thanks I knew it was something simple.

Steve Ross

unread,
Nov 11, 2011, 8:52:43 AM11/11/11
to CouchDB-Python
Should the docs be updated to reflect that? it just says "options –
optional query string parameters"

On Nov 11, 8:22 am, Steve Ross <nowhid...@gmail.com> wrote:
> Thanks I knew it was something simple.
> On Nov 11, 2011 12:04 AM, "Alexander Shorin" <kxe...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Fri, Nov 11, 2011 at 5:53 AM, Steve Ross <nowhid...@gmail.com> wrote:
>
> >> forgive my lack of knowledge of python but I am writing a method to get a
> >> view and it works in javascript but in python it throws the following error:
>
> >> *TypeError:* "'str' object is not callable"
>
> >> function run in *nightly_expiring.py* at line 22
>
> >> self.get_expiring(db)
>
> >> function get_expiring in *nightly_expiring.py* at line 40
>
> >> for row in db.view(view, params):
>
> >> function __iter__ in *untitled* at line 984
>
> >> return iter(self.rows)
>
> >> function rows in *untitled* at line 1003
>
> >> self._fetch()
>
> >> function _fetch in *untitled* at line 992
> >http://packages.python.org/CouchDB/client.html#couchdb.client.Databas...

Alexander Shorin

unread,
Nov 11, 2011, 9:01:17 AM11/11/11
to couchdb...@googlegroups.com
On Fri, Nov 11, 2011 at 5:52 PM, Steve Ross <nowh...@gmail.com> wrote:
> Should the docs be updated to reflect that? it just says "options –
> optional query string parameters"

I'd be happy to do it, but my English is too weak for that task ):
However, current description notes that you could pass any query
parameters, even your own and doesn't binds couchdb-python
documentation to CouchDB supported features.

--
,,,^..^,,,

Steve Ross

unread,
Nov 11, 2011, 10:55:02 AM11/11/11
to couchdb...@googlegroups.com
since it is fairly typical to need to query by a date range it would be nice if the couch lib would convert a date (or datetime) to epoch (miliseconds) when sending in a param. 

Not sure if everyone would want that but it would help me out!

Alexander Shorin

unread,
Nov 11, 2011, 11:03:29 AM11/11/11
to couchdb...@googlegroups.com
On Fri, Nov 11, 2011 at 7:55 PM, Steve Ross <nowh...@gmail.com> wrote:
> since it is fairly typical to need to query by a date range it would be nice
> if the couch lib would convert a date (or datetime) to epoch (miliseconds)
> when sending in a param.
> Not sure if everyone would want that but it would help me out!
>

I'll not agree with you in this case, due to date ranges could be
implemented in different ways. For example, for the last time I'd
prefer @rnewson idea(at least he mentioned it in IRC) about storing
datetime in array form as [yyyy, mm, dd, HH, MM, SS] - it provides
great statistic features over time. So datetime representation is
heavy dependend from task that you solves.

--
,,,^..^,,,

Steve Ross

unread,
Nov 11, 2011, 11:08:38 AM11/11/11
to couchdb...@googlegroups.com
Hm... following #couchdb on IRC and the preferred method of storing dates (I thought) was:

2011-11-03T04:00:00.000Z

and then the way of being able to select a range in couchdb is to emit(Date.parse(doc.date)) since time is numeric it makes sorting / selecting a range pretty easy...

anyway that is just how i am doing it.

Alexander Shorin

unread,
Nov 11, 2011, 11:26:39 AM11/11/11
to couchdb...@googlegroups.com
On Fri, Nov 11, 2011 at 8:08 PM, Steve Ross <nowh...@gmail.com> wrote:
> Hm... following #couchdb on IRC and the preferred method of storing dates (I
> thought) was:
> 2011-11-03T04:00:00.000Z
> and then the way of being able to select a range in couchdb is to
> emit(Date.parse(doc.date)) since time is numeric it makes sorting /
> selecting a range pretty easy...
> anyway that is just how i am doing it.

Yes, storing datetime values as ISO string format in universal method,
but all depends from tasks that you're solving(:

Reply all
Reply to author
Forward
0 new messages