
|
View Full Version : Need quick script to format emails
Have to import emails to a certain program in a specific format and would save me hours if a kind soul could whip up a script to do this:
A) A text box where I can paste in emails, one email per line.
B) Click submit.
C) In the box below, it spits out (in one continuous line) all the emails, however they should be separated by the following format:
'email1@aol.com', 'email2@test.com', 'yada@yada.com', and so on and so forth.
Thanks
mattle 08-26-2009, 08:46 PM Kind souls need to eat :)
Kind souls need to eat :)
I would donate to the cause but I don't believe that such an arrangement is so great per WHT rules.
mwatkins 08-27-2009, 01:01 AM I've already had dinner, so here you go:
#!/usr/bin/env python
emails = ["'%s'" % email.strip() for email in
open('your_input_file.txt', 'r').readlines()]
open('emails.txt', 'w').write(",".join(emails))
# want them sorted?
# open('emails.txt', 'w').write(",".join(sorted(emails)))
The forgoing assumes this requirement of yours is a one off thing - i.e., doesn't have to be a text box for web based clients, but instead data could be within a text file you supply.
The two line "script" takes a file containing:
$ more your_input_file.txt
foo@bar.com
narfy@bat.ca
shoo@foot.org
garbanzo@bean.com
And turns it into:
$ more emails.txt
'foo@bar.com','narfy@bat.ca','shoo@foot.org','garbanzo@bean.com'
Or the following if you want it sorted:
$ more emails.txt
'foo@bar.com','garbanzo@bean.com','narfy@bat.ca','shoo@foot.org'
I've already had dinner, so here you go:
#!/usr/bin/env python
emails = ["'%s'" % email.strip() for email in
open('your_input_file.txt', 'r').readlines()]
open('emails.txt', 'w').write(",".join(emails))
# want them sorted?
# open('emails.txt', 'w').write(",".join(sorted(emails)))The forgoing assumes this requirement of yours is a one off thing - i.e., doesn't have to be a text box for web based clients, but instead data could be within a text file you supply.
The two line "script" takes a file containing:
$ more your_input_file.txt
foo@bar.com
narfy@bat.ca
shoo@foot.org
garbanzo@bean.comAnd turns it into:
$ more emails.txt
'foo@bar.com','narfy@bat.ca','shoo@foot.org','garbanzo@bean.com'Or the following if you want it sorted:
$ more emails.txt
'foo@bar.com','garbanzo@bean.com','narfy@bat.ca','shoo@foot.org'
Thanks so much for your effort. Crazy Q: Should the script be a .sh?
I am getting the following error:
./index.sh: line 2: syntax error near unexpected token `('
./index.sh: line 2: `emails = ["'%s'" % email.strip() for email in'
mwatkins 08-27-2009, 01:46 PM It should run as is:
$ more v2h_emails.py
#!/usr/bin/env python
emails = ["'%s'" % email.strip() for email in
open('your_input_file.txt', 'r').readlines()]
open('emails.txt', 'w').write(",".join(emails))
# want them sorted?
# open('emails.txt', 'w').write(",".join(sorted(emails)))
$ chmod +x v2h_emails.py
$ ./v2h_emails.py
$ more emails.txt
'foo@bar.com','narfy@bat.ca','shoo@foot.org','garbanzo@bean.com'
Or run it:
python v2h_emails.py
If you still get the syntax errors, either the script is being interpreted as a shell script (it isn't) or your Python is really ancient.
$ python --version
Python 2.6.2
Any relatively recent version of Python (2.5 and greater) ought to do.
It should run as is:
$ more v2h_emails.py
#!/usr/bin/env python
emails = ["'%s'" % email.strip() for email in
open('your_input_file.txt', 'r').readlines()]
open('emails.txt', 'w').write(",".join(emails))
# want them sorted?
# open('emails.txt', 'w').write(",".join(sorted(emails)))
$ chmod +x v2h_emails.py
$ ./v2h_emails.py
$ more emails.txt
'foo@bar.com','narfy@bat.ca','shoo@foot.org','garbanzo@bean.com'Or run it:
python v2h_emails.py
If you still get the syntax errors, either the script is being interpreted as a shell script (it isn't) or your Python is really ancient.
$ python --version
Python 2.6.2
Any relatively recent version of Python (2.5 and greater) ought to do.
Thanks so much! Worked like a charm.
|