2021-09-27 00:20:37 +00:00
import requests
2021-10-28 22:16:50 +00:00
import re
2021-09-27 00:20:37 +00:00
import os
2021-09-27 02:18:20 +00:00
import datetime
2021-09-27 00:20:37 +00:00
import json
2021-09-27 02:18:20 +00:00
import smtplib
2021-09-27 00:20:37 +00:00
url = " https://onionoo.torproject.org/details "
r = requests . get ( url )
relays = json . loads ( r . content ) [ " relays " ]
2021-10-01 16:31:23 +00:00
email = " From: relay status <relaystatus@encryptionin.space> \n To: relaywatch@lists.encryptionin.space \n Subject: Relay Status " + datetime . datetime . now ( datetime . timezone . utc ) . strftime ( ' % Y- % m- %d % H ' ) + " \n \n "
2021-09-29 22:29:38 +00:00
status = " "
2021-10-28 22:16:50 +00:00
newVersions = 0
2021-09-29 22:29:38 +00:00
for new_relay in relays :
2021-09-30 21:57:07 +00:00
if datetime . datetime . strptime ( new_relay [ " first_seen " ] , " % Y- % m- %d % H: % M: % S " ) > ( datetime . datetime . utcnow ( ) - datetime . timedelta ( hours = 1 ) ) :
2021-09-29 22:29:38 +00:00
exit = " no "
if new_relay [ " exit_policy " ] [ 0 ] != " reject *:* " :
exit = " yes "
2021-10-01 23:46:43 +00:00
status + = " New relay: \" " + new_relay [ " nickname " ] + " \" , fingerprint: " + new_relay [ " fingerprint " ] + " , potential exit: " + exit + " , effective family size: " + str ( len ( new_relay [ " effective_family " ] ) - 1 ) + " \n "
2021-09-29 22:29:38 +00:00
2021-10-28 22:16:50 +00:00
if re . search ( " 0.3.5.17|0.4.5.11 " , new_relay [ " platform " ] , re . IGNORECASE ) :
newVersions + = 1
2021-09-29 22:29:38 +00:00
if status :
2021-10-28 22:16:50 +00:00
email + = status + " \n Total new versions: " + str ( newVersions ) + " \n "
2021-09-29 22:29:38 +00:00
try :
smtp = smtplib . SMTP ( ' localhost ' )
2021-10-01 16:31:23 +00:00
smtp . sendmail ( ' relaystatus@encryptionin.space ' , [ ' relaywatch@lists.encryptionin.space ' ] , email )
2021-09-30 16:17:33 +00:00
except :
2021-09-29 22:29:38 +00:00
print ( " couldn ' t send " )