Guest User

Untitled

a guest
Apr 24th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import cx_Oracle
  2.  
  3. def _safe_index(arr = [], val = ""):
  4. try:
  5. return arr.index(val)
  6. except ValueError:
  7. return -1
  8.  
  9. log = []
  10. logNames = []
  11.  
  12. def readLogs(args):
  13. start = 0
  14. end = 0
  15. for filename in args:
  16. start = len(log)
  17. f = open(filename, 'r')
  18. log.extend([i for i in f.readlines() if _safe_index(i, "CEmailDef") > -1])
  19. end = len(log)
  20. f.close()
  21. logNames.append((start,end,filename))
  22.  
  23. def getLogName(lineNum = 0):
  24. return [log[2] for log in logNames if log[0] <= lineNum and log[1] > lineNum][0]
  25.  
  26. def readDatabase():
  27. try:
  28. conn = cx_Oracle.connect("c_jmelloy@ods_prod.world")
  29. curs = conn.cursor()
  30.  
  31. sql = "select key_value, msg_id from site_email_outbound where status in (101, 100) and key_value is not null"
  32.  
  33. curs.execute(sql)
  34.  
  35. row = curs.fetchone()
  36. put_away = []
  37. print len(log)
  38. while(row):
  39. print row[0],
  40. i = 0
  41. for logline in log:
  42. if _safe_index(logline, row[0]) > -1:
  43. print "Match found in %s" % getLogName(i)
  44. if (_safe_index(logline, "cancel.asp") > -1 or
  45. _safe_index(logline, "forgot_password.asp") > -1 or
  46. _safe_index(logline, "rx_autorefill.asp") > -1 or
  47. _safe_index(logline, "site_error.asp") > -1 or
  48. _safe_index(logline, "shipment.asp") > -1 or
  49. _safe_index(logline, "vitaminadvisor.asp") > -1):
  50.  
  51. put_away.append(row[1])
  52. break
  53. i += 1
  54. if i == len(log):
  55. print "No match found"
  56.  
  57. row = curs.fetchone()
  58. print "%d matches found " % len(put_away)
  59.  
  60. w = open("update.sql", "w")
  61.  
  62. w.write("select status, count(*) from site_email_outbound where msg_id in (')")
  63. w.write("',\n'".join(put_away))
  64. w.write("') group by status;\n\n")
  65. w.write("update site_email_outbound set status = 1002 where msg_id in ('")
  66. w.write("',\n'".join(put_away))
  67. w.write("');\n\n")
  68. w.write("select status, count(*) from site_email_outbound where msg_id in (')")
  69. w.write("',\n'".join(put_away))
  70. w.write("') group by status;")
  71. w.close()
  72.  
  73. finally:
  74. conn.close()
  75.  
  76. if __name__ == "__main__":
  77. import sys
  78. readLogs(sys.argv[1:])
  79. readDatabase()
Add Comment
Please, Sign In to add comment