-
Notifications
You must be signed in to change notification settings - Fork 0
/
top10.py
796 lines (658 loc) · 25.1 KB
/
top10.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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import re
import os
import argparse
import csv
import logging
import string
import gzip
from ftfy import fix_text
from zipfile import ZipFile, ZIP_DEFLATED
import newspaper
from newspaper import Article
from bs4 import BeautifulSoup
from scraper import SimpleScraper, SeleniumScraper
from datetime import datetime
from configparser import ConfigParser
from notification import Notification
import time
from selenium.webdriver.common.by import By
"""
CSV with following fields:
date, time, src, url, order on the list, text of the link,
title of the article, path to local content file
* Multiple folders --- one for each news org and
containing content of the files in a standard format
(after newspaper package), stripped off all HTML,
name of each file = three_letter_src_name_date_time_order
"""
CSV_HEADER = ['date', 'time', 'src', 'src_list', 'url', 'order', 'link_text']
NEWSPAPER_HEADER = ['path', 'title', 'text', 'top_image', 'authors',
'summary', 'keywords']
MAX_RETRY = 5
def test_newspaper(url):
paper = newspaper.build(url)
for article in paper.articles:
print(article.url)
for category in paper.category_urls():
print(category)
def setup_logger():
""" Set up logging
"""
# create logs dir if not exists
if not os.path.exists('./logs'):
os.makedirs('./logs')
now = datetime.utcnow()
logfilename = "./logs/top10-{0:s}.log".format(now.strftime('%Y%m%d%H%M%S'))
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename=logfilename,
filemode='a')
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
return logfilename
def remove_special_chars(text):
"""remove all special characters except the period (.)
and question mark (?)
for instance, ">", "~", ", $, |, etc.
"""
schars = ''.join([a for a in string.punctuation if a not in ".?"])
text = re.sub('[%s]' % re.escape(schars), '', text)
return text
def clean_text(text):
text = fix_text(text)
text = ' '.join(text.split('\n'))
text = remove_special_chars(text)
return text
def get_record_template(src, src_list=''):
now = datetime.utcnow()
data = {}
data['date'] = now.strftime('%Y-%m-%d')
data['time'] = now.strftime('%H:%M:%S')
data['src'] = src
data['src_list'] = src_list
return data
def washingtonpost_top_politics(n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('https://www.washingtonpost.com/politics/?nid=top_nav_politics')
if not html:
logging.error("Cannot get website")
return results
soup = BeautifulSoup(html, 'html.parser')
for a in soup.select('.story-headline h3 a'):
data = get_record_template('washingtonpost', 'top-politics')
data['url'] = a['href']
data['link_text'] = a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def washingtonpost_mostread(section='politics', n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('https://www.washingtonpost.com/{0:s}'.format(section))
if not html:
logging.error("Cannot get website")
return results
soup = BeautifulSoup(html, 'html.parser')
most_read = soup.find('div', {'id': 'post-most-rr'})
for h in most_read.select('div.headline'):
a = h.parent
if a.name != 'a':
continue
data = get_record_template('washingtonpost',
'mostread-{0:s}'.format(section))
data['url'] = a['href']
data['link_text'] = h.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def washingtonpost_topmost(n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('https://www.washingtonpost.com/pb/themost/')
if not html:
logging.error("Cannot get website")
return results
soup = BeautifulSoup(html, 'html.parser')
for div in soup.select('.feed-link'):
if 'feed-title' in div['class']:
continue
data = get_record_template('washingtonpost', 'themost-atlantic')
try:
data['link_text'] = div.span.text.strip()
except:
continue
onclick = div['onclick']
m = re.match("window\.open\('(.*?)'.*", onclick)
if m:
data['url'] = m.group(1)
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def nyt_mostviewed(section='national', time_period=1, offet=0, n=5, results=None, api_key=''):
if results is None:
results = []
"""
REF: https://developer.nytimes.com/most_popular_api_v2.json
https://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?api_key=e9857cefff754d7dacad8df079a803c0
https://api.nytimes.com/svc/mostpopular/v2/mostviewed/national/1.json?api_key=e9857cefff754d7dacad8df079a803c0
Example :-
{
"status": "string",
"copyright": "string",
"num_results": 0,
"results": [
{
"url": "string",
"column": "string",
"section": "string",
"byline": "string",
"title": "string",
"abstract": "string",
"published_date": "string",
"source": "string"
}
]
}
"""
scraper = SimpleScraper()
url = 'https://api.nytimes.com/svc/mostpopular/v2/mostviewed/{0}/{1}.json?api-key={2}'.format(section, time_period, api_key)
json_str = scraper.get(url)
if not json_str:
logging.error("Cannot get website")
return results
j = json.loads(json_str)
for r in j['results']:
data = get_record_template('nyt', 'mostviewed-{0:s}'.format(section))
data['url'] = r['url']
data['link_text'] = r['title']
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def wsj_twitter_pop():
# TODO:
pass
def wsj_mostpop(n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('http://www.wsj.com/')
if not html:
logging.error("Cannot get website")
return results
with open('html/wsj-mostpop.html', 'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
for a in soup.select('.wsj-popular-list.article .wsj-popular-item .pop-item-link'):
data = get_record_template('wsj', 'mostpop')
data['url'] = a['href']
data['link_text'] = a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def wsj_mostpop_politics(n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('http://www.wsj.com/news/politics')
if not html:
logging.error("Cannot get website")
return results
with open('html/wsj-mostpop-politics.html', 'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
for a in soup.select('.wsj-popular-list.article .wsj-popular-item .pop-item-link'):
data =get_record_template('wsj', 'mostpop-politics')
data['url'] = a['href']
data['link_text'] = a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def foxnews_mostpop(section='politics', n=5, results=None):
if results is None:
results = []
"""
There is JSON API
http://www.foxnews.com/feeds/trending/all/feed/json?callback=articles
http://www.foxnews.com/feeds/trending/politics/feed/json?callback=articles
"""
scraper = SimpleScraper()
json_str = scraper.get('http://www.foxnews.com/feeds/trending/{0:s}/feed/json?callback=articles'
.format(section))
if not json_str:
logging.error("Cannot get website")
return results
m = re.match('articles\((.*)\)', json_str, flags=re.S)
if m:
json_str = m.group(1)
j = json.loads(json_str)
for d in j['response']['docs']:
data = get_record_template('foxnews', 'mostpop-{0:s}'.format(section))
data['url'] = d['url'][0]
data['link_text'] = d['title']
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def foxnews_feeds(section='national', n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('http://feeds.foxnews.com/foxnews/{0:s}'
.format(section))
if not html:
logging.error("Cannot get website")
return results
soup = BeautifulSoup(html, 'lxml')
for item in soup.select('item'):
data = get_record_template('foxnews', 'feeds-{0:s}'.format(section))
data['url'] = item.select('guid')[0].text
data['link_text'] = item.select('title')[0].text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def huffingtonpost_mostpop(n=5, results=None):
if results is None:
results = []
"""
There is JSON API
http://www.huffpost.com/mapi/v2/us/trending?device=desktop&statsType=rawPageView&statsPlatform=desktop&algo=trending
"""
scraper = SimpleScraper()
json_str = scraper.get('http://www.huffpost.com/mapi/v2/us/trending?device=desktop&statsType=rawPageView&statsPlatform=desktop&algo=trending')
if not json_str:
logging.error("Cannot get website")
return results
j = json.loads(json_str)
urls = []
for e in j['results']['entries']:
if e['section_name'].lower() == 'politics':
data = get_record_template('huffingtonpost', 'mostpop-politics')
data['url'] = e['huffpost_url']
data['link_text'] = e['label']
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def huffingtonpost_trending(n=5, results=None):
if results is None:
results = []
scraper = SeleniumScraper()
html = scraper.get('http://www.huffpost.com/')
if not html:
logging.error("Cannot get website")
return results
soup = BeautifulSoup(html, 'lxml')
trending = soup.find('div', {'id': 'trending-zone'})
for a in trending.select('h2 a.card__link'):
data = get_record_template('huffingtonpost', 'trending')
data['url'] = a['href']
data['link_text'] = a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def usatoday_mostpop(n=5, results=None):
if results is None:
results = []
"""
There is only 4 items
"""
scraper = SimpleScraper()
html = scraper.get('http://www.usatoday.com/')
if not html:
logging.error("Cannot get website")
return results
with open('html/usatoday-mostpop.html', 'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
urls = []
for a in soup.select('.hfwmm-light-list-link')[:n]:
data = get_record_template('usatoday', 'mostpop')
data['url'] = 'http://www.usatoday.com' + a['href']
data['link_text'] = a.text.strip()
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def google_news(n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('https://news.google.com/')
if not html:
logging.error("Cannot get website")
return results
with open('html/google-news.html', 'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
for a in soup.select('.top-stories-section h2 .article'):
data = get_record_template('google', 'mostpop')
data['url'] = a['href']
data['link_text'] = a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def google_news_politics(n=5, results=None):
if results is None:
results = []
scraper = SimpleScraper()
html = scraper.get('https://news.google.com/?ned=us&topic=po')
if not html:
logging.error("Cannot get website")
return results
with open('html/google-news-politics.html', 'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
for a in soup.select('h2 a.article'):
data = get_record_template('google', 'mostpop-politics')
data['url'] = a['href']
data['link_text'] = a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def yahoo_news(n=5, results=None):
if results is None:
results = []
scraper = SeleniumScraper()
html = scraper.get('https://www.yahoo.com/news/')
if not html:
logging.error("Cannot get website")
return results
with open('html/yahoo-news.html', 'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
for h2 in soup.select('h2'):
if h2.parent.name == 'a':
href = h2.parent['href']
if href.startswith('/news/'):
data = get_record_template('yahoo', 'mostpop')
data['url'] = 'https://www.yahoo.com' + href
data['link_text'] = h2.text
if data not in results:
results.append(data)
if len(results) >= n:
return results
for h3 in soup.select('h3'):
if h3.a:
href = h3.a['href']
if href.startswith('/news/'):
data = get_record_template('yahoo', 'mostpop')
data['url'] = 'https://www.yahoo.com' + href
data['link_text'] = h3.a.text
if data not in results:
results.append(data)
if len(results) >= n:
break
return results
def yahoo_news_top_politics(n=5, results=None, src_list='original'):
if results is None:
results = []
button = {'original': 'Yahoo Originals',
'ap': 'AP',
'reuters': 'Reuters'}
prov = {'original': 'YahooNews',
'ap': 'AssociatedPress',
'reuters': 'Reuters'}
# FIXME: retry a few times to workaround sometime failed change provider.
retry = 0
while retry < 5:
scraper = SeleniumScraper()
html = scraper.get('http://news.yahoo.com/most-popular/?pt=BureoF4GVB/?format=rss')
if not html:
logging.error("Cannot get website")
return results
try:
drv = scraper.driver
elem = drv.find_element(By.XPATH,
'//a[@data-action-outcome="slcfltr" \
and contains(text(), "{0}")]'
.format(button[src_list]))
elem.click()
# FIXME: delay to make sure content updated.
time.sleep(5)
html = scraper.driver.page_source
except Exception as e:
logging.error(str(e))
return results
with open('html/yahoo-news-top-politics-{0}.html'.format(src_list),
'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
for li in soup.select('li.content'):
for h3 in li.select('h3'):
if h3.a:
href = h3.a['href']
match = False
try:
data_ylk = h3.a['data-ylk']
meta = data_ylk.split(';')
for m in meta:
if m.startswith('prov'):
key, value = m.split(':')
if value == prov[src_list]:
match = True
break
except:
pass
if not match:
continue
if href.startswith('https://www.yahoo.com/news/'):
data = get_record_template('yahoo', 'mostpop-{0:s}'
.format(src_list))
data['url'] = href
data['link_text'] = h3.a.text
if data not in results:
results.append(data)
if len(results) >= n:
return results
retry += 1
logging.info("Failed to change Yahoo news provider, retry #{0:d}"
.format(retry))
return results
def rss_yahoo_news_top_politics(n=5, results=None, src_list='original'):
if results is None:
results = []
sources = {'original': 'yahoo',
'ap': 'ap.org',
'reuters': 'reuters.com'}
retry = 0
while retry < 5:
scraper = SimpleScraper()
html = scraper.get('https://news.yahoo.com/rss/politics')
if not html:
logging.error("Cannot get website")
return results
with open('html/yahoo-news-top-politics-{0}.html'.format(src_list),
'w', encoding='utf-8') as f:
f.write(html)
soup = BeautifulSoup(html, 'xml')
for item in soup.select('item'):
source_url = item.source['url']
if source_url.find(sources[src_list]) != -1:
href = item.link.text
if href.startswith('https://news.yahoo.com/'):
data = get_record_template('yahoo', 'mostpop-{0:s}'
.format(src_list))
data['url'] = href
data['link_text'] = item.title.text
if data not in results:
results.append(data)
if len(results) >= n:
return results
retry += 1
logging.info("Failed to change Yahoo news provider, retry #{0:d}"
.format(retry))
return results
def process_newspaper(r, compress=False):
retry = 0
while retry < MAX_RETRY:
try:
logging.info("Processing URL {0:s}".format(r['url']))
article = Article(url=r['url'])
article.download()
dt = r['date'].replace('-', '') + r['time'].replace(':', '')
name = '{0!s}_{1!s}_{2:d}.html'.format(r['src'], dt, r['order'])
outdir = './news/{0!s}'.format(r['src'])
if not os.path.exists(outdir):
os.mkdir(outdir)
filename = os.path.join(outdir, name)
if compress:
filename += '.gz'
with gzip.open(filename, 'wb') as f:
f.write(bytes(article.html, 'utf-8'))
else:
with open(filename, 'w', encoding='utf-8') as f:
f.write(article.html)
r['path'] = filename
article.parse()
r['text'] = clean_text(article.text)
r['top_image'] = article.top_image
r['authors'] = '|'.join(article.authors)
r['title'] = clean_text(article.title)
#print(article.images)
#print(article.movies)
article.nlp()
r['summary'] = clean_text(article.summary)
r['keywords'] = '|'.join(article.keywords)
break
except Exception as e:
logging.error(e)
retry += 1
logging.warn("Retry #{0:d}".format(retry))
return r
def write_to_csv(writer, results, compress=False):
for i, r in enumerate(results):
r['order'] = i + 1
r = process_newspaper(r, compress)
r['link_text'] = clean_text(r['link_text'])
writer.writerow(r)
def load_config(args):
config = ConfigParser()
config.read(args.config)
args.nyt_api_key = config.get('api', 'nyt_api_key')
args.web_path = config.get('web', 'path')
args.web_url = config.get('web', 'url')
def make_output_web_link(args):
ts_str = args.timestamp.strftime('%Y%m%d-%H%M%S')
filename = 'top10-output-{0:s}.zip'.format(ts_str)
logging.info("Pushing output to web server... {0:s}".format(filename))
filepath = os.path.join(args.web_path, filename)
with ZipFile(filepath, 'w', ZIP_DEFLATED) as zf:
zf.write(args.output)
return (args.web_url + filename)
if __name__ == "__main__":
timestamp = datetime.utcnow()
logfilename = setup_logger()
parser = argparse.ArgumentParser(description='Top News! scraper')
parser.add_argument('-c', '--config', default='top10.cfg',
help='Configuration file')
parser.add_argument('-n', '--count', type=int, default=10,
help='Top N')
parser.add_argument('-o', '--output', default='output.csv',
help='Output file name')
parser.add_argument('--with-header', dest='header', action='store_true',
help='Output with header at the first row')
parser.set_defaults(header=False)
parser.add_argument('--compress', dest='compress',
action='store_true',
help='Compress download HTML files')
parser.set_defaults(compress=False)
args = parser.parse_args()
args.timestamp = timestamp
load_config(args)
logging.info(args)
# to keep scraped data
if not os.path.exists('./html'):
os.mkdir('./html')
# to keep news data
if not os.path.exists('./news'):
os.mkdir('./news')
with open(args.output, 'a', encoding='utf-8', newline='') as f:
writer = csv.DictWriter(f, fieldnames=CSV_HEADER + NEWSPAPER_HEADER,
dialect='excel', quoting=csv.QUOTE_NONNUMERIC)
if args.header:
writer.writeheader()
logging.info("Scraping Washington Post...")
res = washingtonpost_mostread('politics', args.count / 2)
res += washingtonpost_mostread('regional', args.count / 2)
res += washingtonpost_topmost(args.count / 2)
write_to_csv(writer, res, args.compress)
logging.info("Scraping Newyork Times...")
res = nyt_mostviewed('all-sections', n=args.count, api_key=args.nyt_api_key)
res += nyt_mostviewed('national', n=args.count, api_key=args.nyt_api_key)
res += nyt_mostviewed('politics', n=args.count, api_key=args.nyt_api_key)
write_to_csv(writer, res, args.compress)
logging.info("Scraping Wall Street Journal...")
# FIXME: getting same link from either homepage or politics page.
res = wsj_mostpop(args.count)
#res = wsj_mostpop_politics(args.count, res)
write_to_csv(writer, res, args.compress)
logging.info("Scraping Foxnews...")
res = foxnews_mostpop('politics', args.count)
res += foxnews_mostpop('all', args.count)
# FIXME: should get same res as above
#res += foxnews_feeds('most-popular', args.count)
res += foxnews_feeds('national', args.count)
write_to_csv(writer, res, args.compress)
logging.info("Scraping Huffington Post...")
res = huffingtonpost_mostpop(args.count)
# FIXME: seems no trending zone in the home page.
# res += huffingtonpost_trending(args.count)
write_to_csv(writer, res, args.compress)
logging.info("Scraping USA Today...")
res = usatoday_mostpop(args.count)
write_to_csv(writer, res, args.compress)
""" FIXME: Skipped, will update later
logging.info("Scraping Google News...")
res = google_news(args.count)
res += google_news_politics(args.count / 2)
write_to_csv(writer, res, args.compress)
"""
logging.info("Scraping Yahoo News...")
res = rss_yahoo_news_top_politics(args.count)
res += rss_yahoo_news_top_politics(args.count, None, 'ap')
res += rss_yahoo_news_top_politics(args.count, None, 'reuters')
write_to_csv(writer, res, args.compress)
logging.info("Done")
body = ""
if args.web_url != '':
web_link = make_output_web_link(args)
body += "Latest CSV output available at {0:s}\n".format(web_link)
ts_str = timestamp.strftime('%Y-%m-%d %H:%M:%S')
notification = Notification(args.config)
subject = 'Top New! scraper ({0:s})'.format(ts_str)
body += "Please check out log file for more detail."
notification.send_email(subject, body, logfilename)