Simple log file capability added

This commit is contained in:
David Forbes 2016-07-12 21:52:01 +01:00
parent 7b09d8759f
commit 401e509ba9
1 changed files with 23 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import socket
import timeit
import platform
import threading
import datetime
__version__ = '0.3.4'
@ -593,6 +594,8 @@ def speedtest():
parser.add_argument('--version', action='store_true',
help='Show the version number and exit')
parser.add_argument('--log', help='Specify a log file to append results to')
options = parser.parse_args()
if isinstance(options, tuple):
args = options[0]
@ -785,6 +788,26 @@ def speedtest():
(scheme, resultid[0]))
if args.log:
log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()),
'%0.2f'%(dlspeed /1000000 * 8), #Always megabits
'%0.2f'%(ulspeed /1000000 * 8),
config['client']['isp'],
config['client']['ip'],
'%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best
]
if args.share:
log_output.append('%s://www.speedtest.net/result/%s.png' % (scheme, resultid[0]))
fresh_file = not os.path.isfile(args.log)
with open(args.log, "a") as log_file:
if fresh_file:
log_file.write("Date,download,upload,isp,ip,sponsor,location,distance,latency,share link")
log_file.write("%s\n" % ",".join(log_output))
def main():
try:
speedtest()