Skip to content

Commit b0f3b59

Browse files
committed
add library usage demo notebook
1 parent f691591 commit b0f3b59

2 files changed

Lines changed: 534 additions & 0 deletions

File tree

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from dateandtimeparser import DateTimeParser"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"S1 = 'Today is 10/12/16 and tomorrow is January 01 2019.'\n",
19+
"S2 = 'entries are due by January 4, 2017 at 8:00pm'\n",
20+
"S3 = 'created 01/15/2005 by ACME Inc. and associates.'\n",
21+
"S4 = 'Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014'\n",
22+
"\n",
23+
"texts = [S1, S2, S3, S4]"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 3,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stderr",
33+
"output_type": "stream",
34+
"text": [
35+
"DATETIME: 2019-07-09 21:03:33,093 INFO Extracting dates from the text.\n"
36+
]
37+
},
38+
{
39+
"name": "stdout",
40+
"output_type": "stream",
41+
"text": [
42+
"TEXT: Today is 10/12/16 and tomorrow is January 01 2019.\n",
43+
"\n",
44+
"datetime(date='january 01 2019', token_span=(34, 49), token_index=(6, 8), format='%B %d %Y')\n",
45+
"----------------------------------------------------------------------------------------------------\n",
46+
"datetime(date='10/12/16', token_span=(9, 17), token_index=(2, 2), format='%d/%m/%y')\n",
47+
"----------------------------------------------------------------------------------------------------\n",
48+
"****************************************************************************************************\n"
49+
]
50+
},
51+
{
52+
"name": "stderr",
53+
"output_type": "stream",
54+
"text": [
55+
"DATETIME: 2019-07-09 21:03:33,376 INFO Extracting dates from the text.\n",
56+
"DATETIME: 2019-07-09 21:03:33,614 INFO Extracting dates from the text.\n"
57+
]
58+
},
59+
{
60+
"name": "stdout",
61+
"output_type": "stream",
62+
"text": [
63+
"TEXT: entries are due by January 4, 2017 at 8:00pm\n",
64+
"\n",
65+
"EXTRACTION FAILED.\n",
66+
"\n",
67+
"****************************************************************************************************\n",
68+
"TEXT: created 01/15/2005 by ACME Inc. and associates.\n",
69+
"\n",
70+
"datetime(date='01/15', token_span=(8, 13), token_index=(1, 1), format='%m/%d')\n",
71+
"----------------------------------------------------------------------------------------------------\n",
72+
"****************************************************************************************************\n"
73+
]
74+
},
75+
{
76+
"name": "stderr",
77+
"output_type": "stream",
78+
"text": [
79+
"DATETIME: 2019-07-09 21:03:33,866 INFO Extracting dates from the text.\n"
80+
]
81+
},
82+
{
83+
"name": "stdout",
84+
"output_type": "stream",
85+
"text": [
86+
"TEXT: Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014\n",
87+
"\n",
88+
"datetime(date='dec 31 2015', token_span=(14, 25), token_index=(2, 4), format='%b %d %Y')\n",
89+
"----------------------------------------------------------------------------------------------------\n",
90+
"datetime(date='dec.01.2015', token_span=(0, 11), token_index=(0, 0), format='%b.%d.%Y')\n",
91+
"----------------------------------------------------------------------------------------------------\n",
92+
"datetime(date='dec,12,2015', token_span=(28, 39), token_index=(6, 6), format='%b,%d,%Y')\n",
93+
"----------------------------------------------------------------------------------------------------\n",
94+
"datetime(date='dec,12,2015', token_span=(42, 53), token_index=(8, 8), format='%b,%d,%Y')\n",
95+
"----------------------------------------------------------------------------------------------------\n",
96+
"datetime(date='dec122014', token_span=(72, 81), token_index=(12, 12), format='%b%d%Y')\n",
97+
"----------------------------------------------------------------------------------------------------\n",
98+
"****************************************************************************************************\n"
99+
]
100+
}
101+
],
102+
"source": [
103+
"for text in texts:\n",
104+
" TEXT = f\"TEXT: {text}\\n\"\n",
105+
" try:\n",
106+
" parsed_dates = DateTimeParser(text, 2000, 2020, ['%b%d%Y', '%b.%d.%Y', '%b,%d,%Y', '%b,%d and %Y']) # pass your own custom formats, or just leave it.\n",
107+
" print(TEXT)\n",
108+
" for datetime in parsed_dates.datetime:\n",
109+
" print(datetime)\n",
110+
" print(\"-\"*100)\n",
111+
" print(\"*\"*100)\n",
112+
" except Exception:\n",
113+
" print(TEXT)\n",
114+
" print(\"EXTRACTION FAILED.\\n\")\n",
115+
" print(\"*\"*100)\n",
116+
" pass"
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"metadata": {},
123+
"outputs": [],
124+
"source": []
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": null,
129+
"metadata": {},
130+
"outputs": [],
131+
"source": []
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": null,
136+
"metadata": {},
137+
"outputs": [],
138+
"source": []
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {},
144+
"outputs": [],
145+
"source": []
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"metadata": {},
151+
"outputs": [],
152+
"source": []
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": []
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {},
165+
"outputs": [],
166+
"source": []
167+
},
168+
{
169+
"cell_type": "code",
170+
"execution_count": null,
171+
"metadata": {},
172+
"outputs": [],
173+
"source": []
174+
},
175+
{
176+
"cell_type": "code",
177+
"execution_count": null,
178+
"metadata": {},
179+
"outputs": [],
180+
"source": []
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": null,
185+
"metadata": {},
186+
"outputs": [],
187+
"source": []
188+
},
189+
{
190+
"cell_type": "code",
191+
"execution_count": null,
192+
"metadata": {},
193+
"outputs": [],
194+
"source": []
195+
},
196+
{
197+
"cell_type": "code",
198+
"execution_count": null,
199+
"metadata": {},
200+
"outputs": [],
201+
"source": []
202+
},
203+
{
204+
"cell_type": "code",
205+
"execution_count": null,
206+
"metadata": {},
207+
"outputs": [],
208+
"source": []
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": null,
213+
"metadata": {},
214+
"outputs": [],
215+
"source": []
216+
},
217+
{
218+
"cell_type": "code",
219+
"execution_count": null,
220+
"metadata": {},
221+
"outputs": [],
222+
"source": []
223+
},
224+
{
225+
"cell_type": "code",
226+
"execution_count": null,
227+
"metadata": {},
228+
"outputs": [],
229+
"source": []
230+
},
231+
{
232+
"cell_type": "code",
233+
"execution_count": null,
234+
"metadata": {},
235+
"outputs": [],
236+
"source": []
237+
},
238+
{
239+
"cell_type": "code",
240+
"execution_count": null,
241+
"metadata": {},
242+
"outputs": [],
243+
"source": []
244+
}
245+
],
246+
"metadata": {
247+
"kernelspec": {
248+
"display_name": "Python 3",
249+
"language": "python",
250+
"name": "python3"
251+
},
252+
"language_info": {
253+
"codemirror_mode": {
254+
"name": "ipython",
255+
"version": 3
256+
},
257+
"file_extension": ".py",
258+
"mimetype": "text/x-python",
259+
"name": "python",
260+
"nbconvert_exporter": "python",
261+
"pygments_lexer": "ipython3",
262+
"version": "3.7.2"
263+
}
264+
},
265+
"nbformat": 4,
266+
"nbformat_minor": 2
267+
}

0 commit comments

Comments
 (0)