relay_status/prCount.py
2021-10-30 02:55:05 +00:00

48 lines
1 KiB
Python

from collections import Counter
import re
prLines = []
# You need a consensus, I download from collector, e.g: https://collector.torproject.org/recent/relay-descriptors/consensuses/2021-10-29-23-00-00-consensus
cons = open("consensus", "r")
torVersion = input("version to check:")
torSearch = "^v.*Tor " + torVersion
while True:
line1 = cons.readline()
if not line1: break
if re.search(torSearch, line1, re.IGNORECASE):
line2 = cons.readline()
prLines.append(line2)
c = Counter(prLines)
for element in c.most_common():
print(element)
#print(c.most_common())
print()
print(c.most_common(1)[0][0])
most_common = c.most_common(1)[0][0]
cons.close()
cons = open("consensus", "r")
while True:
line1 = cons.readline()
if not line1: break
if re.search("^r", line1, re.IGNORECASE):
line2 = cons.readline()
line2 = cons.readline()
if re.search(torSearch, line2, re.IGNORECASE):
line3 = cons.readline()
if line3 != most_common:
print(line1 + line3)