diff options
author | Linux User <jordan@winter.local> | 2023-06-24 00:13:26 +0000 |
---|---|---|
committer | Linux User <jordan@winter.local> | 2023-06-24 00:13:26 +0000 |
commit | 8cb2c53d2d01c13761627231e3d182002e3742d5 (patch) | |
tree | 3395c50eb6aabdeea20bcd07264c91b551af3de0 /tracker.0x7c0.com/update-stats.py | |
parent | 38c02e531cefaf218655fc3b51bf4a409416a96a (diff) | |
download | www-8cb2c53d2d01c13761627231e3d182002e3742d5.tar.gz www-8cb2c53d2d01c13761627231e3d182002e3742d5.zip |
Diffstat (limited to 'tracker.0x7c0.com/update-stats.py')
-rwxr-xr-x | tracker.0x7c0.com/update-stats.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tracker.0x7c0.com/update-stats.py b/tracker.0x7c0.com/update-stats.py new file mode 100755 index 0000000..2af62eb --- /dev/null +++ b/tracker.0x7c0.com/update-stats.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import fileinput +import os +import shutil +import sys +import urllib.request + +WWW = '/var/www/tracker.0x7c0.com' + +stats = dict.fromkeys(['torrents', 'connections', 'uptime']) + +conn = urllib.request.Request( + 'http://127.0.0.1:6969/stats?format=txt&mode=conn', +) +r = urllib.request.urlopen(conn).read().decode('utf-8').split('\n') + +stats['uptime'] = int(int(r[2].split()[0]) / 3600) +stats['connections'] = r[3].split()[2] + +conn = urllib.request.Request( + 'http://127.0.0.1:6969/stats?format=txt' +) + +r = urllib.request.urlopen(conn).read().decode('utf-8').split('\n') + +stats['torrents'] = r[2].split()[2] + +s = ( + f'The tracker has been up for {stats["uptime"]} hrs, ' + f'serving {stats["torrents"]} torrents at ' + f'{stats["connections"]} requests per second.\n' +) + +for line in fileinput.input([os.path.join(WWW, 'index.html')], inplace=True): + if line.strip().startswith('The tracker has been'): + line = s + sys.stdout.write(line) + +#import code +#code.interact(local=locals()) |