File size: 11,050 Bytes
f3a2528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8a13cfae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5837401d683f4cda99521aaad9baa6f6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "sermons:   0%|          | 0/46 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Volumes/MM/autoThread_old/churches/._all-souls_org.json 'utf-8' codec can't decode byte 0xb0 in position 37: invalid start byte\n",
      "45 files\n"
     ]
    }
   ],
   "source": [
    "from tqdm.notebook import tqdm\n",
    "from pathlib import Path\n",
    "import json\n",
    "import pandas as pd\n",
    "\n",
    "\n",
    "source = Path('/Volumes/MM/autoThread_old/churches/')\n",
    "data = []\n",
    "folder = Path(source).glob('*.json')\n",
    "for _file in tqdm(folder, total=len(list(Path(source).glob('*.json'))), desc='sermons'):\n",
    "    try:\n",
    "        with open(_file, 'r') as f:\n",
    "            docs = json.load(f) # {MP3file : {\"text\" ... }}\n",
    "    except Exception as e:\n",
    "        print(_file, e)\n",
    "        continue\n",
    "    church = _file.stem\n",
    "    updocs = {}\n",
    "    for k,v in docs.items():\n",
    "        v['church'] = church\n",
    "        updocs[k] = v\n",
    "    data.append( updocs )\n",
    "print(len(data), 'files')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "705968c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>church</th>\n",
       "      <th>source</th>\n",
       "      <th>text</th>\n",
       "      <th>sentences</th>\n",
       "      <th>processing_time</th>\n",
       "      <th>transcription_errors</th>\n",
       "      <th>duration(s)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1.1</th>\n",
       "      <td>all-souls_org</td>\n",
       "      <td>04.02.22ILeftMyHeartInSF.mp3</td>\n",
       "      <td>Our reading this morning. Is from the same scr...</td>\n",
       "      <td>177</td>\n",
       "      <td>327.6</td>\n",
       "      <td>26</td>\n",
       "      <td>1528.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1.2</th>\n",
       "      <td>all-souls_org</td>\n",
       "      <td>04.02.15AfraidOfTheDark.mp3</td>\n",
       "      <td>Mornings readings are. 2 and brief. The first ...</td>\n",
       "      <td>123</td>\n",
       "      <td>139.6</td>\n",
       "      <td>6</td>\n",
       "      <td>697.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1.3</th>\n",
       "      <td>all-souls_org</td>\n",
       "      <td>03.01.26AwesomeMeetsTheFamiliar.mp3</td>\n",
       "      <td>It is a great joy and privilege for me to be h...</td>\n",
       "      <td>269</td>\n",
       "      <td>323.8</td>\n",
       "      <td>5</td>\n",
       "      <td>1443.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1.4</th>\n",
       "      <td>all-souls_org</td>\n",
       "      <td>04.02.11WhatGoodIsGod.mp3</td>\n",
       "      <td>I've told many of you how excited i am to have...</td>\n",
       "      <td>125</td>\n",
       "      <td>367.6</td>\n",
       "      <td>3</td>\n",
       "      <td>1387.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1.5</th>\n",
       "      <td>all-souls_org</td>\n",
       "      <td>04.02.29ConspiracyAgainstVu.mp3</td>\n",
       "      <td>Some of you may have thought that. Service wou...</td>\n",
       "      <td>198</td>\n",
       "      <td>280.8</td>\n",
       "      <td>7</td>\n",
       "      <td>1248.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45.470</th>\n",
       "      <td>uufvb_org</td>\n",
       "      <td>2012Mar18Sermon32.mp3</td>\n",
       "      <td>30 years old. Person. Usefulness. By the time ...</td>\n",
       "      <td>302</td>\n",
       "      <td>209.8</td>\n",
       "      <td>4</td>\n",
       "      <td>913.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45.471</th>\n",
       "      <td>uufvb_org</td>\n",
       "      <td>2015Feb22Sermon128.mp3</td>\n",
       "      <td>Good morning everyone is glad to be 80° today ...</td>\n",
       "      <td>632</td>\n",
       "      <td>450.8</td>\n",
       "      <td>20</td>\n",
       "      <td>1885.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45.472</th>\n",
       "      <td>uufvb_org</td>\n",
       "      <td>2011Jul24Sermon32.mp3</td>\n",
       "      <td>4 years ago. As my partner charlie and i were ...</td>\n",
       "      <td>405</td>\n",
       "      <td>295.8</td>\n",
       "      <td>5</td>\n",
       "      <td>1386.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45.473</th>\n",
       "      <td>uufvb_org</td>\n",
       "      <td>2015Feb15Sermon32.mp3</td>\n",
       "      <td>Good morning. Welcome to the unitarian univers...</td>\n",
       "      <td>472</td>\n",
       "      <td>345.6</td>\n",
       "      <td>18</td>\n",
       "      <td>1592.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45.474</th>\n",
       "      <td>uufvb_org</td>\n",
       "      <td>2010Dec12Sermon128.mp3</td>\n",
       "      <td>I shared the words of bill mckibben with joyce...</td>\n",
       "      <td>463</td>\n",
       "      <td>225.5</td>\n",
       "      <td>411</td>\n",
       "      <td>1339.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6900 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               church                               source  \\\n",
       "1.1     all-souls_org         04.02.22ILeftMyHeartInSF.mp3   \n",
       "1.2     all-souls_org          04.02.15AfraidOfTheDark.mp3   \n",
       "1.3     all-souls_org  03.01.26AwesomeMeetsTheFamiliar.mp3   \n",
       "1.4     all-souls_org            04.02.11WhatGoodIsGod.mp3   \n",
       "1.5     all-souls_org      04.02.29ConspiracyAgainstVu.mp3   \n",
       "...               ...                                  ...   \n",
       "45.470      uufvb_org                2012Mar18Sermon32.mp3   \n",
       "45.471      uufvb_org               2015Feb22Sermon128.mp3   \n",
       "45.472      uufvb_org                2011Jul24Sermon32.mp3   \n",
       "45.473      uufvb_org                2015Feb15Sermon32.mp3   \n",
       "45.474      uufvb_org               2010Dec12Sermon128.mp3   \n",
       "\n",
       "                                                     text  sentences  \\\n",
       "1.1     Our reading this morning. Is from the same scr...        177   \n",
       "1.2     Mornings readings are. 2 and brief. The first ...        123   \n",
       "1.3     It is a great joy and privilege for me to be h...        269   \n",
       "1.4     I've told many of you how excited i am to have...        125   \n",
       "1.5     Some of you may have thought that. Service wou...        198   \n",
       "...                                                   ...        ...   \n",
       "45.470  30 years old. Person. Usefulness. By the time ...        302   \n",
       "45.471  Good morning everyone is glad to be 80° today ...        632   \n",
       "45.472  4 years ago. As my partner charlie and i were ...        405   \n",
       "45.473  Good morning. Welcome to the unitarian univers...        472   \n",
       "45.474  I shared the words of bill mckibben with joyce...        463   \n",
       "\n",
       "        processing_time  transcription_errors  duration(s)  \n",
       "1.1               327.6                    26       1528.2  \n",
       "1.2               139.6                     6        697.2  \n",
       "1.3               323.8                     5       1443.6  \n",
       "1.4               367.6                     3       1387.1  \n",
       "1.5               280.8                     7       1248.1  \n",
       "...                 ...                   ...          ...  \n",
       "45.470            209.8                     4        913.2  \n",
       "45.471            450.8                    20       1885.9  \n",
       "45.472            295.8                     5       1386.5  \n",
       "45.473            345.6                    18       1592.7  \n",
       "45.474            225.5                   411       1339.5  \n",
       "\n",
       "[6900 rows x 7 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# rows are (church, MP3): cols are text, etc.\n",
    "vals = []\n",
    "ids = []\n",
    "for idx,item in enumerate(data):\n",
    "    _id = 1\n",
    "    for mp3,val in item.items():\n",
    "        vals.append(val) # dict with text, time, sent, errors, dur, file(name)\n",
    "        ids.append(f\"{idx+1}.{_id}\")\n",
    "        _id += 1\n",
    "df = pd.DataFrame(data=vals, columns=['church', 'file', 'text', 'sentences', 'processing_time', 'errors', 'duration'], index=ids)\n",
    "df.duration = df.duration.round(1)\n",
    "df = df.rename(columns={'duration': 'duration(s)', 'file':'source', 'errors':'transcription_errors'})\n",
    "df.to_csv(\"unitarian-universalist-church-sermons-n=6900b.csv\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd50088f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}