remove pointless things

This commit is contained in:
Christine Dodrill 2015-11-04 17:02:04 -08:00
parent bb8e0c0abf
commit b4f8cbc5ef
5 changed files with 0 additions and 344 deletions

View File

@ -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)

View File

@ -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 <query> -- 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'

View File

@ -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('<p>', ' // '))
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

View File

@ -1,183 +0,0 @@
import re
from util import hook, http
@hook.command
def mtg(inp):
".mtg <name> -- gets information about Magic the Gathering card <name>"
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('<br>', '$')
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'}

View File

@ -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])