Skip to content

Instantly share code, notes, and snippets.

View samirsaci's full-sized avatar

Samir Saci samirsaci

View GitHub Profile
@samirsaci
samirsaci / read_email.py
Created September 10, 2022 18:14
Productivity
import win32com.client
import os
from datetime import datetime, timedelta
# Initiate the Outlook Session
outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")
# Select the folder 6 to get the emails
inbox = mapi.GetDefaultFolder(6)
# Message Object
msg = MIMEMultipart()
msg['Subject'] = 'Workload Report for {}'.format(WEEK)
msg['From'] = from_mail
msg['To'] = ', '.join([from_mail, to_mail])
msg.preamble = 'Workload Report for {}'.format(WEEK)
# Attach the HTML code
msg.attach(MIMEText(html_string, 'html', 'utf-8'))
@samirsaci
samirsaci / add_insights.py
Last active September 3, 2022 14:34
Mail Report
# Add the insights
html_string = html_string.replace("WEEK", WEEK)
html_string = html_string.replace("total_lines", total_lines)
html_string = html_string.replace("busy_day", busy_day)
html_string = html_string.replace("max_lines", max_lines)
html_string = html_string.replace("avg_ratio", avg_ratio)
html_string = html_string.replace("max_ratio", max_ratio)
@samirsaci
samirsaci / add_images.py
Created September 3, 2022 11:35
Mail Report
# Open the visual
with open(file_img, 'rb') as fp:
img = MIMEImage(fp.read())
img.add_header('Content-Disposition', 'attachment', filename=file_img)
img.add_header('X-Attachment-Id', '0')
img.add_header('Content-ID', '<0>')
fp.close()
msg.attach(img)
# Open the header
@samirsaci
samirsaci / save_img.py
Created September 3, 2022 11:28
Mail Report
# save plot
filename = 'visual' + ".png"
path_plot = filename
fig.savefig(path_plot, dpi=fig.dpi)
@samirsaci
samirsaci / insights.py
Created September 3, 2022 11:23
Mail Report
# Lines per orders
avg_ratio = '{:.2f} lines/order'.format(df_plot['LINES/ORDER'].mean())
max_ratio = '{:.2f} lines/order'.format(df_plot['LINES/ORDER'].max())
# Maximum Day Lines
busy_day = dict_days[df_plot.set_index('DAY')['LINES'].idxmax()]
max_lines = '{:,} lines'.format(df_plot['LINES'].max())
# Total Workload
total_lines = '{:,} lines'.format(df_plot['LINES'].sum())
@samirsaci
samirsaci / build_chart.py
Created September 3, 2022 11:19
Mail Report
# Bar Plot: Orders/Lines
fig, ax = plt.subplots(figsize=(14, 7))
df_plot.plot.bar(figsize=(8, 6), edgecolor='black', x='DAY', y=['ORDERS', 'LINES'],
color=['tab:blue', 'tab:red'], legend= True, ax = ax)
plt.xlabel('DAY', fontsize = 12)
plt.title('Workload per day (Lines/day)', fontsize = 12)
plt.show()
@samirsaci
samirsaci / init_process.csv
Created September 3, 2022 11:18
Mail Report
DATE WEEK DAY ORDERS LINES PCS SKU CITIES LINES/ORDER
2017-01-02 WEEK-1 MON 776 1367 1595.0 487 174 1.7615979381443299
2017-01-03 WEEK-1 TUE 902 1550 1861.0 547 188 1.7184035476718404
2017-01-04 WEEK-1 WED 1476 2252 2856.0 513 205 1.5257452574525745
2017-01-05 WEEK-1 THU 909 1637 1972.0 519 175 1.800880088008801
2017-01-06 WEEK-1 FRI 1023 1720 1995.0 502 189 1.6813294232649072
@samirsaci
samirsaci / init.csv
Last active September 3, 2022 11:16
Mail Report
DATE WEEK DAY ORDERS LINES PCS SKU CITIES
2017-01-02 WEEK-1 MON 776 1367 1595.0 487 174
2017-01-03 WEEK-1 TUE 902 1550 1861.0 547 188
2017-01-04 WEEK-1 WED 1476 2252 2856.0 513 205
2017-01-05 WEEK-1 THU 909 1637 1972.0 519 175
2017-01-06 WEEK-1 FRI 1023 1720 1995.0 502 189
@samirsaci
samirsaci / libraries.py
Created August 20, 2022 16:30
Animate PIL
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from PIL import Image, ImageDraw, ImageChops, ImageFont
import io