Query Soundcloud API using created_at filter

允我心安 提交于 2019-12-11 07:38:30

问题


Is it possible to use the created_at filter as part of a query in Python? I added it into my query filters, trying several different ways, but it seems to ignore that particular filter. The results that come back contain everything from last week to 3 years ago, and I'm only looking for recent tracks. I have to believe this is doable somehow...

stamp = "2013/07/01 09:24:50 +0000"

tracks = client.get('/tracks', q='Metallica', genre='', duration={
'from': 1800000
}, created_at={
'from': stamp
}, limit='5', tags='Metal')

I've also tried just entering the datetime stamp directly instead of as a variable, with the same results. Am I just botching the code somewhere here? Or can you really not specify the created_at date for your query results?


回答1:


Yes! It is possible to use the created_at filter as part of a query in Python.

I do not know how the SoundCloud API prioritizes each of the filters, so it is possible that adding more filters may lead to unexpected results.

Limiting the filters simply to the filters {query, created_at} yield your desired result.

# https://github.com/soundcloud/soundcloud-python
import soundcloud 

# Authentication
CLIENT_ID = 'insert_client_id_here'
client = soundcloud.Client(client_id=CLIENT_ID) 

# Call GET request with parameters
# excludes: {genres,tags,duration}
# includes: {order,limit} for organization
stamp = "2013/07/01 09:24:50 +0000"
tracks = client.get('/tracks',
                q='Metallica',
                created_at= {'from': stamp},
                order='created_at', 
                limit=5, 
                )

# Print the results
for i, v in enumerate(tracks):
    print i, v.title, v.created_at


来源:https://stackoverflow.com/questions/17499287/query-soundcloud-api-using-created-at-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!