This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
forked from wikimedia/labs-tools-phabsearchemail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
79 lines (78 loc) · 2.32 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import json
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import sys
def run(emaillist, phaburl):
try:
file = open('config.csv', 'r')
except FileNotFoundError:
file = open('/srv/phabdigest/config.csv', 'r')
apikey = ''
sender = ''
for line in file:
configdata = line.split(',')
apiconfig = 'apikey-' + str(phaburl)
if configdata[1] == apiconfig:
apikey = configdata[2]
if configdata[1] == 'sender':
sender = configdata[2]
if configdata[1] == 'emailpassword':
gmail_password = configdata[2]
if configdata[1] == 'replyto':
replyto = configdata[2]
file = open(emaillist, '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"]
try:
data = result["data"]
except TypeError:
print(response)
sys.exit(1)
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 Digests"
msg["From"] = sender
msg["To"] = info[2]
msg["Reply-to"] = replyto
body = "This is your automated search alert from Phabricator \n " + output
msg.attach(MIMEText(body, 'plain'))
smtp = smtplib.SMTP("smtppro.zoho.eu", 587)
smtp.ehlo()
smtp.starttls()
smtp.login(sender, gmail_password)
smtp.sendmail(msg["From"], msg["To"], msg.as_string())
smtp.quit()
print ("Successfully sent email")
file.close()
try:
if sys.argv[1] == 'weekly':
emaillist = 'weekly.csv'
elif sys.argv[1] == 'monthly':
emaillist = 'monthly.csv'
else:
emaillist = sys.argv[1]
if sys.argv[2] == 'bots':
phaburl = 'phab.fossbots.org'
elif sys.argv[2] == 'mh':
phaburl = 'phabricator.miraheze.org'
run(emaillist,phaburl)
except IndexError as e:
print(e)
print("Format: script.py <list> <phaburl>")