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_latest_episode_ids(user
, count
=10):
8 """ Returns the latest episodes that the user has accessed """
11 raise QueryParameterMissing('user')
13 startkey
= [user
.profile
.uuid
.hex, {}]
14 endkey
= [user
.profile
.uuid
.hex, None]
16 udb
= get_userdata_database()
17 res
= udb
.view('listeners/by_user',
24 stale
= 'update_after',
27 return [r
['value'] for r
in res
]
31 @cache_result(timeout
=60)
32 def get_seconds_played(user
, since
=None, until
={}):
33 """ Returns the number of seconds that the user has listened
35 Can be selected by timespan, podcast and episode """
38 raise QueryParameterMissing('user')
40 since_str
= since
.strftime('%Y-%m-%dT%H:%M:%S') if since
else None
41 until_str
= until
.strftime('%Y-%m-%dT%H:%M:%S') if until
else {}
43 startkey
= [user
.profile
.uuid
.hex, since_str
]
44 endkey
= [user
.profile
.uuid
.hex, until_str
]
46 udb
= get_userdata_database()
47 val
= get_single_result(udb
, 'listeners/times_played_by_user',
51 stale
= 'update_after',
54 return val
['value'] if val
else 0