LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2012, 11:34 AM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
Python script sending email notifications to only one user


Hello --

We are using an ticket tracking application called Roundup, and part of its installation includes a python script that sends out e-mail reminders to users of open tickets. The script is meant to be run as a cron job.

The script is supposed to send reminders to multiple users, but is able to send to only one user. I asked about this issue, and the following reply was sent to me:
Quote:
I think that your original problem of only getting the last email has to do with the script indentation (in Python very i
important).


Here some things to look at:


- At line 56 you have a for loop in it "address" variable is being assigned on line 61
- that for loop ends at line 140
- the loop starting on line 101 and line 141 lock to me pretty much the same


So my "guess fix" without digging deeper is:
- comment lines 140 to 159
- indent lines 162 to 166 by one level, so that they are within the first for loop.
I went through the motions of implementing the suggestions, with the files in question change to the following:

Quote:
140 # old_priority = None
141 # for priority_order, activity_date, creation_date, issue_id in l:
142 # priority = db.issue.get(issue_id,'priority')
143 # if (priority != old_priority):
144 # old_priority = priority
145 # print >>body, '<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name')
146 # creation = (creation_date - date.Date('.')).pretty()
147 # if creation is None:
148 # creation = (creation_date - date.Date('.')).pretty()
149 # title = db.issue.get(issue_id, 'title')
150 # issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB,
151 # issue_id, issue_id)
152 # activity = (activity_date - date.Date('.')).pretty()
153 # print >>body, '''<tr><td>%s</td><td>%s</td><td>%s</td>
154 # <td>%s</td></tr>'''%(creation, issue_id, activity, title)
155 # print >>body, '</table>'
156 #
157 # print >>body, '''<p>To view or respond to any of the issues listed
158 # above, simply click on the issue ID. Do <b>not</b> respond to
159 # this message.</p>'''
160 #
161 # finish of the multipart
162 writer.lastpart()
163
164 # all done, send!
165 smtp = SMTPConnection(db.config)
166 smtp.sendmail(db.config.ADMIN_EMAIL, address, message.getvalue())
NOTE: It does not show it in this posting, but lines 162, 165, and 166 are indented by one tab.

When the script is run using the following command syntax:

Quote:
python /root/roundup-reminder.py /var/lib/roundup/tracker
The following output appears on-screen:

Quote:
File "/root/roundup-reminder.py", line 162
writer.lastpart()
^
IndentationError: unexpected indent
I have included the script with this posting, and I wanted to know what changes do I need to make in order for the script to be able to send to multiple users.

Thanks.
Attached Files
File Type: txt roundup-reminder.py.txt (6.3 KB, 9 views)
 
Old 10-03-2012, 05:51 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
The error is not from the file you sent, as far as I can see: I have no problems running the script. However, nor is anything commented out, so you must have sent the old version. Also, you haven't put the whitespace in the code you posted in [CODE][/CODE] tags - it is impossible for us to help you with your indentation if we can't see it! And you've missed the relevant 'line before' which shows us what the indentation level was before the block. So, to summarise: easiest thing to do is to attach the modified script to your post, or to post more of the script correctly indented.

Apologies if this comes across as a rant of sorts - it is honestly not meant to be so, but we really can't help you very much with the information you gave us
 
Old 10-03-2012, 12:15 PM   #3
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Hello --

I spoke with a colleague about the script, and there was a problem with the indentation. My apologies for the posting not showing the script in its original form. Basically, the loop in question was not indented to the proper location, and the commands within it being seen as not part of the loop. Once the correction was made,
the script worked without issue. The corrected version of the script has been uploaded as an attachment.
Attached Files
File Type: txt roundup-reminder.py.txt (6.0 KB, 6 views)
 
Old 10-03-2012, 05:54 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sendmail is not sending email from PHP script. [RESOLVED] frigy Linux - Software 5 09-13-2010 01:08 PM
sending of email notifications LayTech Linux - Newbie 7 07-23-2010 08:24 AM
Mointor when a user logs in and sending an email beanpost Linux - General 4 03-31-2010 05:11 AM
Sending email notifications on a Squid proxy server RedHelix Linux - Server 4 09-12-2009 10:54 AM
sending email from a script without sendmail tangle Linux - Networking 1 12-06-2005 01:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration