From b4f8cbc5ef0ed871d1aad623245b8d9e495dc43b Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 4 Nov 2015 17:02:04 -0800 Subject: [PATCH] remove pointless things --- plugins/dotnetpad.py | 91 --------------------- plugins/gif.py | 21 ----- plugins/hackernews.py | 35 -------- plugins/mtg.py | 183 ------------------------------------------ plugins/vimeo.py | 14 ---- 5 files changed, 344 deletions(-) delete mode 100644 plugins/dotnetpad.py delete mode 100644 plugins/gif.py delete mode 100644 plugins/hackernews.py delete mode 100644 plugins/mtg.py delete mode 100644 plugins/vimeo.py diff --git a/plugins/dotnetpad.py b/plugins/dotnetpad.py deleted file mode 100644 index 7bbd220..0000000 --- a/plugins/dotnetpad.py +++ /dev/null @@ -1,91 +0,0 @@ -"dotnetpad.py: by sklnd, because gobiner wouldn't shut up" - -import urllib -import httplib -import socket -import json - -from util import hook - - -def dotnetpad(lang, code, timeout=30): - "Posts a provided snippet of code in a provided langugage to dotnetpad.net" - - code = code.encode('utf8') - params = urllib.urlencode({'language': lang, 'code': code}) - - headers = {"Content-type": "application/x-www-form-urlencoded", - "Accept": "text/plain"} - - try: - conn = httplib.HTTPConnection("dotnetpad.net", 80, timeout=timeout) - conn.request("POST", "/Skybot", params, headers) - response = conn.getresponse() - except httplib.HTTPException: - conn.close() - return 'error: dotnetpad is broken somehow' - except socket.error: - return 'error: unable to connect to dotnetpad' - - try: - result = json.loads(response.read()) - except ValueError: - conn.close() - return 'error: dotnetpad is broken somehow' - - conn.close() - - if result['Errors']: - return 'First error: %s' % (result['Errors'][0]['ErrorText']) - elif result['Output']: - return result['Output'].lstrip() - else: - return 'No output' - - -@hook.command -def fs(inp): - ".fs -- post a F# code snippet to dotnetpad.net and print the results" - - return dotnetpad('fsharp', inp) - - -@hook.command -def cs(snippet): - ".cs -- post a C# code snippet to dotnetpad.net and print the results" - - file_template = ('using System; ' - 'using System.Linq; ' - 'using System.Collections.Generic; ' - 'using System.Text; ' - '%s') - - class_template = ('public class Default ' - '{' - ' %s \n' - '}') - - main_template = ('public static void Main(String[] args) ' - '{' - ' %s \n' - '}') - - # There are probably better ways to do the following, but I'm feeling lazy - # if no main is found in the snippet, use the template with Main in it - if 'public static void Main' not in snippet: - code = main_template % snippet - code = class_template % code - code = file_template % code - - # if Main is found, check for class and see if we need to use the - # classed template - elif 'class' not in snippet: - code = class_template % snippet - code = file_template % code - - return 'Error using dotnetpad' - # if we found class, then use the barebones template - else: - code = file_template % snippet - - return dotnetpad('csharp', code) diff --git a/plugins/gif.py b/plugins/gif.py deleted file mode 100644 index d30537e..0000000 --- a/plugins/gif.py +++ /dev/null @@ -1,21 +0,0 @@ -import random - -from util import hook, http - - -@hook.api_key('giphy') -@hook.command('gif') -@hook.command -def giphy(inp, api_key=None): - '''.gif/.giphy -- returns first giphy search result''' - url = 'http://api.giphy.com/v1/gifs/search' - try: - response = http.get_json(url, q=inp, limit=10, api_key=api_key) - except http.HTTPError as e: - return e.msg - - results = response.get('data') - if results: - return random.choice(results).get('bitly_gif_url') - else: - return 'no results found' diff --git a/plugins/hackernews.py b/plugins/hackernews.py deleted file mode 100644 index 225e2cb..0000000 --- a/plugins/hackernews.py +++ /dev/null @@ -1,35 +0,0 @@ -import unittest - -from util import http, hook - - -@hook.regex(r'(?i)https://(?:www\.)?news\.ycombinator\.com\S*id=(\d+)') -def hackernews(match): - base_api = 'https://hacker-news.firebaseio.com/v0/item/' - entry = http.get_json(base_api + match.group(1) + ".json") - - if entry['type'] == "story": - entry['title'] = http.unescape(entry['title']) - return u"{title} by {by} with {score} points and {descendants} comments ({url})".format(**entry) - - if entry['type'] == "comment": - entry['text'] = http.unescape(entry['text'].replace('

', ' // ')) - return u'"{text}" -- {by}'.format(**entry) - -class Test(unittest.TestCase): - def news(self, inp): - re = hackernews._hook[0][1][1]['re'] - return hackernews(re.search(inp)) - - def test_story(self): - assert 'Desalination' in self.news('https://news.ycombinator.com/item?id=9943431') - - def test_comment(self): - res = self.news('https://news.ycombinator.com/item?id=9943987') - assert 'kilowatt hours' in res - assert 'oaktowner' in res - - def test_comment_encoding(self): - res = self.news('https://news.ycombinator.com/item?id=9943897') - assert 'abominations' in res - assert '> ' in res # encoding diff --git a/plugins/mtg.py b/plugins/mtg.py deleted file mode 100644 index 9c74deb..0000000 --- a/plugins/mtg.py +++ /dev/null @@ -1,183 +0,0 @@ -import re - -from util import hook, http - - -@hook.command -def mtg(inp): - ".mtg -- gets information about Magic the Gathering card " - - url = 'http://magiccards.info/query?v=card&s=cname' - h = http.get_html(url, q=inp) - - name = h.find('body/table/tr/td/span/a') - if name is None: - return "no cards found" - card = name.getparent().getparent().getparent() - - type = card.find('td/p').text.replace('\n', '') - - # this is ugly - text = http.html.tostring(card.xpath("//p[@class='ctext']/b")[0]) - text = text.replace('
', '$') - text = http.html.fromstring(text).text_content() - text = re.sub(r'(\w+\s*)\$+(\s*\w+)', r'\1. \2', text) - text = text.replace('$', ' ') - text = re.sub(r'\(.*?\)', '', text) # strip parenthetical explanations - text = re.sub(r'\.(\S)', r'. \1', text) # fix spacing - - printings = card.find('td/small').text_content() - printings = re.search(r'Editions:(.*)Languages:', printings).group(1) - printings = re.findall(r'\s*(.+?(?: \([^)]+\))*) \((.*?)\)', - ' '.join(printings.split())) - - printing_out = ', '.join('%s (%s)' % (set_abbrevs.get(x[0], x[0]), - rarity_abbrevs.get(x[1], x[1])) - for x in printings) - - name.make_links_absolute(base_url=url) - link = name.attrib['href'] - name = name.text_content().strip() - type = type.strip() - text = ' '.join(text.split()) - - return ' | '.join((name, type, text, printing_out, link)) - - -set_abbrevs = { - '15th Anniversary': '15ANN', - 'APAC Junior Series': 'AJS', - 'Alara Reborn': 'ARB', - 'Alliances': 'AI', - 'Anthologies': 'AT', - 'Antiquities': 'AQ', - 'Apocalypse': 'AP', - 'Arabian Nights': 'AN', - 'Arena League': 'ARENA', - 'Asia Pacific Land Program': 'APAC', - 'Battle Royale': 'BR', - 'Battle Royale Box Set': 'BRB', - 'Beatdown': 'BTD', - 'Beatdown Box Set': 'BTD', - 'Betrayers of Kamigawa': 'BOK', - 'Celebration Cards': 'UQC', - 'Champions of Kamigawa': 'CHK', - 'Champs': 'CP', - 'Chronicles': 'CH', - 'Classic Sixth Edition': '6E', - 'Coldsnap': 'CS', - 'Coldsnap Theme Decks': 'CSTD', - 'Conflux': 'CFX', - 'Core Set - Eighth Edition': '8E', - 'Core Set - Ninth Edition': '9E', - 'Darksteel': 'DS', - 'Deckmasters': 'DM', - 'Dissension': 'DI', - 'Dragon Con': 'DRC', - 'Duel Decks: Divine vs. Demonic': 'DVD', - 'Duel Decks: Elves vs. Goblins': 'EVG', - 'Duel Decks: Garruk vs. Liliana': 'GVL', - 'Duel Decks: Jace vs. Chandra': 'JVC', - 'Eighth Edition': '8ED', - 'Eighth Edition Box Set': '8EB', - 'European Land Program': 'EURO', - 'Eventide': 'EVE', - 'Exodus': 'EX', - 'Fallen Empires': 'FE', - 'Fifth Dawn': '5DN', - 'Fifth Edition': '5E', - 'Fourth Edition': '4E', - 'Friday Night Magic': 'FNMP', - 'From the Vault: Dragons': 'FVD', - 'From the Vault: Exiled': 'FVE', - 'Future Sight': 'FUT', - 'Gateway': 'GRC', - 'Grand Prix': 'GPX', - 'Guildpact': 'GP', - 'Guru': 'GURU', - 'Happy Holidays': 'HHO', - 'Homelands': 'HL', - 'Ice Age': 'IA', - 'Introductory Two-Player Set': 'ITP', - 'Invasion': 'IN', - 'Judge Gift Program': 'JR', - 'Judgment': 'JU', - 'Junior Series': 'JSR', - 'Legend Membership': 'DCILM', - 'Legends': 'LG', - 'Legions': 'LE', - 'Limited Edition (Alpha)': 'LEA', - 'Limited Edition (Beta)': 'LEB', - 'Limited Edition Alpha': 'LEA', - 'Limited Edition Beta': 'LEB', - 'Lorwyn': 'LW', - 'MTGO Masters Edition': 'MED', - 'MTGO Masters Edition II': 'ME2', - 'MTGO Masters Edition III': 'ME3', - 'Magic 2010': 'M10', - 'Magic Game Day Cards': 'MGDC', - 'Magic Player Rewards': 'MPRP', - 'Magic Scholarship Series': 'MSS', - 'Magic: The Gathering Launch Parties': 'MLP', - 'Media Inserts': 'MBP', - 'Mercadian Masques': 'MM', - 'Mirage': 'MR', - 'Mirrodin': 'MI', - 'Morningtide': 'MT', - 'Multiverse Gift Box Cards': 'MGBC', - 'Nemesis': 'NE', - 'Ninth Edition Box Set': '9EB', - 'Odyssey': 'OD', - 'Onslaught': 'ON', - 'Planar Chaos': 'PC', - 'Planechase': 'PCH', - 'Planeshift': 'PS', - 'Portal': 'PO', - 'Portal Demogame': 'POT', - 'Portal Second Age': 'PO2', - 'Portal Three Kingdoms': 'P3K', - 'Premium Deck Series: Slivers': 'PDS', - 'Prerelease Events': 'PTC', - 'Pro Tour': 'PRO', - 'Prophecy': 'PR', - 'Ravnica: City of Guilds': 'RAV', - 'Release Events': 'REP', - 'Revised Edition': 'RV', - 'Saviors of Kamigawa': 'SOK', - 'Scourge': 'SC', - 'Seventh Edition': '7E', - 'Shadowmoor': 'SHM', - 'Shards of Alara': 'ALA', - 'Starter': 'ST', - 'Starter 1999': 'S99', - 'Starter 2000 Box Set': 'ST2K', - 'Stronghold': 'SH', - 'Summer of Magic': 'SOM', - 'Super Series': 'SUS', - 'Tempest': 'TP', - 'Tenth Edition': '10E', - 'The Dark': 'DK', - 'Time Spiral': 'TS', - 'Time Spiral Timeshifted': 'TSTS', - 'Torment': 'TR', - 'Two-Headed Giant Tournament': 'THGT', - 'Unglued': 'UG', - 'Unhinged': 'UH', - 'Unhinged Alternate Foils': 'UHAA', - 'Unlimited Edition': 'UN', - "Urza's Destiny": 'UD', - "Urza's Legacy": 'UL', - "Urza's Saga": 'US', - 'Visions': 'VI', - 'Weatherlight': 'WL', - 'Worlds': 'WRL', - 'WotC Online Store': 'WOTC', - 'Zendikar': 'ZEN'} - -rarity_abbrevs = { - 'Land': 'L', - 'Common': 'C', - 'Uncommon': 'UC', - 'Rare': 'R', - 'Special': 'S', - 'Mythic Rare': 'MR'} diff --git a/plugins/vimeo.py b/plugins/vimeo.py deleted file mode 100644 index 6d0564d..0000000 --- a/plugins/vimeo.py +++ /dev/null @@ -1,14 +0,0 @@ -from util import hook, http - - -@hook.regex(r'vimeo.com/([0-9]+)') -def vimeo_url(match): - info = http.get_json('http://vimeo.com/api/v2/video/%s.json' - % match.group(1)) - - if info: - return ("\x02%(title)s\x02 - length \x02%(duration)ss\x02 - " - "\x02%(stats_number_of_likes)s\x02 likes - " - "\x02%(stats_number_of_plays)s\x02 plays - " - "\x02%(user_name)s\x02 on \x02%(upload_date)s\x02" - % info[0])