Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from __future__ import print_function
- import time
- import os
- import sys
- import pandas as pd
- import inspect
- import MailUtil
- import ConfigUtil
- start = time.time()
- mail_notif = True
- def lineno():
- """Returns the current line number in our program."""
- return inspect.currentframe().f_back.f_lineno
- #################################################
- # Folder File Extract #
- #################################################
- cwd = os.path.dirname(os.path.abspath(__file__))
- config_file = os.path.join(cwd, "Config/Config.xml")
- appconfig = ConfigUtil.configread(config_file, 'appsettings')
- try:
- fold_path = sys.argv[1]
- print(fold_path)
- if fold_path is None or not os.path.exists(fold_path):
- raise Exception
- except Exception as e:
- print('invalid argument {}'.format(fold_path),e, lineno())
- mail_notif = False
- sys.exit()
- try:
- fileToSave = appconfig['FILE_TO_BE_SAVED']
- a = open(fileToSave, 'w+')
- for path, subdirs, files in os.walk(fold_path):
- for fileName in files:
- # print(fileName)
- if fileName.endswith('.txt'):
- # print (fileName)
- a.write(fileName + '\n')
- a.close()
- except(NameError, ValueError, AttributeError, IOError, IndexError, KeyError) as e:
- print ('Wrong File!. Please Try Again ', lineno())
- mail_notif = False
- try:
- exl_path = sys.argv[2]
- if exl_path is None:
- raise Exception
- except Exception as e:
- print ("Excel Argument not passed, Need File ", lineno())
- mail_notif = False
- sys.exit()
- try:
- excel_save_text = appconfig['EXL_FILE']
- data = pd.read_excel(exl_path)
- df1 = data.iloc[int(appconfig['row']):int(appconfig['row1']), int(appconfig['col']):int(appconfig['col1'])]
- for key, value in df1.iteritems():
- print(" ".format(key, value))
- df1.to_csv(excel_save_text, mode='w+', sep='\n', index=None, header=None)
- except(NameError, ValueError, AttributeError, IOError, IndexError, KeyError) as e:
- print(e, "Wrong definition file. Please Provide the correct File".format(lineno()))
- mail_notif = False
- # Comparison Operation to compare 2 set of files
- compare_file = appconfig['COMPARE_FILE']
- with open(excel_save_text, 'r') as masterData:
- with open(fileToSave, 'r') as userData:
- with open(compare_file, 'w') as Newdata:
- usedFile = [x.strip('\n') for x in list(userData)]
- usedFile.sort()
- masterFile = [x.strip('\n') for x in list(masterData)]
- masterFile.sort()
- for line in usedFile:
- if line not in masterFile:
- Newdata.write(line + '\n')
- if mail_notif:
- subject = appconfig['subject']
- mail_dl = appconfig['mail_dl']
- sender = appconfig['sender']
- body = appconfig['body']
- smtp_server = appconfig['SMTP_MAIL_SRVR']
- port_no = appconfig['SMTP_PORT']
- MailUtil.mail_notification(subject, body, sender, mail_dl, smtp_server, port_no,appconfig, attachment_file=compare_file)
- end = time.time()
- print("Time taken to process".format(end-start))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement