<commit_before>#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_STATUS_URL, BYTEBOT_TOPIC, BYTEBOT_CHANNEL
from urllib         import urlopen

import json

class autotopic(Plugin):

    def minuteCron(self, irc):
        try:
            irc.topic(BYTEBOT_CHANNEL)
            old_topic = irc.current_topic

            topic = BYTEBOT_TOPIC
            response = urlopen(BYTEBOT_STATUS_URL)
            data = json.loads(response.read())
            if data['state']['open']:
                topic += u' | Space is open (' + unicode(data['state']['message']) + ')'
            else:
                topic += u' | Space is closed'

            if old_topic[2] != unicode(topic).encode('utf-8', errors='replace'):
                irc.topic(BYTEBOT_CHANNEL, unicode(topic).encode('utf-8', errors='replace'))
        except Exception as e:
            print("Error while setting topic")<commit_msg>Fixed topic check<commit_after>#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_STATUS_URL, BYTEBOT_TOPIC, BYTEBOT_CHANNEL
from urllib         import urlopen

import json
import re

class autotopic(Plugin):

    def minuteCron(self, irc):
        try:
            irc.topic(BYTEBOT_CHANNEL)
            old_topic = irc.current_topic

            topic = BYTEBOT_TOPIC
            response = urlopen(BYTEBOT_STATUS_URL)
            data = json.loads(response.read())
            if data['state']['open'] == True:
                topic += u' | Space is open'
                status = 'open'
            else:
                topic += u' | Space is closed'
                status = 'closed'

            try:
                old_status = re.search('Space is (open|closed)', old_topic[2])
                old_status = old_status.group(1)
            except Exception as e:
                old_status = "closed"

            if old_status != status:
                irc.topic(BYTEBOT_CHANNEL, unicode(topic).encode('utf-8', errors='replace'))
        except Exception as e:
            print(e)
            print("Error while setting topic")
{'fraction_non_alphanumeric': 0.10931734317343174, 'fraction_numerical': 0.004612546125461255, 'mean_word_length': 2.0293296089385473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '470966', 'n_tokens_mistral': 644, 'n_tokens_neox': 615, 'n_words': 149}