-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ranks, improved Redunda logging
- Implemented rank detection and mention of the last status (#11) - Improved the logging for Redunda so that the main thread and logging doesn't get blocked. Also, a bug which crashes the bot when Redunda isn't available was fixed (#13)
- Loading branch information
Showing
4 changed files
with
108 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
ranks = { | ||
"365": { | ||
"title": "A flag a day keeps bad posts away", | ||
"description": "One year has 365 days", | ||
"count": 365 | ||
}, | ||
"1111": { | ||
"title": "No badge needed", | ||
"description": "A number is prettier than a badge anyway!", | ||
"count": 1111 | ||
}, | ||
"2008": { | ||
"title": "Flag Overflow", | ||
"description": "Stack Overflow was created in 2008", | ||
"count": 2008 | ||
}, | ||
"10000": { | ||
"title": "Elite Squad", | ||
"description": "At one point of time, there were only 16 of us", | ||
"count": 10000 | ||
}, | ||
"11111": { | ||
"title": "Game of Flags", | ||
"description": "All elevens because the TV show Game of Thrones started in 2011", | ||
"count": 11111 | ||
}, | ||
"22656": { | ||
"title": "Almost Jon Skeet", | ||
"description": "22656 is his (John's) user ID", | ||
"count": 22656 | ||
}, | ||
"33333": { | ||
"title": "The Mad Flagger", | ||
"description": "Got nothing better to do with your time? ;D", | ||
"count": 33333 | ||
}, | ||
"42195": { | ||
"title": "The Marathon", | ||
"description": "Marathon's length in meters", | ||
"count": 42195 | ||
}, | ||
"65536": { | ||
"title": "The two to the sixteen", | ||
"description": None, | ||
"count": 65536 | ||
}, | ||
"101010": { | ||
"title": "Definitely a robot", | ||
"description": "42 in binary code. [Also 42 is the Answer to the Ultimate Question of Life, the Universe, and Everything](https://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#Answer_to_the_Ultimate_Question_of_Life,_the_Universe,_and_Everything_(42))", | ||
"count": 101010 | ||
}, | ||
"2147483647": { | ||
"title": "The Overflow", | ||
"description": "[Maximum size of a 32-bit integer](https://stackoverflow.com/a/94608)", | ||
"count": 2147483647 | ||
}, | ||
"4294967296": { | ||
"title": "A `long` journey", | ||
"description": None, | ||
"count": 4294967296 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
from threading import Thread | ||
from urllib import parse, request | ||
from time import localtime, strftime | ||
|
||
import json | ||
import time | ||
from urllib.error import URLError | ||
|
||
|
||
def pingRedunda(bot_version): | ||
data = parse.urlencode({"key": "19b558436329ff6eb8247bc21fdd2aaa1135597b5bb858a10e8eef2688b8565e", "version": bot_version}).encode() | ||
req = request.Request("https://redunda.sobotics.org/status.json", data) | ||
class RedundaThread(Thread): | ||
def __init__(self, event, bot_version, logging): | ||
Thread.__init__(self) | ||
self.stopped = event | ||
self.bot_version = bot_version | ||
self.logging = logging | ||
|
||
response = request.urlopen(req) | ||
def run(self): | ||
while not self.stopped.wait(60): | ||
self.pingRedunda() | ||
|
||
jsonReturned = json.loads(response.read().decode("utf-8")) | ||
def pingRedunda(self): | ||
try: | ||
data = parse.urlencode({"key": "19b558436329ff6eb8247bc21fdd2aaa1135597b5bb858a10e8eef2688b8565e", "version": self.bot_version}).encode() | ||
req = request.Request("https://redunda.sobotics.org/status.json", data) | ||
|
||
def continousPing(bot_version): | ||
while True: | ||
pingRedunda(bot_version) | ||
time.sleep(60) | ||
response = request.urlopen(req) | ||
|
||
jsonReturned = json.loads(response.read().decode("utf-8")) | ||
except (OSError, URLError) as e: | ||
current_timestamp = strftime("%Y-%m-%d %H:%M:%S", localtime()) | ||
self.logging.warn("Pinging Redunda failed at {} CET", current_timestamp) |