<commit_before>import irclib
import signal
import sys
import time
from pyinotify import WatchManager, ThreadedNotifier, ProcessEvent, IN_CLOSE_WRITE
import os
from tweepy import OAuthHandler, API, TweepError, debug
from configobj import ConfigObj
import re
import random
import feedparser

#irclib.DEBUG = True

MIN_IRC_ANC = 2000
MIN_TWIT_ANC = 8000

FILE111 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v111.txt"
FILE100 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v100.txt"
FILE120p3 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v120p3.txt"
FILE120p4 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v120p4.txt"
FILE120p6 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v120p6.txt"

LOCDIR = "/var/lib/adom/tmp/player_locations"

config = ConfigObj('/var/lib/adom/etc/config')

CONSUMER_KEY = config.get("CONSUMER_KEY")
CONSUMER_SECRET = config.get("CONSUMER_SECRET")
ACCESS_KEY = config.get("ACCESS_KEY")
ACCESS_SECRET = config.get("ACCESS_SECRET")

ANCTOIRC = config.as_bool('ANNOUNCE_TO_IRC')
ANCTOTWIT = config.as_bool("ANNOUNCE_TO_TWITTER")
READTWIT = config.as_bool("READ_TWEETS")
ANCRSS = config.as_bool("READ_RSS")
URL = config.get("RSSURL")

#try to set up twitter
if ANCTOTWIT == True or READTWIT == True:
  try:
      auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
      auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
      api = API(auth)
  except TweepError as e:
      print "Error: could not set up OAuth. {0}".format(e)

items = None
#set up RSS
if ANCRSS == True:
  print "Checking RSS ... "
  feed = feedparser.parse(URL)
  items = set(sorted(feed[ "items" ], key=lambda entry: entry["date_parsed"]))

maxseen = 0
#Start reading tweets
if READTWIT == True:
  print "Reading tweets ... "
  try:
    tbtweets = api.user_timeline("thomas_biskup")
    for key in tbtweets:
      if key.id > maxseen:
        maxseen = key.id

  except TweepError as e:
    print "Error: Could not retrieve tweets. {0}".format(e)

def signal_handler(signal, frame):
    print "Received signal {0}".format(signal)
    notifier.stop()
    notifierloc.stop()
    s.quit("Augh!")
    sys.exit(1)

signal.signal(signal.SIGTERM, signal_handler) 
signal.signal(signal.SIGINT, signal_handler)

def tweet(version, text):
    if ANCTOTWIT != 1:
      return

    m = re.match('(.*?)\. (L\d{0,1}.*?) \((M|F)\)\. \d+ xps\. \d+ turns?\. (.*?)\. (Rank: #\d{0,3}), score (\d+)',text)

    raceclass = m.group(2)
    score = int(m.group(6))
    if score <= MIN_TWIT_ANC:
        return

    mapping = [ ('drakish ', 'Dr'), ('dwarven ','Dw'), ('dark elven ', 'De'), ('gray elven ', 'Ge'), ('high elven ', 'He'), ('gnomish ','Gn'), ('human ','Hm'), ('hurthling ', 'Hr'), ('orcish ','Or'), ('trollish ','Tr'), ('archer','Ar'), ('assassin','As'), ('barbarian','Bb'), ('bard','Br'), ('beastfighter','Bf'), ('druid','Dr'), ('elementalist','El'), ('farmer','Fa'), ('fighter','Fi'), ('healer','He'), ('merchant','Me'), ('mindcrafter','Mi'), ('monk','Mo'), ('necromancer','Ne'), ('paladin','Pa'), ('priest','Pr'), ('ranger','Ra'), ('thief','Th'), ('weaponsmith','We'), ('wizard','Wz') ]
<commit_msg>support new races & classes in adombot<commit_after>import irclib
import signal
import sys
import time
from pyinotify import WatchManager, ThreadedNotifier, ProcessEvent, IN_CLOSE_WRITE
import os
from tweepy import OAuthHandler, API, TweepError, debug
from configobj import ConfigObj
import re
import random
import feedparser

#irclib.DEBUG = True

MIN_IRC_ANC = 2000
MIN_TWIT_ANC = 8000

FILE111 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v111.txt"
FILE100 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v100.txt"
FILE120p3 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v120p3.txt"
FILE120p4 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v120p4.txt"
FILE120p6 = "/var/lib/adom/public_html/adom_hiscore/hiscore_v120p6.txt"

LOCDIR = "/var/lib/adom/tmp/player_locations"

config = ConfigObj('/var/lib/adom/etc/config')

CONSUMER_KEY = config.get("CONSUMER_KEY")
CONSUMER_SECRET = config.get("CONSUMER_SECRET")
ACCESS_KEY = config.get("ACCESS_KEY")
ACCESS_SECRET = config.get("ACCESS_SECRET")

ANCTOIRC = config.as_bool('ANNOUNCE_TO_IRC')
ANCTOTWIT = config.as_bool("ANNOUNCE_TO_TWITTER")
READTWIT = config.as_bool("READ_TWEETS")
ANCRSS = config.as_bool("READ_RSS")
URL = config.get("RSSURL")

#try to set up twitter
if ANCTOTWIT == True or READTWIT == True:
  try:
      auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
      auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
      api = API(auth)
  except TweepError as e:
      print "Error: could not set up OAuth. {0}".format(e)

items = None
#set up RSS
if ANCRSS == True:
  print "Checking RSS ... "
  feed = feedparser.parse(URL)
  items = set(sorted(feed[ "items" ], key=lambda entry: entry["date_parsed"]))

maxseen = 0
#Start reading tweets
if READTWIT == True:
  print "Reading tweets ... "
  try:
    tbtweets = api.user_timeline("thomas_biskup")
    for key in tbtweets:
      if key.id > maxseen:
        maxseen = key.id

  except TweepError as e:
    print "Error: Could not retrieve tweets. {0}".format(e)

def signal_handler(signal, frame):
    print "Received signal {0}".format(signal)
    notifier.stop()
    notifierloc.stop()
    s.quit("Augh!")
    sys.exit(1)

signal.signal(signal.SIGTERM, signal_handler) 
signal.signal(signal.SIGINT, signal_handler)

def tweet(version, text):
    if ANCTOTWIT != 1:
      return

    m = re.match('(.*?)\. (L\d{0,1}.*?) \((M|F)\)\. \d+ xps\. \d+ turns?\. (.*?)\. (Rank: #\d{0,3}), score (\d+)',text)

    raceclass = m.group(2)
    score = int(m.group(6))
    if score <= MIN_TWIT_ANC:
        return

    mapping = [ ('drakish ', 'Dr'), ('dwarven ','Dw'), ('dark elven ', 'De'), ('gray elven ', 'Ge'), ('high elven ', 'He'), ('gnomish ','Gn'), ('human ','Hm'), ('hurthling ', 'Hr'), ('orcish ','Or'), ('trollish ','Tr'), ('ratling','Rt'), ('mist elven','Me'), ('archer','Ar'), ('assassin','As'), ('barbarian','Bb'), ('bard','Br'), ('beastfighter','Bf'), ('druid','Dr'), ('elementalist','El'), ('farmer','Fa'), ('fighter','Fi'), ('healer','He'), ('merchant','Me'), ('mindcrafter','Mi'), ('monk','Mo'), ('necromancer','Ne'), ('paladin','Pa'), ('priest','Pr'), ('ranger','Ra'), ('thief','Th'), ('weaponsmith','We'), ('wizard','Wz'), ('chaos Knight','Ck') ]

{'fraction_non_alphanumeric': 0.19051408562788477, 'fraction_numerical': 0.017825879356995065, 'mean_word_length': 4.786372007366483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1630897', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2434, 'n_words': 494}