hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Need quick script to format emails
Reply

Forum Jump

Need quick script to format emails

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 08-26-2009, 07:35 PM
amex amex is offline
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



Sponsored Links
  #2  
Old 08-26-2009, 08:46 PM
mattle mattle is offline
Web Hosting Master
 
Join Date: May 2009
Posts: 766
Kind souls need to eat

  #3  
Old 08-26-2009, 08:47 PM
amex amex is offline
Community Guide
 
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
Quote:
Originally Posted by mattle View Post
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

Sponsored Links
  #4  
Old 08-27-2009, 01:01 AM
mwatkins mwatkins is offline
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.”

  #5  
Old 08-27-2009, 01:13 PM
amex amex is offline
Community Guide
 
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
Quote:
Originally Posted by mwatkins View Post
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

  #6  
Old 08-27-2009, 01:46 PM
mwatkins mwatkins is offline
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.”

  #7  
Old 08-27-2009, 05:59 PM
amex amex is offline
Community Guide
 
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
Quote:
Originally Posted by mwatkins View Post
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

Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script that creates emails on the server celio Hosting Software and Control Panels 1 05-23-2006 04:28 AM
problems sending emails with php script man_mm Web Design and Content 7 03-22-2006 05:11 PM
script needed to send other people's emails akr44 Programming Discussion 4 07-26-2003 02:43 AM
monitoring script that emails if diskspace reaches 99%? universal2001 Web Hosting 1 01-28-2003 02:20 PM

Related posts from TheWhir.com
Title Type Date Posted
Service Providers Push Updates to Fight OpenSSL Heartbleed Bug Web Hosting News 2014-04-08 16:58:05
Web Hosting Sales and Promos Roundup - December 6, 2013 Web Hosting News 2013-12-06 15:09:54
OpenStack and the AWS API Debate Web Hosting News 2013-07-30 14:21:54
Rackspace Integrates Mailgun into Cloud Control Panel Web Hosting News 2013-05-23 14:55:51
eleven Report for June Sees 927.4 Percent Rise in Virus-Infected Emails Web Hosting News 2012-06-07 15:33:50


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?