
08-26-2009, 07:35 PM
|
|
Community Guide
|
|
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
|
|
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
__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree
|

08-26-2009, 08:46 PM
|
|
Web Hosting Master
|
|
Join Date: May 2009
Posts: 766
|
|
Kind souls need to eat 
|

08-26-2009, 08:47 PM
|
|
Community Guide
|
|
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
|
|
Quote:
Originally Posted by mattle
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.
__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree
|

08-27-2009, 01:01 AM
|
|
Web Hosting Master
|
|
Join Date: Nov 2001
Location: Vancouver
Posts: 2,416
|
|
I've already had dinner, so here you go:
PHP Code:
#!/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:
Code:
$ more your_input_file.txt
foo@bar.com
narfy@bat.ca
shoo@foot.org
garbanzo@bean.com
And turns it into:
Code:
$ more emails.txt
'foo@bar.com','narfy@bat.ca','shoo@foot.org','garbanzo@bean.com'
Or the following if you want it sorted:
Code:
$ more emails.txt
'foo@bar.com','garbanzo@bean.com','narfy@bat.ca','shoo@foot.org'
__________________
“Even those who arrange and design shrubberies are under
considerable economic stress at this period in history.”
|

08-27-2009, 01:13 PM
|
|
Community Guide
|
|
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
|
|
Quote:
Originally Posted by mwatkins
I've already had dinner, so here you go:
PHP Code:
#!/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:
Code:
$ more your_input_file.txt
foo@bar.com
narfy@bat.ca
shoo@foot.org
garbanzo@bean.com
And turns it into:
Code:
$ more emails.txt
'foo@bar.com','narfy@bat.ca','shoo@foot.org','garbanzo@bean.com'
Or the following if you want it sorted:
Code:
$ 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:
Code:
./index.sh: line 2: syntax error near unexpected token `('
./index.sh: line 2: `emails = ["'%s'" % email.strip() for email in'
__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree
|

08-27-2009, 01:46 PM
|
|
Web Hosting Master
|
|
Join Date: Nov 2001
Location: Vancouver
Posts: 2,416
|
|
It should run as is:
Code:
$ 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.
__________________
“Even those who arrange and design shrubberies are under
considerable economic stress at this period in history.”
|

08-27-2009, 05:59 PM
|
|
Community Guide
|
|
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
|
|
Quote:
Originally Posted by mwatkins
It should run as is:
Code:
$ 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.
__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|