-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson2txt.py
44 lines (26 loc) · 957 Bytes
/
json2txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding: utf-8
# In[6]:
"""Extract TED Talks subtitles from json objects"""
# Author: Sameera Lanka
# Website: www.sameera-lanka.com
# Copyright © TED Conferences, LLC
import pandas as pd
import os
import json
if not os.path.exists('./TED_transcripts'):
os.makedirs('./TED_transcripts')
i = 0;
filename = './TED_json/transcript.json?language=en.' + str(i)
while os.path.isfile(filename):
with open(filename, 'r') as f:
try:
talk_html = json.load(f)
transcript = open("./TED_transcripts/transcript_" + str(i) + ".txt", "w")
for cues in talk_html['paragraphs']:
for text in cues['cues']:
transcript.write(text['text'] + " ")
transcript.close()
except:
pass
i = i+1
filename = './TED_json/transcript.json?language=en.' + str(i)