I'm making a program that will retrieve the data from google sheet which is a spending diary of how much I spend a week. After successfully retrieving the data, program will send an email to me that how much I spend day by day in a week.
I'm using gspread to retrieve the data, and I was able to retrive the data column by column using for loop
And it gives me data as a list. For example, if I do
num_days = 7
goods = []
for day in range(2, num_days + 2):
goods.append(worksheet.col_values(day))
OUTPUT: [['Mon 04/08/2019', 'Edeka 20.07'], ['Tue 04/09/2019', 'Edeka 9.77', 'Gym 60'], ['Wed 04/10/2019', 'Party 5', 'Jiujitsu System 30', 'Jiujitsu card 5', 'Jiujitsu Monthly fee 54'], ['Thu 04/11/2019', 'Laundry 3.5', 'Part 7.5 Euro'], ['Fri 04/12/2019', 'Edeka 5.95', 'Laundry 2'], ['Sat 04/13/2019', 'Food Festival 20 ', 'DM Hair Roller 3.25', 'Rewe 9.97'], ['Sun 04/14/2019', 'Monitor 224.99']]
So I am able to retrieve the column by column and put them in a list as a list.
That's all good. But I want to send email in this following format.
EX)
Mon: Edeka 20.07
Tue: Edeka 9.77, Gym 60
...
Sun: Monitor 224.99
And here is the photo of email that has arrived into my mailbox.
I want first elements to be gone to just show what goods I bought, excluding the date.
How can I form my message of email to be sent like the photo above?
I'm currently using smtplib to send an email, but I don't know how to fit just goods that I bought into the message.
def send_email_for_spending(money_spent_week):
with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
# title for your email
subject = "Here is how much you spent in this week."
# Number of Days
num_days = 7
goods = []
# it starts from 2 because column that has monday is 2nd
# column
for day in range(2, num_days + 2):
goods.append(worksheet.col_values(day))
message = f"""
MON:
{goods[0]}
TUE:
{goods[1]}
WED:
{goods[2]}
THU:
{goods[3]}
FRI:
{goods[4]}
SAT:
{goods[5]}
SUN:
{goods[6]}
"""
smtp.sendmail(EMAIL_ADDRESS, 'dudeindaegu@gmail.com', message)