<commit_before>import MySQLdb
import xlsxwriter
import mysql.connector  
import datetime  





from xml.dom import minidom

doc = minidom.parse("mykong.xml")

majors = doc.getElementsByTagName("major")

get_user = doc.getElementsByTagName("user")[0]
get_pwd = doc.getElementsByTagName("password")[0]
get_db = doc.getElementsByTagName("dbname")[0]
get_host = doc.getElementsByTagName("host")[0]
user = get_user.firstChild.data
pwd = get_pwd.firstChild.data
dbn = get_db.firstChild.data
host = get_host.firstChild.data



db = mysql.connector.connect(user=user, password=<PASSWORD>,
                              host=host,
                              database=dbn)
                              
                              

cursor = db.cursor()

for major in majors:

  title = major.getElementsByTagName("title")[0]
  heading = title.firstChild.data
  sql = major.getElementsByTagName("sql")[0]
  location = major.getElementsByTagName("location")[0]
  loc = location.firstChild.data
  query=sql.firstChild.data 
  try:	
          print query
          
          cursor.execute(query)
          
          result = cursor.fetchall()
          num_fields = len(cursor.description)
        
          field_names = [i[0] for i in cursor.description]
          print result
          workbook = xlsxwriter.Workbook(loc)
          worksheet = workbook.add_worksheet()
             
          worksheet.set_column(0,6,5)
          bold = workbook.add_format({'bold': True})
          date_format = workbook.add_format({'num_format': 'mmmm d yyyy'})
          time_format = workbook.add_format({'num_format': 'hh:mm:ss'})
          timestamp_format = workbook.add_format({'num_format': 'dd/mm/yy hh:mm:ss'})



          worksheet.write(0,0,heading,bold)
      

          row=1
          col=0
          j = 0
          for rows in field_names:
              worksheet.write(row,col,field_names[j],bold)
              col = col + 1
              j = j + 1
          n=0
          for rows in result:
            col=0
            row = row + 1
            for cols in rows:
                if type(result[n][col]) is datetime.date:
                  worksheet.write(row,col,result[n][col],date_format)
                if type(result[n][col]) is datetime.timedelta :
                  worksheet.write(row,col,result[n][col],time_format)
                if type(result[n][col]) is datetime.datetime:
                  worksheet.write(row,col,result[n][col],timestamp_format)

                else:
                  worksheet.write(row,col,result[n][col])
                col = col + 1
            n = n+1
                

            
          
   	
  except Exception as inst:
	 		  print "database & workbook is closing due to Exception"
        
      
      

workbook.close()
db.close()
print "database closed"
print "fine"<commit_msg>included receivers<commit_after>#packages

import MySQLdb
import xlsxwriter
import mysql.connector  
import datetime  
import logging
import sys
from mailer import Mailer
from mailer import Message
import smtplib
import base64

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
from xml.dom import minidom

doc = minidom.parse("mykong.xml")

#------------------------------------------------------------------------------------------------

def mailing_system(reciepent,loc,heading):
  fromaddr = "<EMAIL>"
  reciever = reciepent
  toaddr = reciever.split(',')
  location = loc
  larray = location.split('/')
  larray.reverse()
  filename = larray[0]
  msg = MIMEMultipart()
 
  msg['From'] = "<NAME>"
  msg['To'] = "Atharva outlook"
  msg['Subject'] = heading
 
  body = "Hi, please find the attachments below. Thanks :D"
 
  msg.attach(MIMEText(body, 'plain'))
 
  attachment = open(location, "rb")
 
  part = MIMEBase('application', 'octet-stream')
  part.set_payload((attachment).read())
  encoders.encode_base64(part)
  part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
 
  msg.attach(part)
 
  server = smtplib.SMTP('smtp.gmail.com', 587)
  server.starttls()
  server.login(fromaddr, "8425959435123")
  text = msg.as_string()
  server.sendmail(fromaddr, toaddr, text)
  server.quit()
 
#--------------------------------------------------------------------------------------




majors = doc.getElementsByTagName("major")

get_user = doc.getElementsByTagName("user")[0]
get_pwd = doc.getElementsByTagName("password")[0]
get_db = doc.getElementsByTagName("dbname")[0]
get_host = doc.getElementsByTagName("host")[0]
user = get_user.firstChild.data
pwd = get_pwd.firstChild.data
dbn = get_db.firstChild.data
host = get_host.firstChild.data
log = open("myprog.log", "a")
sys.stdout = log


db = mysql.connector.connect(user=user, password=<PASSWORD>,
                              host=host,
                              database=dbn)
                              
                              

cursor = db.cursor()

for major in majors:

  title = major.getElementsByTagName("title")[0]
  heading = title.firstChild.data
  sql = major.getElementsByTagName("sql")[0]
  location = major.getElementsByTagName("location")[0]
  loc = location.firstChild.data
  query=sql.firstChild.data 
  reciever = major.getElementsByTagName("reciever")[0]
  reciepent = reciever.firstChild.data
  try:  
          print query
          
          cursor.execute(query)
          
          result = cursor.fetchall()
          num_fields = len(cursor.description)
        
          field_names = [i[0] for i in cursor.description]
          print result
          workbook = xlsxwriter.Workbook(loc)
          worksheet = workbook.add_worksheet()


                      
        
          bold = workbook.add_format({'bold': True})
          date_format = workbook.add_format({'num_format': 'mmmm d yyyy'})
          time_format = workbook.add_format({'num_format': 'hh:mm:ss'})
          timestamp_format = workbook.add_format({'num_format': 'dd/mm/yy hh:mm:ss'})
          format = workbook.add_format()
          size = workbook.add_format()
          align = workbook.add_format()
          format.set_border()
          date_format.set_border()
          time_format.set_border()
          timestamp_format.set_border()
          align.set_border()
          format.set_bg_color('cyan')
          size.set_font_size(20)  
          align.set_align('left')
          date_format.set_align('left')
          time_format.set_align('left')
          timestamp_format.set_align('left')
          worksheet.write(0,0,heading,size)
          worksheet.set_column(0,6,10)
          format.set_bold()
          

          row=1
          col=0
          j = 0
          for rows in field_names:

              worksheet.write(row,col,field_names[j],format)

              col = col + 1
              j = j + 1
          n=0
          for rows in result:
            col=0
            row = row + 1
            for cols in rows:
                if type(result[n][col]) is datetime.date:
                  worksheet.write(row,col,result[n][col],date_format)
                if type(result[n][col]) is datetime.timedelta :
                  worksheet.write(row,col,result[n][col],time_format)
                if type(result[n][col]) is datetime.datetime:
                  worksheet.write(row,col,result[n][col],timestamp_format)

                else:
                  
                  worksheet.write(row,col,result[n][col],align)

                col = col + 1
            n = n+1
          mailing_system(reciepent,loc,heading)      


            
          
    
  except Exception as inst:
        print "database & workbook is closing due to Exception"
        
      
      

workbook.close()
db.close()
print "database closed"
print "fine"
{'fraction_non_alphanumeric': 0.13084711008586442, 'fraction_numerical': 0.009099064462386262, 'mean_word_length': 1.9877488514548238, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2778550', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2338, 'n_words': 442}