-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.py
74 lines (64 loc) · 1.91 KB
/
timer.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#Author:Shruti Kapoor
#!/usr/bin/python
import re
import os
import sys
import datetime
import smtplib
from email.mime.text import MIMEText
#---------------SEARCH THE FILE FOR FOLLOWING STRINGS----------
datefield="date_submitted"
admin_email="ssharan@eoas.ubc.ca"
sender= "webadmin@slimweb.eos.ubc.ca"
#dateformat = '%m/%d/%Y' # Date should be in the format: month/date/year eg: 12/22/2012
timer_days=45
typename="@unpublished"
#--------------------DECLARATIONS------------
num_files=len(sys.argv)
int_keys=[]
setlist=[]
error_list=[]
key=[]
#---------------BEGIN PROCESSING------------------------
fileIN=open(sys.argv[1],"r")
def sendmail(error_list):
errors=" "
if error_list:
for each in error_list:
errors = errors + " " + each
text="Please update the following entries in unpublished.bib -" + errors
msg = MIMEText(text)
msg['Subject'] = 'Update unpublished.bib in SVN repository'
msg['From'] = sender
msg['To'] = admin_email
s = smtplib.SMTP()
s.connect(host='smtp.eos.ubc.ca',port=25)
s.sendmail(msg['From'],[admin_email], msg.as_string())
print("Message sent")
s.close()
else:
print("All entries updated")
print("Reading...")
for line in fileIN:
line=line.strip()
if typename.lower() in line.lower():
# Arnold: can do a regex extraction here and cut two/three lines something like [@]+([a-zA-Z]).[{].*?
entries=line.split('@')
entry=entries[1].strip()
split_entry=entry.split("{")[1]
key=split_entry.split(",")[0]
setlist.append(key)
if datefield.lower() in line.lower():
temp=line.split(datefield)
date=re.sub('[^A-Za-z0-9/]+', '', temp[1])
setlist.append
end_date=datetime.datetime.utcnow()
start_date = datetime.datetime.strptime(date,'%m/%d/%Y')
diff = (end_date - start_date).days
if diff > timer_days:
error_list.append(key)
if diff < 0:
print("Error:Invalid Date")
quit()
sendmail(error_list)
fileIN.close()