diff --git a/relaystatus.py b/relaystatus.py index bf21d61..6bb1fa4 100644 --- a/relaystatus.py +++ b/relaystatus.py @@ -9,8 +9,11 @@ url = "https://onionoo.torproject.org/details" r = requests.get(url) relays = json.loads(r.content)["relays"] -email = "From: relay status \nTo: relaywatch@lists.encryptionin.space\nSubject: Relay Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n" -status = "" +relayWatchEmail = "From: relay status \nTo: relaywatch@lists.encryptionin.space\nSubject: Relay Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n" +relayStatus = "" + +exitWatchEmail = "From: relay status \nTo: exitwatch@lists.encryptionin.space\nSubject: Exit Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n" +exitStatus = "" newVersions = 0 @@ -19,15 +22,24 @@ for new_relay in relays: exit = "no" if new_relay["exit_policy"][0] != "reject *:*": exit = "yes" - status += "New relay: \"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", potential exit: " + exit + ", effective family size: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n" + exitStatus += "New exit: \"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", effective family size: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n" + relayStatus += "New relay: \"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", potential exit: " + exit + ", effective family size: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n" if re.search("0.3.5.17|0.4.5.11", new_relay["platform"], re.IGNORECASE): newVersions += 1 -if status: - email += status + "\nTotal new versions: " + str(newVersions) + "\n" +if relayStatus: + relayWatchEmail += relayStatus + "\nTotal new versions: " + str(newVersions) + "\n" try: smtp = smtplib.SMTP('localhost') - smtp.sendmail('relaystatus@encryptionin.space', ['relaywatch@lists.encryptionin.space'], email) + smtp.sendmail('relaystatus@encryptionin.space', ['relaywatch@lists.encryptionin.space'], relayWatchEmail) + except: + print("couldn't send") + +if exitStatus: + exitWatchEmail += exitStatus + try: + smtp = smtplib.SMTP('localhost') + smtp.sendmail('relaystatus@encryptionin.space', ['exitwatch@lists.encryptionin.space'], exitWatchEmail) except: print("couldn't send")