From 79fa8402a5258325b266e9c54ef625423c820c8e Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Wed, 6 Mar 2013 17:57:06 +0530 Subject: [PATCH] add example function to get transcripts for a list --- utils.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 1326cfd..b93f0fd 100644 --- a/utils.py +++ b/utils.py @@ -2,6 +2,7 @@ from settings import username, password, url import ox import json import codecs +import urllib2 api = ox.api.API(url) user = api.signin({'username': username, 'password': password}) @@ -197,8 +198,35 @@ def dumpKnownPlaces(): #def replaceAnnotation(track, old, new): - - +def getTranscriptsForList(listId='sanj:spaces of theatre'): + result = api.find({ + 'sort': [{ + 'key': 'title', + 'operator': '+' + }], + 'query': { + 'conditions': [ + { + 'key': 'list', + 'value': listId, + 'operator': '' + } + ], + 'operator': '&' + }, + 'keys': ['id', 'title'] + }) + items = [{'id': item['id'], 'title': item['title']} for item in result['data']['items']] + outfolder = "out" + for i in items: + print i['title'] + savePath = "%s/%s_%s.txt" % (outfolder, i['id'], i['title']) + transcript_url = 'http://pad.ma/%s/transcripts.srt' % i['id'] + txt = urllib2.urlopen(transcript_url).read() + outfile = open(savePath, "w") + outfile.write(txt) + outfile.close() + def getIds(result): return [item.id for item in result['data']['items']]