http://aspn.activestate.com/ASPN/Cookboo…n/Recipe/138889
und etwas angepasst:
|
Quellcode
|
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
|
import sys
import re
def grab_email(file):
found = []
if file != None:
mailsrch = re.compile(r'[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}')
for line in open(file, 'r'):
found.extend(mailsrch.findall(line))
# remove duplicate elements
# borrowed from Tim Peters' algorithm on ASPN Cookbook
u = {}
for item in found:
u[item] = 1
# return list of unique email addresses
return u.keys()
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'usage: %s <file with email addresses>' % sys.argv[0]
sys.exit()
for addr in grab_email(sys.argv[1]):
print addr
|
dazu noch eine dist-setup.py:
|
Quellcode
|
1
2
3
4
|
from distutils.core import setup
import py2exe
setup(console=["mailgrabber.py"])
|
und ein
|
Quellcode
|
1
|
python dist-setup.py py2exe
|
und schon hat man ne windows-binary (natürlich ist dann nur noch der ursprüngliche source plattform-unabhängig).
den output (je eine adresse pro zeile) kann man dann mit > in eine datei umlenken oder noch an diverse sortierer oder z.b. tee weiterleiten.
edit: na das mit der einrückung muss man sich halt denken oder kopieren...