Open ha1f3mpty opened 8 years ago
I have the same issue. I have three thresholds, listed in ascending order in the .json file, and the {downloadResult} mismatches to the threshold values and then 'tweets' the wrong message.
},
"tweetTo": "@telstra",
"internetSpeed": "18",
"tweetThresholds": {
"4": [
"{tweetTo} {downloadResult}Mbit/s? Please get me back up to speed ({internetspeed}Mbit/s)!"
],
"12": [
"{tweetTo} {downloadResult}Mbit/s is OK, but I would rather be getting the {internetSpeed}Mbit/s that I'm supposed to get"
],
"16": [
"{tweetTo} {downloadResult}Mbit/s vs. {internetSpeed}Mbit/s - nice job!"
]
},
Im having the same issue. The messages are not correct compare to the download result. Always is using the last one.
Bump, you need to add a break inside this if statement:
if speedTestResults['downloadResult'] < threshold: message = messages[random.randint(0, len(messages) - 1)].replace('{tweetTo}', self.config['tweetTo']).replace('{internetSpeed}', self.config['internetSpeed']).replace('{downloadResult}', str(speedTestResults['downloadResult'])) break
A smarter solution would actually be to have a min variable such that if you find a threshold value < minThreshold then you update the message object. minThreshold is initialized as 10000 or something. Therefore the code would look something like this:
minThreshold = 10000 if speedTestResults['downloadResult'] < threshold and threshold < minThreshold: minThreshold = threshold message = messages[random.randint(0, len(messages) - 1)].replace('{tweetTo}', self.config['tweetTo']).replace('{internetSpeed}', self.config['internetSpeed']).replace('{downloadResult}', str(speedTestResults['downloadResult']))
First off, thanks for this and I do not have any issues with how this runs. I think i just need to have a better understanding. I have been able to successfully modify the config.json file to fit my needs with "tweetTo", "internetSpeed", and "tweetThresholds". I say successful because the thing sucessfully tweets the different messages. My "issue" is that it doesn't tweet the right message based on tweetThresholds, well not the one I expect.
Here is the scenario; the Internet through put I pay for is 100 Mbps / 10 Mbps down/up respectively. I set tweetThresholds of 10, 25, 50, and 80 which tweet out some words along with a hashtag of EpicFail, Fail, OK, and Congrats respectively. Lately my connection has been decent, between 60 and 79. I point out the 79 because my highest in the last 5 days was 79.92 all of which had the highest tweet of Congrats, which should be reserved for 80 Mbps and up. I also had a 5 day low of 56.14 Mbps and it also got the highest tweet of Congrats. It feels like no matter what the "internetSpeed" is at it tweets the highest level tweet. I modified the speedcomplainer script file to tweak the number of seconds that the complainer should tweet so it will be about 3.3 days between tweets. Any help is appreciated, below are the content of my files. I tried to use the insert code option but it still broke it up so I put it in just as text, sorry. I would have attached files but thats not an option.
Here is my config.json file with my twitter account specifics removed for privacy:
{
} `
And here is the speedcomplainer file:
import os import sys import time from datetime import datetime import daemon import signal import threading import twitter import json import random from logger import Logger
shutdownFlag = False
def main(filename, argv): print "======================================" print " Starting Speed Complainer! " print " Lets get noisy! " print "======================================"
def shutdownHandler(signo, stack_frame): global shutdownFlag print 'Got shutdown signal (%s: %s).' % (signo, stack_frame) shutdownFlag = True
class Monitor(): def init(self): self.lastPingCheck = None self.lastSpeedTest = None
class PingTest(threading.Thread): def init(self, numPings=3, pingTimeout=2, maxWaitTime=6): super(PingTest, self).init() self.numPings = numPings self.pingTimeout = pingTimeout self.maxWaitTime = maxWaitTime self.config = json.load(open('./config.json')) self.logger = Logger(self.config['log']['type'], { 'filename': self.config['log']['files']['ping'] })
class SpeedTest(threading.Thread): def init(self): super(SpeedTest, self).init() self.config = json.load(open('./config.json')) self.logger = Logger(self.config['log']['type'], { 'filename': self.config['log']['files']['speed'] })
class DaemonApp(): def init(self, pidFilePath, stdout_path='/dev/null', stderr_path='/dev/null'): self.stdin_path = '/dev/null' self.stdout_path = stdout_path self.stderr_path = stderr_path self.pidfile_path = pidFilePath self.pidfile_timeout = 1
if name == 'main': main(file, sys.argv[1:])