@@ -0,0 +1,1155 @@
+#!/usr/bin/python%0A# -*- coding: utf8 -*-%0A%0Aimport os%0Aimport json%0Aimport sys%0Afrom collections import OrderedDict%0Aimport json%0A%0A%0A%0Adef GetTitleAndURL(id):%0A  for attempt in range(10):%0A    try:%0A      command = %22curl -s http://www.ted.com/talks/view/id/%25s%22 %25 id%0A      output = os.popen(command).readlines()%5B0%5D%0A      url = output.split('%22')%5B1%5D%0A      title = url.split('/')%5B-1%5D%0A      title = title.title().replace('_', ' ')%0A      return %7B%22title%22 : title, 'url' : url%7D%0A    except:%0A      print id, %22exe------------%22%0A      continue%0A%0A%0AfromIdx = int(sys.argv%5B1%5D)%0AtoIdx = int(sys.argv%5B2%5D)%0A%0A%0Afor i in xrange(fromIdx,toIdx):%0A  print i%0A  obj = %7B%7D%0A  try:%0A    obj = GetTitleAndURL(str(i))%0A  except Exception, e:%0A    continue%0A  else:%0A    if len(obj%5B%22url%22%5D) %3C 4:%0A      continue%0A    if obj%5B%22url%22%5D%5B0:4%5D != %22http%22:%0A      continue%0A%0A    obj%5B%22id%22%5D = i%0A    sort_order = %5B'id', 'title', 'url'%5D%0A    obj_ordered = OrderedDict(sorted(obj.iteritems(), key=lambda (k, v): sort_order.index(k)))%0A    content = json.dumps(obj_ordered, ensure_ascii=False)%0A    content += ',%5Cn'%0A%0A    fileWrite = open('infos.json','a')%0A    fileWrite.write(content) %0A    fileWrite.close()%0A    print obj_ordered%0A%0A%0A%0A%0A

create parseTedInfo