From 123201c70cb8923496dab174b33c0ee4fde6395c Mon Sep 17 00:00:00 2001 From: Roberto Anic Banic Date: Mon, 16 Oct 2017 15:40:23 +0000 Subject: [PATCH] Fix --- api/ApiResponse.py | 15 +++++++++++++++ api/ApiResult.py | 21 +++++++++++++++++++++ bot.py | 8 +------- 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 api/ApiResponse.py create mode 100644 api/ApiResult.py diff --git a/api/ApiResponse.py b/api/ApiResponse.py new file mode 100644 index 00000000..ba9f72a4 --- /dev/null +++ b/api/ApiResponse.py @@ -0,0 +1,15 @@ +import json + +import ApiResult + +class ApiResponse(object): + def __init__(self, data): + parsed_data = json.loads(data) + self.code = parsed_data["return_code"] + self.load_results(parsed_data["results"]) + + def load_results(self, data): + self.results = array() + for id, result_data in data: + self.results.append(ApiResult(id, result_data)) + diff --git a/api/ApiResult.py b/api/ApiResult.py new file mode 100644 index 00000000..d66b5619 --- /dev/null +++ b/api/ApiResult.py @@ -0,0 +1,21 @@ +from datetime import datetime.strptime, date.strftime + +class ApiResult(object): + def __init__(self, id, data): + self.id = id + self.title = data["title"] + self.status = data["status"] + self.date = strptime("%Y-%m-%d", data["date"]) + self.thread = data["thread"] + self.commit = data["commit"] + self.pr = data["pr"] + + def to_chat_string(self): + return "ID:{:9s} Title:{:40s} PR:{:4s} Status:{:8s} Updated:{:10s}".format( + self.id, + self.title, + self.pr, + self.status, + self.date, + strftime("%Y-%m-%d", self.date) + ) diff --git a/bot.py b/bot.py index 3c17501f..5e215cdb 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,4 @@ import discord -import asyncio import requests import re import urllib.parse @@ -13,12 +12,7 @@ rpcs3Bot = Bot(command_prefix="!") pattern = '[A-z]{4}\\d{5}' @rpcs3Bot.event - - -asyncio.async - - -def on_message(message): +async def on_message(message): if message.author.name == "RPCS3 Bot": return try: