コード例 #1
0
ファイル: repost.py プロジェクト: freephys/mylab
def getfile(fname):
    with open(fname, 'r') as f:
        for line in reversed(f.readlines()):
            if len(line) < 2:
                continue
            count, userid, user, id, txt = line.split(' ', 4)
            yield int(count), int(userid), tounicode(user), tounicode(txt.strip('\n'))
コード例 #2
0
ファイル: head.py プロジェクト: chfr/spiffy
def title(self, input):
    """Fetches the contents of the <title> tag of a web page"""
    url = input.args.strip()
    
    if not url: 
        try:
            url = self.lasturl[input.sender.lower()]
        except KeyError:
            self.reply("No URLs posted previously and none given, nothing I can do.")
            return
    
    m = re.search(r"^https?://", url, re.I)
    if not m:
        url = "http://" + url
       
    self.lasturl[input.sender.lower()] = url       

       
    try:
        page = tounicode(urllib2.urlopen(url).read())
        title = re.search('<title>(.*?)</title>', page, re.I | re.MULTILINE | re.DOTALL)
        if not title:
            self.say("Page has no title tag!")
            return
        self.say("\x02Title:\x02 %s" % decodehtml(title.group(1).replace("\n","")))
    except urllib2.URLError, e:
        self.say('Error: Invalid url.')
コード例 #3
0
ファイル: head.py プロジェクト: chfr/spiffy
def autotitle(self, input):
    """Automatically shows the title for specified sites"""

    if hasattr(self.bot,"pluginstorage_at"):
        self.storage = self.bot.pluginstorage_at
    else:
        self.say("Patterns not loaded, hopefully this should never happen")

    matches = re.findall(r"(https?://[^ ]+|www\.[^ ]+)", input.args, re.I)
    if not matches:
       return

    for m in matches:
        url = m.encode('utf-8')
        if not url.startswith("http"):
            url = "http://" + url

        for p in self.storage["autotitle"]:
            if re.search(p, url, re.I):
                try:
                    page = tounicode(urllib2.urlopen(url).read())
                    title = re.search('<title>(.*?)</title>', page, re.I | re.MULTILINE | re.DOTALL)
                    if not title:
                        self.say("Page has no title tag!")
                        return
                    title = decodehtml(title.group(1).replace("\n","")).strip()
                    title = re.sub(r"\s+", " ", title)
                    self.say("\x02Title:\x02 %s" % title)
                except urllib2.URLError, e:
                    self.say('Error: Invalid url.')
コード例 #4
0
ファイル: bot.py プロジェクト: s3/spiffy
    def msg(self, receiver, message):

        # "It's easier to ask forgiveness than it is to get permission"
        # ...meaning that we force the message into a string!
        message = tounicode(message)

        lines = message.split("\n")
        for line in lines:
            self.logger.log(self.me, 'PRIVMSG', [receiver], line)
            self.sendLine("PRIVMSG %s :%s" % (receiver, line))
コード例 #5
0
ファイル: bot.py プロジェクト: s3/spiffy
 def lineReceived(self, line):
     self.lastmsg = time.mktime(time.gmtime())
     line = lowDequote(line)
     line = tounicode(line)
     try:
         prefix, command, params, text = self.parsemsg(line)
         if numeric_to_symbolic.has_key(command):
             command = numeric_to_symbolic[command]
         self.handleCommand(command, prefix, params, text, line)
     except Exception, e:
         self._print("Error: %s" % e, 'err')
         print traceback.format_exc()
コード例 #6
0
ファイル: head.py プロジェクト: s3/spiffy
def title(self, input):
   "Fetches the contents of the <title> tag of a web page"
   url = input.args
   
   if not url.strip() and hasattr(self, 'last_seen_url'): 
      try:
         url = self.last_seen_url[input.sender]
      except KeyError:
         self.reply("Failed spectacularly, try again later!")
         return
   elif not url.strip() and not hasattr(self, "last_seen_url"):
      self.reply("No URLs posted previously and none given, nothing I can do.")
      return
   
   if not "http://" in url:
      url = "http://" + url
      
   if hasattr(self, "last_seen_url"):
      self.last_seen_url[input.sender] = url
      
   page = tounicode(urllib2.urlopen(url).read())
   
   title = re.search('<title>(.*?)</title>', page, re.I).group(1)
   self.say("\x02Title:\x02 %s" % title)
コード例 #7
0
ファイル: bot.py プロジェクト: s3/spiffy
 def notice(self, receiver, message):
     message = tounicode(message)
     lines = message.split("\n")
     for line in lines:
         self.logger.log(self.me, 'NOTICE', [receiver], line)
         self.sendLine("NOTICE %s :%s" % (receiver, line))