From 5aa60efce99962ddf31ecb8d2028be5bf1db0110 Mon Sep 17 00:00:00 2001 From: Richard Radics Date: Tue, 28 Feb 2017 00:19:25 +0100 Subject: [PATCH] Add cocoapod search command for cocoapod.org --- limbo/plugins/cocoapodplease.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 limbo/plugins/cocoapodplease.py diff --git a/limbo/plugins/cocoapodplease.py b/limbo/plugins/cocoapodplease.py new file mode 100644 index 00000000..8ed25753 --- /dev/null +++ b/limbo/plugins/cocoapodplease.py @@ -0,0 +1,28 @@ +"""!cocoapod returns search results from cocoapods.org""" +import re +import requests +import json + + +def cocoapods(q): + url = "http://search.cocoapods.org/api/pods?query={0}".format(q) + rawText = requests.get(url).text + data = json.loads(rawText) + + docs = data.get("allocations")[0][5] + result = '```' + + for x in docs: + result +='\'' + x + '\'\n' + + result += '```' + return result + + +def on_message(msg, server): + text = msg.get("text", "") + match = re.findall(r"!cocoapod (.*)", text) + if not match: + return + + return cocoapods(match[0]) \ No newline at end of file