scanning through page and replacing all instances of 00:00:00.00
I have a python-cgi file that pulls data from an sql database, i am wondering what is the easiest way to remove all instances of '00:00:00.00' in my date column. how would i write a python script to scan the entire page and delete all instances of '00:00:00.00', would i use regular expressions? -- http://mail.python.org/mailman/listinfo/python-list
Re: scanning through page and replacing all instances of 00:00:00.00
Fredrik Lundh wrote: > "Kun" wrote: > >> I have a python-cgi file that pulls data from an sql database, i am >> wondering what is the easiest way to remove all instances of >> '00:00:00.00' in my date column. >> >> how would i write a python script to scan the entire page and delete all >> instances of '00:00:00.00', would i use regular expressions? > > umm. if you're using a database, why not filter out uninteresting dates > either > in the SQL statement, or when you're building the page ? > > > > > because in my sql database, the date is only 'date' (as in -mm-dd), only when i extract it with my python-cgi does the date turn into (-mm-dd 00:00:00.00), thus i figured the best way to fix this problem is to parse it after the matter. side note: the 'date' column is not formatted as datetime in the mysql database. -- http://mail.python.org/mailman/listinfo/python-list
Re: scanning through page and replacing all instances of 00:00:00.00
Fredrik Lundh wrote: > "Kun" wrote: > >> because in my sql database, the date is only 'date' (as in -mm-dd), >> only when i extract it with my python-cgi does the date turn into >> (-mm-dd 00:00:00.00), thus i figured the best way to fix this >> problem is to parse it after the matter. > > you still make no sense. why not fix this in your python cgi script ? > > > > > i have the following python-cgi which extracts data from a mysql table, how do i parse the date so that it doesn't display the time '00:00:00.00'? print 'Query Results' try: db = MySQLdb.connect(host="localhost", user="xxx", passwd="", db="") cursor = db.cursor() sqlstring = (select + " FROM dir" + where + order_by + limit) print sqlstring cursor.execute(sqlstring) numrows = cursor.rowcount numcols = len(cursor.description) #print sqlstring #print "SQL statement used:" + sqlstring print """""" print "" for col in range(0, numcols): print "", cursor.description[col][0], "" print "" for row in range(0,numrows): record = cursor.fetchone() print "" for col in range(0, numcols): print "", record[col], "" print "" except MySQLdb.OperationalError, message: print "Error %d:%s" % (message[0], message[1]) print "SQL statement used:" + sqlstring print "" -- http://mail.python.org/mailman/listinfo/python-list
Re: scanning through page and replacing all instances of 00:00:00.00
[EMAIL PROTECTED] wrote: > Kun> i have the following python-cgi which extracts data from a mysql > Kun> table, how do i parse the date so that it doesn't display the time > Kun> '00:00:00.00'? > > I have no idea which column in your table is a datetime object, but just > convert it to a date. For example: > > >>> import datetime > >>> dt = datetime.datetime.now() > >>> print dt > 2006-04-17 18:19:38.698925 > >>> print dt.date() > 2006-04-17 > > Skip assuming that my date column is 2, how would i parse out the date? the example you gave is of you parsing out the current time, but how do you parse out a pre-specified time that is extracted via sql? i don't think something like dt.date() works because it doesn't work with a string? correct me if i'm wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: scanning through page and replacing all instances of 00:00:00.00
Tim Chase wrote: >> for col in range(0, numcols): >> print "", record[col], "" > > This is the point at which you want to intercept the column data and > make your change: > > print "", str(record[col]).replace("00:00:00.0", ""), " > If it's possible/plausible that other fields might have such a value > reasonably, then you'd want to do a check, something like > > > THEDATECOL = 42 > for col in range(0, numcols): > foo = record[col] > if col == THEDATECOL: > foo = foo.replace("00:00:00.00", "") > print "%s" % foo > > or alternatively > > DATECOLUMNS = [3, 14] > for col in range(0, numcols): > foo = record[col] > if col in DATECOLUMNS: > foo = foo.replace("00:00:00.00", "") > print "%s" % foo > > I don't know off the top of my head if your MySQL cursor object supports > metadata...something like the following pseudocode: > > for col in range(0, numcols): > foo = record[col] > if cursor.fieldtypes[col] == MYSQL_DATE: > foo = foo.replace("00:00:00.00", "") > print "%s" % foo > > Adjust accordingly. > > -tkc > much thanks! > > > > mu -- http://mail.python.org/mailman/listinfo/python-list
scanning for numerals / letters
I have the following if statement that checks if a form is empty: if form.has_key("date") and form["date"].value != "": date=form['date'].value else: print "ERROR: No date entered!" raise Exception I would also like to add another if statement checking if 'date' has any letters (a-z) in it, and if so, would like to say that "you have to enter a date with numbers". I am not sure how to alter my current if statement to do that check so any assistance would be appreciated. On the flip side, I also have a field called 'purchases' where the user must enter non-numerals, thus i would also like to know how to scan to see if their entry has numerals and print 'please do not use numbers' if they did. Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
removing cgi fieldstorage keys
i don't know what happened but all of a sudden, my cgi.fieldstorage has two extra keys, 'x' and 'y', does anyone know how i can remove them in python? -- http://mail.python.org/mailman/listinfo/python-list
imap folder scanner
Hey guys, I would like to have a code in python (as simple as possible) to scan a specific folder in my mailbox and if the subject is equal to, say, 'BIKES', I would like to have the code automatically send the SENDER an email saying something like "We have received your Email". Furthermore, I would also like to somehow save the sender's email into a list which would be compiled by another python program into an html file that would show a list of email addresses whose subject matched 'BIKE' I know i am asking for a lot but since i am new to python, can someone help me out with this? Whether its tips or code, i'll be very excited to hear your answer. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: UPDATE imap folder scanner
Okay So I got the 'search' part to work, which outputs me a long list of message numbers. how do i use that list of message numbers to fetch the 'from' address for each one and send them a confirmation email? is this some sort for loop? any help would be greatly appreciated. cheers. Kun wrote: > Hey guys, I would like to have a code in python (as simple as possible) > to scan a specific folder in my mailbox and if the subject is equal to, > say, 'BIKES', I would like to have the code automatically send the > SENDER an email saying something like "We have received your Email". > Furthermore, I would also like to somehow save the sender's email into a > list which would be compiled by another python program into an html file > that would show a list of email addresses whose subject matched 'BIKE' > > I know i am asking for a lot but since i am new to python, can someone > help me out with this? Whether its tips or code, i'll be very excited to > hear your answer. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: imap folder scanner
Sebastjan Trepca wrote: > A very simple example... > > import imaplib > m = imap.IMAP4() > m.login(username,password) > m.select('myfolder') > status, data = m.search(None,'(SUBJECT "BIKES")') > assert status=='OK', "Error. Message: %s"%data > data = data[0] #you get your results in a list and search returns only > one result > assert data,"No results" > #cool, we have results, but IMAP's search command only returns IDs so > we have to fetch > #msgs now > status,senders = m.fetch(data.replace(' > ',','),'(BODY.PEEK[HEADER.FIELDS (FROM)])') > assert status=='OK', "Error. Message: %s"%data > > Now you just have to parse the "senders" data. There are many examples > about sending emails with python, like this one: > > def send_notice(): > import smtplib > msg = 'we got your mail, indeed' > from email.MIMEText import MIMEText > mail = MIMEText(msg, 'plain', 'utf-8') > mail['From'] =fro='[EMAIL PROTECTED]' > mail['Subject'] = "Spam machine" > mail['To'] = to = '[EMAIL PROTECTED]' > server = smtplib.SMTP('localhost') > errors = server.sendmail(fro, to, mail.as_string()) > server.quit() > > That other program should be very simple to make now. > > Sebastjan > > On 3/24/06, Kun <[EMAIL PROTECTED]> wrote: >> Hey guys, I would like to have a code in python (as simple as possible) >> to scan a specific folder in my mailbox and if the subject is equal to, >> say, 'BIKES', I would like to have the code automatically send the >> SENDER an email saying something like "We have received your Email". >> Furthermore, I would also like to somehow save the sender's email into a >> list which would be compiled by another python program into an html file >> that would show a list of email addresses whose subject matched 'BIKE' >> >> I know i am asking for a lot but since i am new to python, can someone >> help me out with this? Whether its tips or code, i'll be very excited to >> hear your answer. Thanks. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> Thank you very much for your help. I am trying to use your code and currently it works up to the 'fetch', where I am getting the following error: error: FETCH command error: BAD ['Protocol Error: "Specified message set is invalid".'] I guess I do not understand why you have data.replace('',',') and what ",',' means. Thanks so much. Kun -- http://mail.python.org/mailman/listinfo/python-list
Re: imap folder scanner
Marco Carvalho wrote: > On 3/24/06, Sebastjan Trepca <[EMAIL PROTECTED]> wrote: > >> m.select('myfolder') > > Some attention is required here to retrieve subfolders. > Some imap servers like Cyrus and Courier uses "INBOX.subfolder" to > access subfolders. > -- > Marco Carvalho (macs) | marcoacarvalho(a)gmail.com > http://arrakis.no-ip.info | http://cdd.debian-br.org > Maceio - Alagoas - Brazil > Debian GNU/Linux unstable (Sid) > GNU-PG ID:08D82127 - Linux Registered User #141545 > Notícias Semanais do Debian em Português: http://www.debian.org/News/weekly > Alertas de Segurança Debian (DSA): http://www.debian.org/security so i have used the following code and have successfully saved a list of senders as a string. however, the string has much more information than just the email address and i am wondering what is the best way to parse the email address out of the entire string. sample string: >>> print status, senders OK [('460 (BODY[HEADER.FIELDS (FROM)] {46}', 'From: Friend <[EMAIL PROTECTED]>\r\n\r\n'), ')', ('462 (BODY[HEADER.FIELDS (FROM)] {37}', 'From: Kun <[EMAIL PROTECTED]>\r\n\r\n'), ')'] how do i just get the two email addresses out of there? my code is: from imaplib import * import getpass m = IMAP4("") m.login('xx', 'xxx') m.select('Inbox') status, data = m.search(None,'(SUBJECT "BIKES")') assert status=='OK', "Error. Message: %s"%data data = data[0] #you get your results in a list and search returns only one result assert data,"No results" #cool, we have results, but IMAP's search command only returns IDs so we have to fetch #msgs now status,senders = m.fetch(data.replace(' ',','),'(BODY.PEEK[HEADER.FIELDS (FROM)])') assert status=='OK', "Error. Message: %s"%data print senders -- http://mail.python.org/mailman/listinfo/python-list
newbie parsing question
i have a list of that is: [('460 (BODY[HEADER.FIELDS (FROM)] {46}', 'From: Friend <[EMAIL PROTECTED]>\r\n\r\n'), ')', ('462 (BODY[HEADER.FIELDS (FROM)] {37}', 'From: Kun <[EMAIL PROTECTED]>\r\n\r\n'), ')'] how do i parse the email addresses out of it into another list or string? -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie parsing question
[EMAIL PROTECTED] wrote: > Use Regular expressions > http://docs.python.org/lib/module-re.html > i tried to parse (below) with the regular expression: emails = re.findall('\S*\s([EMAIL PROTECTED])', senders) and got the following error: Traceback (most recent call last): File "/Life/School/Homework/Spring 2006/OPIM 399/Tutorial/IMAP/scannermailer.py", line 19, in -toplevel- emails = re.findall('\S*\s([EMAIL PROTECTED])', senders) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/sre.py", line 167, in findall return _compile(pattern, flags).findall(string) TypeError: expected string or buffer any help would be appreciated. [('460 (BODY[HEADER.FIELDS (FROM)] {46}', 'From: Kevin Feng <[EMAIL PROTECTED]>\r\n\r\n'), ')', ('461 (BODY[HEADER.FIELDS (FROM)] {37}', 'From: Kevin <[EMAIL PROTECTED]>\r\n\r\n'), ')'] -- http://mail.python.org/mailman/listinfo/python-list
send email to string of emails
the code below outputs a string of emails (e.g. ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]'] i would like to somehow send an email to everyone on the string of emails telling them 'thanks for emailing me' anyone know how to do this? much thanks ahead of time. from imaplib import * import getpass, re m = IMAP4("xx") m.login('x', 'xx') m.select('Inbox') status, data = m.search(None,'(SUBJECT "BIKES")') assert status=='OK', "Error. Message: %s"%data data = data[0] #you get your results in a list and search returns only one result assert data,"No results" #cool, we have results, but IMAP's search command only returns IDs so we have to fetch #msgs now status,senders = m.fetch(data.replace(' ',','),'(BODY.PEEK[HEADER.FIELDS (FROM)])') assert status=='OK', "Error. Message: %s"%data ''.join([''.join(t) for t in senders]) senderlist =''.join([''.join(t) for t in senders]) emails = re.findall('([EMAIL PROTECTED])', senderlist) print emails -- http://mail.python.org/mailman/listinfo/python-list
simple string search and replace
hey guys, here's my code, senders = [('460 (BODY[HEADER.FIELDS (FROM)] {46}', 'From: Friend <[EMAIL PROTECTED]>\r\n\r\n'), ')', ('462 (BODY[HEADER.FIELDS (FROM)] {37}', 'From: Kun <[EMAIL PROTECTED]>\r\n\r\n'), ')'] print senders parsed_senders = [] sender = "" for item in senders: if isinstance(item,tuple): item= ''.join(item) if item==')': parsed_senders.append(sender[sender.find('<')+1:].strip()) sender = "" else: sender+=item print parsed_senders wondering if anyone knows how i can remove the '>'s from the list, which outputs to something like ['[EMAIL PROTECTED]>', '[EMAIL PROTECTED]>'] -- http://mail.python.org/mailman/listinfo/python-list
using regex to pull out email addresses
i have a regular expression that searches a string and plucks out email addresses however it doesn't work for email addresses w/a subdomain e.g. [EMAIL PROTECTED] emails = re.findall('([EMAIL PROTECTED])', senderlist) <-- my code is there any way to modify that to include email addresses that also have subdomains? -- http://mail.python.org/mailman/listinfo/python-list
sending emails to a list of recipients
i have the following code: -- import smtplib from email.MIMEText import MIMEText fp = open('confirmation.txt', 'rb') msg = MIMEText(fp.read()) From = '[EMAIL PROTECTED]' msg['Subject'] = 'Purchase Confirmation' msg ['From'] = From msg['To'] = emails s = smtplib.SMTP('.xxx.xxx.edu') s.login('x','') s.sendmail(msg['From'], msg['To'], msg.as_string()) s.close() -- it works if msg['To'] = '[EMAIL PROTECTED]' however, i'm trying to attach a list of emails named 'emails' to msg['To'] emails is in the following format: ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]', '[EMAIL PROTECTED]'] anyone have an idea how i can modify this script to work with sending a list? note this is a snippet of a larger code, 'emails' is as a string defined earlier. -- http://mail.python.org/mailman/listinfo/python-list
Re: sending emails to a list of recipients [update]
Kun wrote: > i have the following code: > > -- > import smtplib > > from email.MIMEText import MIMEText > fp = open('confirmation.txt', 'rb') > msg = MIMEText(fp.read()) > > From = '[EMAIL PROTECTED]' > > msg['Subject'] = 'Purchase Confirmation' > msg ['From'] = From > msg['To'] = emails > > s = smtplib.SMTP('.xxx.xxx.edu') > s.login('x','') > s.sendmail(msg['From'], msg['To'], msg.as_string()) > s.close() > -- > > it works if msg['To'] = '[EMAIL PROTECTED]' > > however, i'm trying to attach a list of emails named 'emails' to msg['To'] > > emails is in the following format: ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]', > '[EMAIL PROTECTED]'] > > > anyone have an idea how i can modify this script to work with sending a > list? note this is a snippet of a larger code, 'emails' is as a string > defined earlier. this is my error msg of leaving the code in its current state... (brave yourself) Traceback (most recent call last): File "/Tutorial/IMAP/scannermailer.py", line 41, in -toplevel- s.sendmail(msg['From'], msg['To'], msg.as_string()) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Message.py", line 129, in as_string g.flatten(self, unixfrom=unixfrom) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Generator.py", line 82, in flatten self._write(msg) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Generator.py", line 120, in _write self._write_headers(msg) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Generator.py", line 166, in _write_headers header_name=h, continuation_ws='\t').encode() File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Header.py", line 395, in encode return self._encode_chunks(newchunks, maxlinelen) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Header.py", line 355, in _encode_chunks _max_append(chunks, s, maxlinelen, extra) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/quopriMIME.py", line 79, in _max_append L.append(s.lstrip()) AttributeError: 'list' object has no attribute 'lstrip' -- http://mail.python.org/mailman/listinfo/python-list
pulling data from html and putting it in mysql database
i have the following simple html that asks for a price: -- http://mail.python.org/mailman/listinfo/python-list
using regex to remove $ sign
i have an html/cgi input that takes in values to a mysql database, however, if i stick in $20 instead of 20, it crashes the program because of the extra $ sign. I was wondering if anyone has a quick regular expression in python to remove the $-sign if it is present in the input. -- http://mail.python.org/mailman/listinfo/python-list
modifying html input date for mysql, reg ex or string interpolation?
I have an html form that takes dates and inserts them into a mysql file. Currently, users have to type in dates in the -mm-dd format. As of now, this process works with the sql. However, I would like to make this process easier by: 1) providing drop down menus for year, month, and date respectively. in a failed attempt, i tried made 3 drop down lists (dateyear, datemonth, dateday) respectively and then used string interpolation to tie them together into a -mm-dd string called 'date'. I then tried to use this 'date' string in my original sql query and it no longer worked. Is this because the new 'date' value is a string instead of an int? How can I go about solving this problem and making the new 'date' string work with my old sql query? Attached is my code: #!/usr/bin/env python import cgi print "Content-type: text/html" print form = cgi.FieldStorage() print form.keys() #gets value for each input price = form["price"] price = price.value purchasetype = form["purchasetype"] purchasetype = purchasetype.value date = form["date"] date = date.value comment = form["comment"] comment = comment.value dateyear = form["dateyear"] dateyear = dateyear.value datemonth = form["datemonth"] datemonth = datemonth.value dateday = form["dateday"] dateday = dateday.value #string interpolation for date date = "%d-%d-%d" % (dateyear, datemonth, dateday) print "" for x in form.keys(): print "%s=%s" % (x, form[x].value) + "" # make connection to MySQL import MySQLdb import re import urllib import sys try: connection = MySQLdb.connect(host="localhost", user="", passwd="", db ="") except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) sys.exit (1) #take data and put it into table that you have created. cursor = connection.cursor() mysqlstatement = "" mysqlstatement = "INSERT INTO dir (date, purchasetype, price, comment) VALUES ('"+ date +"','"+ purchasetype +"','"+ price +"','"+ comment +"' )" print mysqlstatement cursor.execute (mysqlstatement) -- http://mail.python.org/mailman/listinfo/python-list
turning python-cgi into an html output
i have a python cgi script that displays tables from a mysql database in html. the problem is, i want to use excel's web query to pull this data and the web query doesn't read .py files. thus i am wondering what is the easiest way to just turn my .py html output into a .html output. you can check the query here: http://opimx.wharton.upenn.edu/~fengk/getfinances.html just click 'submit' any help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
multiple parameters in if statement
I am trying to make an if-statement that will not do anything and print 'nothing entered' if there is nothing entered in a form. I have the following code that does that, however, now even if I enter something into the form, the code still outputs 'nothing entered'. This violates the if statement and I am wondering what I did wrong. if form.has_key("delete_id") and form["delete_id"].value != "" and form.has_key("delete_date") and form["delete_date"].value != "" and form.has_key("delete_purchasetype") and form["delete_purchasetype"].value != "" and form.has_key("delete_price") and form["delete_price"].value != "" and form.has_key("delete_comment") and form["delete_comment"].value != "": delete_id=form['delete_id'].value delete_date=form['delete_date'].value delete_purchasetype=form['delete_purchasetype'].value delete_price=form['delete_price'].value delete_comment=form['delete_comment'].value else: print "ERROR: Nothing entered!" raise Exception -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple parameters in if statement...
[EMAIL PROTECTED] wrote: > Kun wrote: >> I am trying to make an if-statement that will not do anything and print >> 'nothing entered' if there is nothing entered in a form. I have the >> following code that does that, however, now even if I enter something > > Yes, but did you enter everything? > >> into the form, the code still outputs 'nothing entered'. > > The logic doesn't imply "nothing", it implies "not everything". > The else clause will execute if ANY item is not enetered. > >> This violates >> the if statement and I am wondering what I did wrong. >> >> if form.has_key("delete_id") and form["delete_id"].value != "" and >> form.has_key("delete_date") and form["delete_date"].value != "" and >> form.has_key("delete_purchasetype") and >> form["delete_purchasetype"].value != "" and form.has_key("delete_price") >> and form["delete_price"].value != "" and form.has_key("delete_comment") >> and form["delete_comment"].value != "": >> delete_id=form['delete_id'].value >> delete_date=form['delete_date'].value >> delete_purchasetype=form['delete_purchasetype'].value >> delete_price=form['delete_price'].value >> delete_comment=form['delete_comment'].value >> else: >> print "ERROR: Nothing entered!" >> raise Exception > How do I make this so that it only prints 'nothing entered' when none of the fields are entered? -- http://mail.python.org/mailman/listinfo/python-list
Sending part of a page as the body of an email
I currently have a python-cgi script that extracts data from a mysql table. I would like to save this data as a string and send it to a recipient via email. I know how to send email using the smtp lib, but what I do not know his how to save a portion of the page as a string. Any pointers? -- http://mail.python.org/mailman/listinfo/python-list
filling today's date in a form
i have a form which takes in inputs for a mysql query. one of the inputs is 'date'. normally, a user has to manually enter a date, but i am wondering if there is a way to create a button which would automatically insert today's date in the date form field if the user chooses to use today's date. -- http://mail.python.org/mailman/listinfo/python-list
Re: filling today's date in a form
Felipe Almeida Lessa wrote: > Em Dom, 2006-04-16 às 19:22 -0400, Kun escreveu: >> i have a form > > Which kind of form? Which toolkit? > >> which takes in inputs for a mysql query. one of the inputs >> is 'date'. normally, a user has to manually enter a date, > > Enter the date in which kind of control? > >> but i am >> wondering if there is a way to create a button which would automatically >> insert today's date in the date form field if the user chooses to use >> today's date. > > Almost 100% sure that there is, but I can't tell you if or how if you > don't tell us how you are doing what you are doing. > Form is an html form called by a python cgi file using fieldstorage. Date as in '2006-04-16'... is that what you meant by control? -- http://mail.python.org/mailman/listinfo/python-list
passing string from one file to another
I have a python-cgi form whose sole purpose is to email. It has the fields 'to', 'from', 'subject', 'body', etc. and if the user fills them out and clicks submit, it will invoke another file called mail.py which uses smtplib to send the message. This works fine but instead of typing in a 'body', i would like the initial python program to just send a string as the body of the email. now normally i'd just set the msg in the mail.py file equal to the string, however, i do not know how to link a string from another python file to the mail.py file. does anyone know a solution to this? -- http://mail.python.org/mailman/listinfo/python-list
Re: passing string from one file to another
Kun wrote: > I have a python-cgi form whose sole purpose is to email. > > It has the fields 'to', 'from', 'subject', 'body', etc. and if the user > fills them out and clicks submit, it will invoke another file called > mail.py which uses smtplib to send the message. > > This works fine but instead of typing in a 'body', i would like the > initial python program to just send a string as the body of the email. > now normally i'd just set the msg in the mail.py file equal to the > string, however, i do not know how to link a string from another python > file to the mail.py file. > > does anyone know a solution to this? i am aware that i could write the string to a text file and invoke it with the second python program, however, unfortunately i do not have write permission on the server i am working with, thus we need to find some other way... your help would be greatly appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: passing string from one file to another
I V wrote: > Kun wrote: >> This works fine but instead of typing in a 'body', i would like the >> initial python program to just send a string as the body of the email. >> now normally i'd just set the msg in the mail.py file equal to the >> string, however, i do not know how to link a string from another python >> file to the mail.py file. > > Where does mail.py get the body from at the moment? And how are you > invoking mail.py? The obvious would be to import mail.py and call a > function in it; then, you would just need to change the string you pass > to the function. But presumably that's not how you've got it set up or > you wouldn't be asking the question. If you can explain a bit more how > your program works that would be helpful, maybe post an exerpt of the > code that shows where mail.py gets invoked from the main program, and > the bit of mail.py that accesses the body that gets sent. > mail currently gets the body from an input box. this is where mail.py gets invoked: Email Results SMTP Server: Username: Password: From: To: Subject: Message: """ this is mail.py #!/usr/bin/env python import cgi import smtplib import os import sys import urllib import re from email.MIMEText import MIMEText print "Content-type: text/html\n" form = cgi.FieldStorage() #Initializes the form dictionary to take data from html form key = [ 'SMTP Server', 'Username', 'Password', 'From', 'To', 'Subject', 'Message' ] def get(form, key): if form.has_key(key): return form[key].value else: return "" if get(form, "SMTP Server") or get(form, "Username") or get(form, "Password") or get(form, "From") or get(form, "To") or get(form, "Subject") or get(form, "Message"): print '' else: print 'Error: You did not enter any Email parameters' print '' print 'Email Confirmation PageYour email has been sent.""" -- http://mail.python.org/mailman/listinfo/python-list
Re: passing string from one file to another
I V wrote: > Kun wrote: >> mail currently gets the body from an input box. >> >> this is where mail.py gets invoked: > > OK, I'm a bit confused. Where is the "initial python program" in all > this? You seem to have an one python program (mail.py) and an HTML > form. As it stands, I don't see why you can't change mail.py so that it > refers to your string instead of msg.as_string() . > the html i pasted is part of a python-cgi file that is the 'initial' file. i can't just tell mail.py to use the string because the string is defined in the first python profile, not mail.py. -- http://mail.python.org/mailman/listinfo/python-list
attaching an excel file using MIME in smtp
does anyone know how to attach an excel file to send out using smtplib and MIME? -- http://mail.python.org/mailman/listinfo/python-list