Hello. I tried to streamline the standard role of new employees, telephone answering, with Python.
It is common for the person to handle the call to not be at your desk. At that time, I would send an e-mail telling me that there was a call, but it is actually troublesome to write a fixed text every time. So I wrote a program to create the text and subject.
Create the body of a message email telling you that there was a call
Phone number suggestion based on the company name / name that was called in the past
Creating and sending emails is manual ('ω')
Output a txt file like this. The first line is the subject. The text after that is the text.
TELmemo.txt
[Message memo] foobar
hoge
thank you for your hard work. [My name].
There was a call from bar of foo.
Please return.
TEL 000-000-000
Below is the source code.
TELmemo.py
#coding:utf-8
import time
from datetime import datetime
import csv
import pandas as pd
import os.path
def existsLog():
#Create the log file if it does not exist
if os.path.exists("telLog.csv") == False:
f = open('telLog.csv','w')
writer = csv.writer(f,lineterminator='\n')
header = []
header.append('To')
header.append('From')
header.append('incNm')
header.append('Tel')
header.append('Time')
writer.writerow(header)
f.close()
#Name entered,A method to suggest a phone number from a log with a company name
def suggestTelNo(df,nm,incNm):
telNo = ""
select = ""
for index,row in df.iterrows():
if row['From'] == nm and row['incNm'] == incNm:
print("Maybe this phone number? : ",end="")
print(row['Tel'])
print("y/n: ",end="")
select = input()
telNo = row['Tel']
break
if select == 'y':
return telNo
else:
return None
#Method to output log
def mkLog(To,From,incNm,telNo):
time = datetime.now()
timeStr = time.strftime("%Y.%m.%d %H:%M:%S")
info = [To,From,incNm,telNo,timeStr]
with open('telLog.csv','a') as f:
writer = csv.writer(f,lineterminator='\n')
writer.writerow(info)
f.close()
if __name__ == "__main__":
f = open('TELmemo.txt','w')
ln1 = "\n Thank you for your hard work. [My name]."
ln2_1 = "of"
ln2_2 = "I got a call from you."
ln3 = "Please return."
ln4 = "TEL "
print("---The one who makes the text of the message mail---")
print("---Message history---")
existsLog()
#Data frame for phone number suggestion
df = pd.read_csv('telLog.csv',encoding='UTF-8')
del df['Time']
#Display message history
print(df)
print("\n * Names are omitted.")
print("To whom?:",end="")
to = input()
print("From where?")
print("Company name:",end="")
incNm = input()
print("name:",end="")
nm = input()
ln2 = incNm + ln2_1 + nm + ln2_2
#Name entered,The process of suggesting a phone number from a log with a company name
tel = suggestTelNo(df,nm,incNm)
#Enter your phone number when you call for the first time
if tel is None:
print("TEL:",end="")
tel = input()
ln4 = ln4 + tel
#Show phone number if you have called in the past
else:
print("TEL:" + tel)
ln4 = ln4 + tel
#Output log
mkLog(to,nm,incNm,tel)
#Create subject
sub = "[Message memo]" + incNm + nm + "Mr" + '\n'
#Divide and store the wording to be included in the text
msg = (sub,to+"Mr.",ln1,ln2,ln3,ln4)
#Write the text line by line to a txt file and output to the screen
for line in msg:
print(line)
f.write(line + '\n')
f.close()
#I'll just wait for 3 seconds(To check the contents)
time.sleep(3)
exit()
Recommended Posts