-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.py
59 lines (59 loc) · 1.74 KB
/
script.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
import requests
import json
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import sys
def run(config):
file = open('config.csv', 'r')
apikey = ''
phaburl = 'phabricator.wikimedia.org'
sender = ''
for line in file:
configdata = line.split(',')
if configdata[1] == 'apikey':
apikey = configdata[2]
if configdata[1] == 'phaburl':
phaburl = configdata[2]
if configdata[1] == 'sender':
sender = configdata[2]
file = open(config, 'r')
for line in file:
info = line.split(',')
data = {
'api.token': apikey,
'queryKey': info[1]
}
response = requests.post('https://' + phaburl + '/api/maniphest.search', data=data)
response = response.json()
result = response["result"]
data = result["data"]
x = 0
output = ''
while x < len(data):
parse = data[x]
description = parse["fields"]
description = description["name"]
output = output + "\n\nhttps://" + phaburl + "/T" + str(parse["id"]) + " - " + str(description)
output = str(output)
x = x + 1
msg = MIMEMultipart()
msg["Subject"] = "Phabricator Search Alert"
msg["From"] = sender
msg["To"] = info[2]
body = "This is your automated search alert from Phabricator \n " + output
msg.attach(MIMEText(body, 'plain'))
smtp = smtplib.SMTP("localhost")
smtp.sendmail(msg["From"], msg["To"], msg.as_string())
smtp.quit()
print ("Successfully sent email")
file.close()
try:
if sys.argv[1] == 'weekly':
run('weekly.csv')
elif sys.argv[1] == 'monthly':
run('monthly.csv')
else:
run(sys.argv[1])
except IndexError:
print("No command specified.")