gt
跳转到导航
跳转到搜索
A tiny little python script used to get the latest trackers from various sources and, by default, uploads the aggregated list to a specific location using fup, or, when switch ‘-c’ is given, copies the aggregated list to the clipboard. (Or, if the python script is run independently, it will save the aggregated list to a file named ‘trackers’ in the current location—yes, extension is deliberately omitted here.)
The python script and the batch / bash script shall be put into %PATH%, where in my case, C:\ on Windows or / on Linux. On Linux, those scripts shall also be marked as ‘executable’ by ch. And of course, on Windows, python must be installed.
The python script
gt.py
import requests, sys, subprocess
t=[]
for x in['https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt','https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all_ip.txt','https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt']:
try:
r=requests.get(x,timeout=12);r.raise_for_status();t.extend(r.text.splitlines())
except:sys.exit(1)
s=set();a=[]
for y in t:
z=y.strip()
if z and z not in s:s.add(z);a.append(z)
if a:
c='\n\n'.join(a)+'\n'
try:
if'-c'in sys.argv:
if sys.platform.startswith('win'):subprocess.Popen(['clip'],stdin=subprocess.PIPE).communicate(input=c.encode())
elif sys.platform=='darwin':subprocess.Popen(['pbcopy'],stdin=subprocess.PIPE).communicate(input=c.encode())
else:
try:subprocess.Popen(['xclip','-selection','clipboard'],stdin=subprocess.PIPE).communicate(input=c.encode())
except FileNotFoundError:subprocess.Popen(['xsel','--clipboard','--input'],stdin=subprocess.PIPE).communicate(input=c.encode())
else:
open('trackers','w',encoding='utf-8').write(c)
except:sys.exit(1)
The batch
gt.bat
@echo off
chcp 65001 >nul
if /i "%1"=="-c" ("C:\_c\gt.py" -c) else ("C:\_c\gt.py" && fup trackers && del trackers)
The bash
gt
#!/bin/bash
if [ "${1,,}" = "-c" ]; then
python3 /usr/local/bin/gt.py -c
else
python3 /usr/local/bin/gt.py && fup trackers && rm -f trackers
fi