SHARE
TWEET

Untitled

a guest Sep 11th, 2019 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import time
  3. import sys
  4. import subprocess
  5. import mysql.connector
  6. from mysql.connector import Error
  7. from mysql.connector import errorcode
  8.  
  9. getmail = "echo 's 1 newmail.txt' | mailx"
  10. delmail = "rm -rf newmail.txt"
  11. getLOG_ID = "grep LOG_ID newmail.txt"
  12. getVA_DATE = "grep VA_DATE newmail.txt"
  13. getEMAIL_ADDRESS = "grep EMAIL_ADDRESS newmail.txt"
  14. getNAME_1 = "grep NAME_1 newmail.txt"
  15. getNAME_2 = "grep NAME_2 newmail.txt"
  16. getPHYSADDRESS = "grep PHYS_ADDRESS newmail.txt"
  17. getCITY = "grep CITY newmail.txt"
  18. getNUMBER_TICKETS = "grep NUMBER_TICKETS newmail.txt"
  19.  
  20. while True:
  21.         try:
  22.                 subprocess.check_output(getmail, shell=True)
  23.                 print("New order found")
  24.                 LOG_ID_TMP = subprocess.check_output(getLOG_ID, shell=True, universal_newlines=True)
  25.                 VA_DATE_TMP = subprocess.check_output(getVA_DATE, shell=True, universal_newlines=True)
  26.                 EMAIL_ADDRESS_TMP = subprocess.check_output(getEMAIL_ADDRESS, shell=True, universal_newlines=True)
  27.                 NAME_1_TMP = subprocess.check_output(getNAME_1, shell=True, universal_newlines=True)
  28.                 NAME_2_TMP = subprocess.check_output(getNAME_2, shell=True, universal_newlines=True)
  29.                 PHYSADDRESS_TMP = subprocess.check_output(getPHYSADDRESS, shell=True, universal_newlines=True)
  30.                 CITY_TMP = subprocess.check_output(getCITY, shell=True, universal_newlines=True)
  31.                 NUMBER_TICKETS_TMP = subprocess.check_output(getNUMBER_TICKETS, shell=True, universal_newlines=True)
  32.                
  33.                 LOG_ID = LOG_ID_TMP.split(']')[1]
  34.                 VA_DATE = VA_DATE_TMP.split(']')[1]
  35.                 EMAIL_ADDRESS = EMAIL_ADDRESS_TMP.split(']')[1]
  36.                 NAME_1 = NAME_1_TMP.split(']')[1]
  37.                 NAME_2 = NAME_2_TMP.split(']')[1]
  38.                 PHYSADDRESS = PHYSADDRESS_TMP.split(']')[1]
  39.                 CITY = CITY_TMP.split(']')[1]
  40.                 NUMBER_TICKETS = NUMBER_TICKETS_TMP.split(']')[1]
  41.                 print("Opening connection to sql server")
  42.                 def insertVariblesIntoTable(LOG_ID, VA_DATE, EMAIL_ADDRESS, NAME_1, NAME_2, PHYSADDRESS, CITY, NUMBER_TICKETS):
  43.                     try:
  44.                         connection = mysql.connector.connect(host='localhost',
  45.                                                              database='ksgtickets',
  46.                                                              user='ksgtickets',
  47.                                                              password='12testpassword34')
  48.                         cursor = connection.cursor()
  49.                         mySql_insert_query = """INSERT INTO orders (LOG_ID, VA_DATE, EMAIL_ADDRESS, NAME_1, NAME_2, PHYSADDRESS, CITY, NUMBER_TICKETS)
  50.                                                VALUES (%s, %s, %s, %s, %s, %s, %s, %s) """
  51.                         recordTuple = (LOG_ID, VA_DATE, EMAIL_ADDRESS, NAME_1, NAME_2, PHYSADDRESS, CITY, NUMBER_TICKETS)
  52.                         cursor.execute(mySql_insert_query, recordTuple)
  53.                         connection.commit()
  54.                         print("Record inserted successfully into orders table")
  55.                     except mysql.connector.Error as error:
  56.                         print("Failed to insert into MySQL table {}".format(error))
  57.                     finally:
  58.                         if (connection.is_connected()):
  59.                             cursor.close()
  60.                             connection.close()
  61.                             print("MySQL connection is closed")
  62.                 insertVariblesIntoTable(LOG_ID, VA_DATE, EMAIL_ADDRESS, NAME_1, NAME_2, PHYSADDRESS, CITY, NUMBER_TICKETS)
  63.                 os.system(delmail)
  64.        
  65.         except subprocess.CalledProcessError:
  66.                 print("Nothing to do, sleep")
  67.         time.sleep(5)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top