1 from mygpo
.cache
import cache_result
2 from mygpo
.db
.couchdb
import get_userdata_database
, get_single_result
3 from mygpo
.db
import QueryParameterMissing
6 @cache_result(timeout
=60)
7 def get_seconds_played(user
, since
=None, until
={}):
8 """ Returns the number of seconds that the user has listened
10 Can be selected by timespan, podcast and episode """
13 raise QueryParameterMissing('user')
15 since_str
= since
.strftime('%Y-%m-%dT%H:%M:%S') if since
else None
16 until_str
= until
.strftime('%Y-%m-%dT%H:%M:%S') if until
else {}
18 startkey
= [user
.profile
.uuid
.hex, since_str
]
19 endkey
= [user
.profile
.uuid
.hex, until_str
]
21 udb
= get_userdata_database()
22 val
= get_single_result(udb
, 'listeners/times_played_by_user',
26 stale
= 'update_after',
29 return val
['value'] if val
else 0