-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cocoapod search command for cocoapod.org
- Loading branch information
1 parent
b2459c1
commit 5aa60ef
Showing
1 changed file
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""!cocoapod <parameter> 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]) |