-
Notifications
You must be signed in to change notification settings - Fork 0
/
trkchk.py
165 lines (129 loc) · 5.4 KB
/
trkchk.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import requests
import os
from rich.console import Console
from rich.table import Table
from termcolor import colored
# Tracker file
TRACKER_FILE = 'data/trackers.txt'
MENU = [
{ 'item': 1, 'name': 'Check for open signups', 'function': 'checkForOpenSignups' },
{ 'item': 2, 'name': 'List trackers', 'function': 'listTrackers' },
{ 'item': 3, 'name': 'Add a tracker to the list', 'function': 'addTrackerToFile' },
{ 'item': 4, 'name': 'Remove a tracker from the list', 'function': 'removeTrackerFromFile' },
{ 'item': 5, 'name': 'Open trackers.txt', 'function': 'openTrackerFile'},
{ 'item': 6, 'name': 'Exit', 'function': 'exit' }
]
# Logo
def displayLogo():
print('▄▄▄▄▄▄▄▄ ▄ •▄ ▄▄· ▄ .▄▄ •▄ ');
print('•██ ▀▄ █·█▌▄▌▪▐█ ▌▪██▪▐██▌▄▌▪');
print(' ▐█.▪▐▀▀▄ ▐▀▀▄·██ ▄▄██▀▐█▐▀▀▄·');
print(' ▐█▌·▐█•█▌▐█.█▌▐███▌██▌▐▀▐█.█▌');
print(' ▀▀▀ .▀ ▀·▀ ▀·▀▀▀ ▀▀▀ ··▀ ▀');
print('-------------------------------------------------');
# Menu + input
def getMenuInput():
for menuItem in MENU:
print(colored('[' + str(menuItem['item']) + '] ', 'yellow') + menuItem['name'])
userInput = input('> ')
print('\n')
return userInput
# Check that the tracker file exists
def checkTrackerFileStatus():
if not os.path.isfile(TRACKER_FILE):
print(colored('[ERROR]', 'red') + ' Tracker list not found!')
input('Press enter to exit...')
exit()
# List trackers
def listTrackers():
checkTrackerFileStatus()
rows = []
columns = ['ID', 'Name', 'Reg. URL', 'Closed text']
# Open the file and read the trackers into an array
with open(TRACKER_FILE, 'r', encoding='utf-8') as f:
lines = f.readlines()
i = 1
for line in lines:
line = line.strip()
tracker = line.split('|')
rows.append([str(i), tracker[0], tracker[1], tracker[2]])
i = i + 1
# Print the trackers in a table format
table = Table(title='Trackers')
for column in columns:
table.add_column(column)
for row in rows:
table.add_row(*row, style='bright_green')
console = Console()
console.print(table)
# Check for open signups
def checkForOpenSignups():
checkTrackerFileStatus()
print(colored('[CHECKING FOR OPEN SIGNUPS]', 'cyan'))
trackers = []
# Open the file and read the trackers into an array
with open(TRACKER_FILE, 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
line = line.strip()
tracker = line.split('|')
trackers.append([tracker[0], tracker[1], tracker[2]])
# Check each tracker
for tracker in trackers:
# Get the tracker's response
try:
response = requests.get(tracker[1])
except:
print(colored('[ERROR]', 'red') + ' Could not connect to ' + colored(tracker[0], 'yellow'))
continue
# If the response includes the text we are looking for it is closed
if tracker[2] in response.text:
print(colored(tracker[0], 'yellow') + ' is ' + colored('closed', 'red'))
# If the response doesn't include the text we are looking for it is open
else:
print(colored(tracker[0], 'yellow') + ' is ' + colored('open', 'green') + ' | ' + colored(tracker[1], 'blue'))
# Add tracker to file
def addTrackerToFile():
print(colored('[ADD TRACKER TO LIST]', 'cyan'))
tracker = input('Tracker name: ')
url = input('Tracker registration URL: ')
text = input('Text to look for: ')
# Add the tracker to the list
with open(TRACKER_FILE, 'a', encoding='utf-8') as f:
f.write(tracker + '|' + url + '|' + text + '\n')
print(colored('Tracker added!', 'green'))
# Remove tracker from file
def removeTrackerFromFile():
checkTrackerFileStatus()
print(colored('[REMOVE TRACKER FROM LIST]', 'cyan'))
listTrackers()
trackerInput = input('Tracker ID: ')
# Remove tracker from the list based on the ID (line number)
with open(TRACKER_FILE, 'r', encoding='utf-8') as f:
lines = f.readlines()
# Check that the tracker ID is a valid line number
if int(trackerInput) > len(lines):
print(colored('[ERROR]', 'red') + ' Tracker ID not found!')
input('Press enter to exit...')
exit()
# Remove the tracker from the list
lines.pop(int(trackerInput) - 1)
with open(TRACKER_FILE, 'w', encoding='utf-8') as f:
f.writelines(lines)
print(colored('Tracker removed!', 'green'))
def openTrackerFile():
os.system('start ' + TRACKER_FILE)
# Logo
displayLogo()
while True:
# Grab user input
userInput = getMenuInput()
# Check if the user entered a valid number
if userInput.isdigit():
userInput = int(userInput)
if userInput == 6:
exit()
if userInput > 0 and userInput <= len(MENU):
locals()[MENU[userInput - 1]['function']]()
else:
print(colored('[ERROR]', 'red') + ' Invalid menu item!')