From Scanty Matamata, 1 Week ago, written in Plain Text.
  1. # "THE BEER-WARE LICENSE" (Revision 42):
  2. # <notphillid@emailisbloat.example.com> wrote this file. As long as you
  3. # retain this notice you can do whatever you want with this stuff.
  4. # If we meet some day, and you think this stuff is worth it,
  5. # you can buy me a beer in return.
  6.  
  7.  
  8. import subprocess
  9. import urllib
  10.  
  11. from supybot import utils, plugins, ircutils, callbacks
  12. from supybot.commands import *
  13. try:
  14.     from supybot.i18n import PluginInternationalization
  15.     _ = PluginInternationalization('AwkTube')
  16. except ImportError:
  17.     # Placeholder that allows to run the plugin on a bot
  18.     # without the i18n module
  19.     _ = lambda x: x
  20.  
  21.  
  22. class AwkTube(callbacks.Plugin):
  23.     """Lookup dem dere yoooootooob vidjyers and print url and title.
  24.     Uses system() with awk and curl. Python is dumb."""
  25.  
  26.     def __init__(self, irc):
  27.         self.__parent = super(AwkTube, self)
  28.         self.__parent.__init__(irc)
  29.  
  30.     def yt(self, irc, msg, args, query):
  31.         """Fur der fingerpokken das youtube.com und die mittengrabben dein vidjeo. Don't be silly, `curl | awk` is great html parser!"""
  32.  
  33.         awkcmd = " 'BEGIN{while((\"curl -s https://www.youtube.com/results?q=\"q |& getline)>0) {if($0 ~ /description-id/) {print  $2 \" :: \" $8; exit}} }'"
  34.         call = "awk  -F '\"' -v RS=\"href\" -v ORS='' -v q=" + urllib.quote(str(query)) + awkcmd
  35.  
  36.         # TODO: lol errors? what are those
  37.         result = "https://www.youtube.com" + subprocess.check_output(call, shell=True)
  38.  
  39.         irc.reply(result)
  40.  
  41.     # define a name to use as command. or.. tie it to a value or smth? fk knows. python why.
  42.     yt = wrap(yt, [many('anything')])
  43.  
  44.  
  45. Class = AwkTube
captcha