<commit_before>#!/usr/bin/env python

import re
import sys
import xmpp

from benderjab.benderjab import BenderFactory

def read_linux_uptime():
  """So I don't have to keep retyping /proc/loadavg
  """
  return open("/proc/loadavg", 'r').read()

def parse_uptime(loadavg):
  """
  parse loadavg for the 1,5,15 minute averages and the number of processes
  """
  loadavg = read_linux_uptime().split()
  one = float(loadavg[0])
  five = flaot(loadavg[1])
  fifteen = float(loadavg[2])
  process = loadavg[3]
  return (one,five,fifteen,process)

def parser(message, who=None):
  reply = ""
  try:
    if re.match("uptime", message):
      reply = parse_uptime(read_linux_uptime())
    elif re.match("time", message):
      reply = "Server time is "+time.asctime()
    else:
      reply = "Unknown command:", message
  except Exception, e:
    return "failed:"+str(e)
  return reply

class update_presence(object):
  def __init__(self):
    self.presence = ''
    
  def __call__(self, bot):
    loadavg = read_linux_uptime()
    one,five,fifteen,process = parse_uptime(loadavg)
    if one > 10.0:
      presence = 'xa'
    elif one > 5.0:
      presence = 'dnd'
    elif one > 1.0:
      presence = 'away'
    else:
      presence = ''
    if self.presence != presence
      self.presence = presence
      bot.cl.send(xmpp.Presence(typ=presence, show=loadavg))

def main(args=None):
  if len(args > 1):
    bot = BenderFactory(args[1])
  else:
    bot = BenderFactory()

  # lets not overload already overloaded systems, wait 5 seconds between
  # updates
  bot.timeout = 5
  bot.parser = parser
  bot.eventTasks.append(update_presence)
  bot.logon()
  bot.eventLoop()
  return 0

if __name__ == "__main__":
  sys.exit(main(sys.argv))<commit_msg>[project @ get sysmon working]<commit_after>#!/usr/bin/env python

import re
import sys
import xmpp

from benderjab.benderjab import BenderFactory

def read_linux_uptime():
  """So I don't have to keep retyping /proc/loadavg
  """
  return open("/proc/loadavg", 'r').read()

def parse_uptime(loadavg):
  """
  parse loadavg for the 1,5,15 minute averages and the number of processes
  """
  loadavg = read_linux_uptime().split()
  one = float(loadavg[0])
  five = float(loadavg[1])
  fifteen = float(loadavg[2])
  process = loadavg[3]
  return (one,five,fifteen,process)

def parser(message, who=None):
  reply = ""
  try:
    if re.match("uptime", message):
      reply = read_linux_uptime()
    elif re.match("time", message):
      reply = "Server time is "+time.asctime()
    else:
      reply = "Unknown command:", message
  except Exception, e:
    return "failed:"+str(e)
  return reply

class update_presence(object):
  def __init__(self):
    self.presence = ''
    
  def __call__(self, bot):
    loadavg = read_linux_uptime()
    one,five,fifteen,process = parse_uptime(loadavg)
    if one > 10.0:
      presence = 'xa'
    elif one > 5.0:
      presence = 'dnd'
    elif one > 1.0:
      presence = 'away'
    else:
      presence = ''
    print "presence:", presence, one
    if self.presence != presence:
      self.presence = presence
      bot.cl.send(xmpp.Presence(show=presence, status=loadavg))

def main(args=None):
  if args is not None and len(args) > 1:
    bot = BenderFactory(args[1])
  else:
    bot = BenderFactory()

  # lets not overload already overloaded systems, wait 5 seconds between
  # updates
  bot.parser = parser
  bot.eventTasks.append(update_presence())
  bot.logon()
  bot.eventLoop()
  return 0

if __name__ == "__main__":
  sys.exit(main(sys.argv))
{'fraction_non_alphanumeric': 0.1304101838755304, 'fraction_numerical': 0.011032531824611032, 'mean_word_length': 3.3870967741935485, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2309719', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1226, 'n_words': 311}