-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinventory_daily.py
executable file
·47 lines (40 loc) · 1.29 KB
/
inventory_daily.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
import subprocess
import pickle
import datetime
import smtplib
import string
#MYEMAIL = "test@test.com"
#MYFROM = "test@inventory.com"
def sendmessage(recipient, subject, body):
try:
process = subprocess.Popen(['mail', '-s', subject, recipient],
stdin=subprocess.PIPE)
except Exception, error:
print error
process.communicate(body)
def main():
file = open('inventory.inv', 'r')
inventoryarr = pickle.load(file)
file.close()
#We just check for expiry of the elements
for upc in inventoryarr.keys():
length = inventoryarr[upc][0][0]
item = inventoryarr[upc][0][1]
for key in inventoryarr[upc][1:]:
newdate = key + datetime.timedelta(days=length)
print newdate
if newdate < datetime.date.today() + datetime.timedelta(days=2):
subj = "[INVENTORY] \"Items about to expire!\""
text = "\"Item UPC" + upc + ", " + item + " is expiring on " + str(newdate) + ". Consume with expedience!\""
BODY = string.join((
"From: %s" % MYFROM,
"To: %s" % MYEMAIL,
"Subject: %s" % subj ,
"",
text
), "\r\n")
sendmessage(MYEMAIL, subj, text)
print(text)
if __name__ == "__main__":
main()