Skip to content

New unit added in volume calculation #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Converter/converter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
cubic m : m3
litre: l
milliliter : ml
kilolitre : kl

MASS : M ----------------------------------------------------------------
gram : g
Expand All @@ -49,6 +50,11 @@
week : w
year : y

TEMPERATURE : t ----------------------------------------------------------------
kelvin : K
Celsius : C
Fahrenheit : F

''',

"help":'''
Expand Down Expand Up @@ -98,7 +104,8 @@
"ml":10**(6) ,
"l":10**(3) ,
"in3":61023.7441 ,
"ft3":35.31467}
"ft3":35.31467 ,
"kl":1}

M= {"g":1 ,
"kg":10**(-3) ,
Expand All @@ -115,3 +122,6 @@
"min":1440 ,
"sec":86400 }

t= {"K":274.15 ,
"C":1 ,
"F":33.8 }
31 changes: 31 additions & 0 deletions Error and Logs Handling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)
[![View My Profile](https://img.shields.io/badge/View-My_Profile-green?logo=GitHub)](https://github.com/ndleah)
[![View Repositories](https://img.shields.io/badge/View-My_Repositories-blue?logo=GitHub)](https://github.com/ndleah?tab=repositories)

# Execute Shell Command

## 🛠️ Description
Python code is written to perform below 3 functionalities:
1. Execute shell command and get the output and error.
2. Logging of all steps
3. Archiving of logs

## ⚙️ Languages or Frameworks Used
Language used is Python. There are no dependencies.

## 🌟 User Inputs
There are 3 inputs required from user before executing the code:
1. Email Id
2. Log path
3. Archive Log path

Make sure to provide correct path for log, archive log and email_id in python file before executing it.

## 🌟 How to run
Simply import required funtions in your Python script and execute it.

## Author Name

[Madhuri Agarwal](https://github.com/magar51)

108 changes: 108 additions & 0 deletions Error and Logs Handling/error_logging_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""This script aims at creating log file and sending it on email"""
import os
import sys
import glob
import logging
import datetime
from shutil import move
import subprocess


"""Generic error handling module"""
def error(status, error_msg, module_name, return_code):

if status.lower() == 'error':
logging.error('!!! Error !!!')
logging.error('Error executing module : %s', module_name)
logging.error(error_msg)
logging.error('Module return code : %s', return_code)
logging.error('Exiting script with exit(1) !!!')
email_log_file(log_file, status='failure')
sys.exit(1)

if status.lower() == 'warning':
logging.warning('!!! Warning !!!')
logging.warning('Error executing module : %s', module_name)
logging.warning(error_msg)
logging.warning('Module return code : %s', return_code)
logging.warning('Script execution will continue !!!')


"""Generic Logging function """
def initiate_logging():

dt_now = datetime.datetime.today()
log_file = '<file_path>' + 'testing' + dt_now.strftime('_%Y%m%d_%H%M%S') + '.log'
log_file_pattern = '<file_path>' + 'testing' + '*' + '.log'
log_file_list = glob.glob(log_file_pattern)

for file in log_file_list:
if os.path.exists(file):
dest_file = '<archive_log_path>' + file.split('/')[-1]
if os.path.exists(dest_file):
os.remove(dest_file)
move(file, '<archive_log_path>')

logging.basicConfig(filename=log_file, level=logging.DEBUG,
format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

return log_file


"""Executes the provided unix shell command """
def execute_shell_command(command):

try:
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = proc.communicate()
return_code = proc.returncode
if err:
print(str(err))
return out, return_code
except Exception as err:
print("Exception Occurred while executing module : %s", str(err))
return 105


"""Emails the status of job execution along with log file as attachment"""
def email_log_file(log_file, status):

if status == 'success':
body = 'Execution successful...PFA log file'
subject = 'Execution successful - testing'

email_cmd = """echo "{b}" | mailx -s "{s}" -a "{l}" "{to}" """.format(b=body, s=subject, l=log_file, to='<email_id>')
logging.info('Email Command :- %s', email_cmd)
os.system(email_cmd)
else:
body = 'Execution Failed...PFA log file'
subject = '!!! Failure - testing !!!'

email_cmd = """echo "{b}" | mailx -s "{s}" -a "{l}" "{to}" """.format(b=body, s=subject, l=log_file, to='<email_id>')
logging.info('Email Command :- %s', email_cmd)
os.system(email_cmd)


# Start of Execution
if __name__ == '__main__':

log_file = initiate_logging()

logging.info('!!! Execution Begins !!!')

command ='echo Madhuri'
result, status = execute_shell_command(command)

if status != 0:
logging.info("Exception in running shell command")
STATUS = 'error'
ERROR_MSG = '!!! Error !!! Execution failed !!!'
MODULE_NAME = 'Execution Script'
RETURN_CODE = ''
error(STATUS, ERROR_MSG, MODULE_NAME, RETURN_CODE)
else:
command_result = result.decode('utf8').rstrip("\r\n")
logging.info(command_result)

email_log_file(log_file, status='success')
# End of Execution
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,4 @@ If you have any feedback or ideas to improve this project, feel free to contact
<a href="https://github.com/ndleah">
<img align="left" alt="Reeha's Github" width="22px" src="https://cdn.jsdelivr.net/npm/simple-icons@v3/icons/github.svg" />
</a>
# python-mini-projects
2 changes: 1 addition & 1 deletion Smart_Calculator/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def calculate():
list.insert(END,'something went wrong please enter again')

operations = {'ADD':add,'ADDITION':add, 'SUM':add, 'PLUS':add,
'SUB':sub, 'DIFFERENCE':sub, 'MINUS': sub, 'SUBTRACT':sub, 'DIFF':sub,
'SUB':sub, 'DIFFERENCE':sub, 'MINUS': sub, 'SUBTRACT':sub, 'DIFF':sub, 'SUBTRACTION':sub,
'LCM':lcm, 'HCF':hcf, 'PRODUCT':mul, 'MULTIPLICATION':mul,
'MULTIPLY':mul, 'DIVISION':div, 'DIV':div, 'DIVIDE':div,
'MOD':mod,'REMAINDER':mod, 'MODULUS':mod}
Expand Down