-
Notifications
You must be signed in to change notification settings - Fork 5
/
muttqt
executable file
·790 lines (691 loc) · 25 KB
/
muttqt
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
#!/usr/bin/env python
"""muttqt - Mutt query tool.
Stores sent addresses to a database and queries the database and other sources
for email addresses."""
import os
import sys
# import fileinput
import argparse
import sqlite3
import email
import email.utils
import datetime as dt
# from time import strftime
import subprocess as sp
import shlex
from configparser import ConfigParser
__version__ = "0.2.0"
__commit__ = None
# constants
# configfile = '~/.muttqt/muttqt.conf'
# configfile = os.path.expanduser(configfile)
sqldateformat = '%Y-%m-%d %H:%M:%S'
lbdbdateformat = '%Y-%m-%d %H:%M'
class dataSource(object):
def __init__(self, cfg, getData = True):
self.cfg = cfg
if getData:
self.getData()
def printResults(self, numbered = False):
"""Print search results."""
if numbered:
# data = []
# for i,d in enumerate(self.results):
# t = [str(i),]
# t.extend(d[1:])
# data.append(tuple(t))
data = [tuple(t) for t in self.results]
fstr = "{}\t{}\t{}\t{}"
else:
data = self.results
fstr = "{}\t{}\t{}"
i = len(self.results)
print("{0} matches:".format(i))
for i, s in enumerate(data):
out = fstr.format(*s)
print(out)
def searchData(self, query):
"""Search list data for query."""
results = []
query = query.lower()
for l in self.data:
if l[0].lower().find(query) > -1 or l[1].lower().find(query) > -1:
results.append(l)
self.query = query
self.results = results
def getData(self):
pass
class aliasData(dataSource):
def __init__(self, cfg, datatype = 'alias', getData = True):
self.datatype = datatype
super(aliasData, self).__init__(cfg, getData = getData)
def getData(self):
"""Read data from mutt alias files."""
files = self.cfg.get(self.datatype, 'files').split(',')
files = [os.path.expanduser(f.strip()) for f in files]
self.files = files
data = []
for fn in files:
try:
f = open(fn)
lines = f.readlines()
f.close()
except:
return []
for line in lines:
l = line.rstrip().split()
if l != [] and l[0] == 'alias':
stuff = l[1:]
nick = "%s [%s]" % (stuff[0], os.path.basename(fn))
addy = " ".join(stuff[1:])
# some addresses seem to have escaped " - get rid of them
# addy = addy.translate(None, '\\')
# addy = addy.translate({ord(c): None for c in '\\'})
addy = addy.replace('\\', '')
if addy.find(',') == -1:
a = email.utils.parseaddr(addy)
# If we don't have a name, let's take the first part of
# the email address and use that
if a[0] == '':
a = (a[1].split('@')[0], a[1])
data.append((a[1], a[0], nick))
self.data = data
class sentTxtData(dataSource):
def __init__(self, cfg, datatype = 'senttxt', getData = True):
self.datatype = datatype
super(sentTxtData, self).__init__(cfg, getData = getData)
def getData(self):
"""Gets all data in the sent txt file.
This file has the same format as an LBDB database."""
fn = self.cfg.get('sent', 'txtfile')
tempdat = ingestLBDB(fn)
data = []
for i,d in enumerate(tempdat):
t = [str(i),]
t.extend(d)
data.append(tuple(t))
self.data = data
def getAllSent(self):
self.results = self.data
def datePruneSent(self, date):
"""Remove addresses from sent txt file prior to date.
Date should be in YYYY-MM-DD format."""
self.getAllSent()
data = self.results
sorttmp = [(a[3], a, i) for i,a in enumerate(data)]
sorttmp.sort()
sorttmp.reverse()
from dateutil.parser import parse
d = parse(date)
for i,a in enumerate(sorttmp):
t = dt.datetime.strptime(a[0], sqldateformat)
if d > t:
break
sorttmp = sorttmp[:i]
results = [a[1] for a in sorttmp]
self.writeSent(results)
def removeSent(self, rowids):
"""Delete addresses from the SQL txt file.
Addresses to be deleted are specified by rowid."""
rowids = [int(i) for i in rowids]
self.getAllSent()
data = self.results
pruned = [j for i,j in enumerate(data) if i not in rowids]
self.writeSent(pruned)
def writeSent(self, data, enc = 'utf-8'):
"""Write sent addresses to the txt file.
This function looks for the number of columns in the data. If there are
3, we assume that the data was scraped from an email using ingestEmail,
so the file is opened up in append mode and the data just added to the
end. If there are 4 columns, assume the data is either a full listing
or a pruned listing, so open the file up in write mode and overwrite the
existing data.
Note (as of now) that unlike the SQL version of this function, no
attempt is made to prune duplicate email entries."""
# this is hackish
if len(data[0]) == 3:
k = 0
mode = 'a'
elif len(data[0]) == 4:
k = 1
mode = 'w'
fn = self.cfg.get('sent', 'txtfile')
fn = os.path.expanduser(fn)
lines = []
for d in data:
t = dt.datetime.strptime(d[k+2], sqldateformat)
tmp = (d[k+0], d[k+1], t.strftime(lbdbdateformat))
line = '\t'.join(tmp) + '\n'
lines.append(line)
try:
import codecs
f = codecs.open(fn, mode, enc)
# f = open(fn, mode)
f.writelines(lines)
f.close()
except:
print("problem writing file {}".format(fn))
sys.exit(13)
def searchData(self, query, sortby):
"""Query the sent address txt file.
Matches against name or email."""
fn = self.cfg.get('sent', 'txtfile')
data = ingestLBDB(fn)
results = searchDat(data, query)
o = {'email':0, 'name':1, 'date':2}
i = o[sortby]
sorttmp = [(a[i], a) for a in results]
sorttmp.sort()
if sortby == 'date':
sorttmp.reverse()
results = [a[1] for a in sorttmp]
self.results = results
class sentSQLData(dataSource):
def __init__(self, cfg, datatype = 'sentsql', getData = True):
self.datatype = datatype
super(sentSQLData, self).__init__(cfg, getData = getData)
def getData(self):
self.getSQL()
self.data = []
def getSQL(self, make = False):
"""Connect to the sent mail SQL db file."""
sqlfn = os.path.expanduser(self.cfg.get('sent', 'sqlfile'))
if not make and not os.path.exists(sqlfn):
return
sql = sqlite3.connect(sqlfn)
c = sql.cursor()
self.sql = sql
self.c = c
def createTables(self):
"""Creates the default table in the SQL db."""
try:
self.getSQL(make = True)
sql = self.sql
c = self.c
except:
print("can't make sqlite db")
sys.exit(12)
tables = c.execute('select name from sqlite_master')
tlist = []
for table in tables:
tlist.append(table[0])
if 'addresses' not in tlist:
c.execute('create table addresses (email text, name text, '
'date text)')
# think about not having the unique index be keyed to name as well
c.execute('create unique index "post_email" on addresses '
'(email, name)')
def getAllSent(self):
"""Gets all data in the sent SQL db.
Entries are prefixed by the rowid of the entry and are sorted
alphabetically by email address."""
try:
sql = self.sql
c = self.c
except:
print("no sent sql db")
sys.exit(11)
c.execute('select rowid, email, name, date from addresses order '
'by email')
sqlchildren = c.fetchall()
# c.close()
results = [s for s in sqlchildren]
self.results = results
def searchData(self, query, sortby = 'name'):
"""Query the sent address SQL db.
Matches against name or email."""
try:
sql = self.sql
c = self.c
except:
return
cfg = self.cfg
displaydateformat = cfg.get('sent', 'date-format', raw=True)
sortTerms = {
'email': 'email',
'name': 'name',
'date': 'date desc' }
s = sortTerms[sortby]
# I don't know why I can't use parameter substitution for the order by
# part. I've made sure to ONLY accept email, name, or date as options
# which should be secure. Hopefully.
q = "%%%s%%" % query
c.execute('select email, name, date from addresses where name like ? or '
'email like ? order by ' + s, (q,q))
sqlchildren = c.fetchall()
c.close()
results = []
for s in sqlchildren:
tmp = dt.datetime.strptime(s[-1], sqldateformat)
tmp = tmp.strftime(displaydateformat)
# tmp += ' [sent]'
result = (s[0], s[1], tmp)
results.append(result)
self.results = results
# stick our results into data too, since SQL object doesn't have any
# thing stored there until we do a search.
self.data = results
def writeSent(self, data):
"""Write sent addresses to the SQL db."""
cfg = self.cfg
try:
sql = self.sql
c = self.c
except:
self.createTables()
sql = self.sql
c = self.c
for d in data:
c.execute('insert or replace into addresses values (?, ?, ?)', d)
sql.commit()
c.close()
def datePruneSent(self, query):
"""Remove addresses from sent SQL db prior to date.
Date should be in YYYY-MM-DD format."""
try:
sql = self.sql
c = self.c
except:
print("no sent sql db")
return
q = "%s" % query
c.execute('delete from addresses where datetime(date) < ?', (q,))
sql.commit()
c.close()
def removeSent(self, rowids):
"""Delete addresses from the SQL db.
Addresses to be deleted are specified by rowid."""
try:
sql = self.sql
c = self.c
except:
print("no sent sql db")
return
for q in rowids:
c.execute('delete from addresses where rowid = ?', (q,))
sql.commit()
c.close()
class extCommandData(dataSource):
def __init__(self, cfg, helper, datatype = 'extCommand',
getData = True):
self.helper = helper
super(extCommandData, self).__init__(cfg, getData = getData)
def getData(self):
c = self.cfg
h = self.helper
cmd = c.get(h, 'cmd')
try:
helperText = c.get(h, 'text')
except:
helperText = h
# indices of returned output to keep
try:
indices = c.get(h, 'cols')
# split the input and make it into a tuple of ints
indices = tuple([int(i) for i in indices.split(',')])
except:
indices = (0,1)
try:
ignoreFirst = c.getboolean(h, 'ignore_first')
# split the input and make it into a tuple of ints
except:
ignoreFirst = False
self.ignoreFirst = ignoreFirst
self.indices = indices
cmd = os.path.expanduser(cmd)
self.queryCmd = cmd
self.helperText = helperText
def searchData(self, query):
"""Search with an external command.
Depends on an the external program that returns data in the proper
format. The command is set up in the config file. The proper format
for returned data is the same as the mutt query command expects except
with out the header line."""
cmd = self.queryCmd
cmd = '%s %s' % (cmd, query)
c = shlex.split(cmd)
try:
compproc = sp.run(c , stdout = sp.PIPE, stderr = sp.PIPE)
except:
self.results = []
# if compproc.returncode > 0:
# print('{} error - {}'.format(self.helper, compproc.returncode),
# file=sys.stderr)
# print(compproc)
stdout = compproc.stdout.decode('utf-8')
if compproc.returncode == 0 and len(stdout) > 0:
helperText = '\t%s' % self.helperText
helperText = self.helperText
# split by line
# results = stdout.rstrip().split('\n')
results = stdout.split('\n')
if self.ignoreFirst:
results = results[1:]
# split lines by tabs, removing any blank lines
self.results = [list(r.split('\t')) for r in results if r != '']
self.processResults()
# fill in blanks
self.results = [['-' if i == '' else i for i in r] for r in self.results]
self.results = [tuple(r + [helperText,]) for r in self.results]
else:
self.results = []
def processResults(self):
"""Process returned results.
Simple method to process the results returned from the command. This
can be replaced in a subclass if needed. The default method just calls
specific columns of the returned data."""
# self.results = [r[:2] for r in self.results]
self.results = [[r[i] for i in self.indices] for r in self.results]
def configDefaults():
"""Sets up config file defaults.
These are used if a particular parameter can't be found in the config file,
or if the config file doesn't exist."""
parser = ConfigParser()
parser.add_section('global')
parser.set('global', 'helpers', 'mutt_alias, sent')
parser.add_section('alias')
parser.set('alias', 'files', '~/.mutt/aliases')
parser.add_section('sent')
parser.set('sent', 'format', 'sql')
parser.set('sent', 'sortby', 'date')
parser.set('sent', 'sqlfile', '~/.muttqt/sent.sqlite3')
parser.set('sent', 'txtfile', '~/.muttqt/sent.txt')
parser.set('sent', 'date-format', '%%Y-%%m-%%d')
parser.add_section('osx_abook')
parser.set('osx_abook', 'cmd', 'contacts -m')
parser.set('osx_abook', 'text', 'Address Book')
parser.set('osx_abook', 'cols', '0,1')
parser.set('osx_abook', 'ignore_first', 'True')
parser.add_section('goobook')
parser.set('goobook', 'cmd', 'goobook query')
parser.set('goobook', 'text', 'Google')
parser.set('goobook', 'cols', '0,1')
parser.set('goobook', 'ignore_first', 'True')
parser.add_section('mu')
parser.set('mu', 'cmd', 'mu cfind -o mutt-ab')
parser.set('mu', 'text', 'mu')
parser.set('mu', 'cols', '0,1')
parser.set('mu', 'ignore_first', 'on')
return parser
def configWrite(parser):
"""Writes out a default config file."""
# write out a default config file if one doesn't exist already
print("attempting to make default config file at {}".format(configfile))
if not os.path.exists(os.path.dirname(configfile)):
try:
print("making directory")
os.makedirs(os.path.dirname(configfile))
except:
print("failed making directory")
sys.exit(10)
if not os.path.exists(configfile):
try:
print("writing file")
o = open(configfile, 'w')
parser.write(o)
o.close()
except:
print("failed writing file")
sys.exit(10)
else:
print("config file already exists")
def configRead():
"""Reads the config file.
Also fetches the configuration defaults."""
parser = configDefaults()
# parser.read(os.path.expanduser(configfile))
try:
parser.read(os.path.expanduser(configfile))
except:
e = sys.exc_info()[0]
print("problem reading config file")
print("Error: {}".format(e))
sys.exit(10)
return parser
def ingestEmail(lines):
"""Scrape email addresses from sent mails.
Looks in the To:, CC:, and BCC: headers."""
msg = email.message_from_string(lines)
now = dt.datetime.now()
t = now.strftime(sqldateformat)
toAddr = []
for header in ['to', 'cc', 'bcc']:
# if msg.has_key(header):
if header in msg:
toAddr.extend(msg.get_all(header, []))
out = []
for a in toAddr:
out.append(a)
toAddr = out
toAddr = email.utils.getaddresses(toAddr)
data = []
for i,a in enumerate(toAddr):
if a[0] == '':
tmpName = a[1].split('@')[0]
b = (a[1].lower(), tmpName, t)
else:
b = (a[1].lower(), a[0], t)
data.append(b)
return data
def ingestLBDB(fn, enc = 'utf-8'):
"""Imports sent mail history from LBDB."""
try:
fn = os.path.expanduser(fn)
import codecs
fin = codecs.open(fn, 'r', enc)
lines = fin.readlines()
fin.close()
except:
print("problem opening file {}".format(fn))
sys.exit(13)
data = []
for line in lines:
# print line.rstrip().split('\t')
a, n, t = line.rstrip().split('\t')
t = dt.datetime.strptime(t, lbdbdateformat)
data.append((a.lower(), n, t.strftime(sqldateformat)))
return data
def dumpFile(data, fn):
"""Dump the slq file to an LBDB compatible text file."""
fn = os.path.expanduser(fn)
lines = []
for d in data:
t = dt.datetime.strptime(d[3], sqldateformat)
tmp = (d[1], d[2], t.strftime(lbdbdateformat))
line = '\t'.join(tmp) + '\n'
lines.append(line)
if os.path.exists(fn):
print("output file {} already exists".format(fn))
sys.exit(13)
try:
import codecs
f = codecs.open(fn, 'w', 'utf-8')
f.writelines(lines)
f.close()
except:
print("problem writing file {}".format(fn))
sys.exit(13)
def searchDat(data, query):
"""Search list data for query."""
results = []
query = query.lower()
for l in data:
if l[0].lower().find(query) > -1 or l[1].lower().find(query) > -1:
results.append(l)
return results
def printResults(results, numbered = False):
"""Print search results."""
i = len(results)
print("{} matches:".format(i))
if numbered:
fstr = "{}\t{}\t{}\t{}"
else:
fstr = "{}\t{}\t{}"
for i,s in enumerate(results):
# out = "{} {} {}".format(*s)
out = fstr.format(*s)
print(out)
# print uout.encode('ascii', 'ignore')
def main(argv=None):
"""Main function."""
if argv is None:
argv = sys.argv
programName = os.path.basename(argv[0])
parser = argparse.ArgumentParser(
description = 'Scrape email addresses from emails.')
parser.add_argument('-V', '--version',
action = "version",
version = "%(prog)s " + "{0} ({1})".format(__version__, __commit__),
help = 'prints version')
parser.add_argument( '-c', '--config',
dest = 'config_file',
nargs = 1,
default = ['~/.muttqt/muttqt.conf'],
help = 'set custom config file')
parser.add_argument('-f', '--fetch',
dest = 'fetch',
metavar = 'FETCH_FILE',
# type = file,
type = open,
const = sys.stdin,
nargs = '?',
help = ('fetch addressees from a file. If no file is given, stdin is '
'used.'))
parser.add_argument( '-q', '--query',
dest = 'query',
nargs = 1,
default = False,
help = 'query the database')
parser.add_argument( '-s', '--sort',
dest = 'sortby',
nargs = 1,
default = None,
help = ("set the sort order of sent address results. valid choices "
"are 'email', 'date', or 'name'"))
parser.add_argument('-i', '--import',
dest = 'import_file',
default = False,
help = 'import addresses from an LBDB m_inmail file')
parser.add_argument('-d', '--dump',
dest = 'dump_file',
default = False,
help = 'dump sent addresses to an LBDB compatible file')
parser.add_argument('--print-sent',
dest = 'print_sent',
action = 'store_true',
help = 'print sent history with sql rowids')
parser.add_argument('--remove-sent',
dest = 'remove_sent',
metavar = 'ROWID',
action = 'store',
nargs = '*',
default = False,
help = 'remove entries by rowid from the sent history')
parser.add_argument('--date-prune',
dest = 'date_prune',
metavar = 'YYYY-MM-DD',
default = False,
help = 'prune all entries prior to YYYY-MM-DD')
parser.add_argument('--write-config',
dest = 'write_config',
action = 'store_true',
default = False,
help = 'write out a default config file to ~/.muttqt/muttqt.conf')
args = parser.parse_args()
# don't return a value for set config, other options could be appended as
# well
# Update global config file variable
global configfile
configfile = os.path.expanduser(args.config_file[0])
# get configuration data
cfg = configRead()
if not os.path.isfile(configfile):
print("Config file not found: {}".format(configfile))
if args.write_config:
configWrite(cfg)
return 0
else:
print("""If you would like to create a config file here, rerun as:
muttqt --write-config -c {}""".format(configfile))
sys.exit(1)
sentFileFormat = cfg.get('sent', 'format')
if sentFileFormat == 'sql':
sentSource = sentSQLData(cfg)
# getAllSent = getAllSentSQL
# datePruneSent = datePruneSentSQL
# removeSent = removeSentSQL
# writeSent = writeSentSQL
# searchSent = searchSentSQL
elif sentFileFormat == 'text':
sentSource = sentTxtData(cfg)
# getAllSent = getAllSentTxt
# datePruneSent = datePruneSentTxt
# removeSent = removeSentTxt
# writeSent = writeSentTxt
# searchSent = searchSentTxt
if args.print_sent:
sentSource.getAllSent()
sentSource.printResults(numbered = True)
return 0
if args.date_prune:
results = sentSource.datePruneSent(args.date_prune)
return 0
if args.remove_sent:
results = sentSource.removeSent(args.remove_sent)
return 0
if args.dump_file:
sentSource.getAllSent()
dumpFile(sentSource.results, args.dump_file)
return 0
# don't return a value for either import_file or fetch - these modify the
# data bbase and we will just write out the database after both of them.
if args.import_file:
# data = ingestLBDB(args.import_file, 'latin-1')
data = ingestLBDB(args.import_file)
if args.fetch:
# read our lines from stdin or the file passed
lines = ''.join(args.fetch.readlines())
data = ingestEmail(lines)
if args.fetch or args.import_file:
sentSource.writeSent(data)
return 0
if args.query:
helpers = cfg.get('global', 'helpers').split(',')
helpers = [h.strip() for h in helpers]
# helpers = ['mutt_alias', 'osx_abook', 'sent']
results = []
query = args.query[0]
for helper in helpers:
data = []
if helper == 'mutt_alias':
aliasDat = aliasData(cfg)
aliasDat.searchData(query)
data = aliasDat.results
# data.insert(0,( 'alias','---','---' ))
elif helper in ['osx_abook','goobook',]:
extSource = extCommandData(cfg, helper)
extSource.searchData(query)
data = extSource.results
# data.insert(0,( 'osx','---','---' ))
# data = searchExtCommand(cfg, helper, query)
elif helper == 'sent':
sortby = cfg.get('sent', 'sortby')
if args.sortby:
sortby = args.sortby[0]
sentSource.searchData(query, sortby)
data = sentSource.results
# data.insert(0,( 'sent','---','---' ))
else:
# this is potentially risky, but we'll try to parse any other
# helpers in the config file as external commands
try:
extSource = extCommandData(cfg, helper)
extSource.searchData(query)
data = extSource.results
except:
pass
results.extend(data)
printResults(results)
return 0
if __name__ == "__main__":
sys.exit(main())