5
5
import ystockquote, sys, os
11
bsch_quote = float(ystockquote.get_price('SAN.MC'))
12
diff = bsch_quote - purchase_price
14
quote_str = "Banco Santander: " + str(bsch_quote) + "€ (+" + str(diff) \
17
quote_str = "Banco Santander: " + str(bsch_quote) + "€ (" + str(diff) + \
19
print quote_str + "\n"
21
balance = (bsch_quote * num_stocks) - (purchase_price * num_stocks)
22
percentage = ((purchase_price - bsch_quote ) / purchase_price) * -100
25
balance_str = "Balance: +" + str(balance) + "€ (+" \
26
+ str(percentage)[:4] + "%)"
28
balance_str = "Balance: " + str(balance) + "€ (" \
29
+ str(percentage)[:4] + "%)"
32
total = bsch_quote * num_stocks
33
total_str = "Total: " + str(total) + "€ (" + str(num_stocks) + " stocks)"
37
# lets send an email with the info
38
fromaddr = "booty@rorschach"
12
stocks.append("SAN.MC")
13
num_stocks.append(444)
14
purchase_prices.append(6.66)
16
stocks.append("SAN.MC")
18
purchase_prices.append(6.79)
21
fromaddr = "finance <luisbg@ubuntu.com>"
39
22
toaddrs = "bethencourt@gmail.com"
40
subject = "Finance update"
23
subject = "[LBG] Finance update"
25
smtpuser = "bethencourt@gmail.com"
26
gpass = open("/home/luisbg/gmailpass")
27
smtppass = gpass.readlines(1)[0]
42
29
# Add the From: and To: headers at the start!
43
30
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
44
31
% (fromaddr, toaddrs, subject))
45
msg = msg + quote_str + " \n" + "\n" + balance_str + "\n" + total_str
47
server = smtplib.SMTP('localhost')
48
server.set_debuglevel(1)
33
# Print all the information and add it to the mail
36
for elements in stocks:
37
quote = float(ystockquote.get_price(stocks[c]))
38
diff = quote - purchase_prices[c]
40
quote_str = "Banco Santander: " + str(quote) + "€ (+" + str(diff) \
43
quote_str = "Banco Santander: " + str(quote) + "€ (" + str(diff) + \
45
print quote_str + "\n"
47
balance = (quote * num_stocks[c]) - (purchase_prices[c] * num_stocks[c])
48
percentage = ((purchase_prices[c] - quote ) / purchase_prices[c]) * -100
51
balance_str = "Balance: +" + str(balance) + "€ (+" \
52
+ str(percentage)[:4] + "%)"
54
balance_str = "Balance: " + str(balance) + "€ (" \
55
+ str(percentage)[:4] + "%)"
58
value = quote * num_stocks[c]
59
value_str = "Value: " + str(value) + "€ (" + str(num_stocks[c]) + " stocks)"
63
msg = msg + quote_str + " \n" + "\n" + balance_str + "\n" + value_str + "\n\n"
68
total_str = "Total: " + str(total) + "€"
74
server = smtplib.SMTP('smtp.gmail.com')
75
server.set_debuglevel(False)
79
server.login(smtpuser, smtppass)
49
80
server.sendmail(fromaddr, toaddrs, msg)