Beginner PYTHON, and guide MySQL date field after the query with the current tim

At present, there is a MySQL Library
dbname=myserver
tablename=PhysicalDevice

select name,end_of_warranty from PhysicalDevice

+--------------------------------------------------+-----------------+
| name | end_of_warranty |
+--------------------------------------------------+-----------------+
| Server1 | NULL |
| Server2 | NULL |
| Server3 | NULL |
| Server4 | 2013-05-21 |
| Router1 | NULL |
| Switch1 | NULL |
| Rack1 | NULL |
| Rack B01 | 2015-03-28 |
| Rack B02 | 2015-03-28 |
| Rack B03 | 2015-03-28 |
| Rack B04 | 2015-03-28 |
| VCENTER SERVER | 2015-02-01 |
| livep1 | 2015-02-01 |
| livep2 | 2015-02-01 |
| livep3 | 2015-02-01 |
| livep4 | 2015-02-01 |
| livep5 | 2015-02-01 |
+--------------------------------------------------+-----------------+


To realize the comparison between the end_of_warranty and the current time with PYTHON, delete selected due maintenance within three months of the entry, and e-mail notice sent greatly, can be under the guidance of it

Started by Linda at January 09, 2017 - 1:55 PM

A personal idea, if the database pressure not so big, can consider to use DateDiff with SQL that what needs to be communicated, then, you only need to use Python to a mail to.
As with the python to send mail, here is an example to.
  1. #!/usr/bin/python

  2. import smtplib

  3. sender = ''
  4. receivers = ['']
  5. message = """From: From Person <>
  6. To: To Person <>
  7. MIME-Version: 1.0
  8. Content-type: text/html
  9. Subject: SMTP HTML e-mail test

  10. This is an e-mail message to be sent in HTML format

  11. <b>This is HTML message.</b>
  12. <h1>This is headline.</h1>
  13. """

  14. try:
  15. smtpObj = smtplib.SMTP('localhost')
  16. smtpObj.sendmail(sender, receivers, message)
  17. print "Successfully sent email"
  18. except SMTPException:
  19. print "Error: unable to send email"

Posted by Theobald at January 11, 2017 - 1:43 PM