<commit_before>from halibot import HalModule
from datetime import datetime, timedelta
from pytz import timezone, UnknownTimeZoneError
import json

def is_valid_tz(tz):
    try:
        timezone(tz)
        return True
    except UnknownTimeZoneError:
        return False

def time_for(tz):
    return str(timezone(tz).localize(datetime.utcnow()))

TZLINK = 'https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'

class TZ(HalModule):
    def init(self):
        self.dbpath = self.config['tz-path']
        self.load()

    def load(self):
        try:
            with open(self.dbpath, 'r') as f:
                self.users = json.loads(f.read())
        except FileNotFoundError:
            self.users = {}
            self.save()
    
    def save(self):
        with open(self.dbpath, 'w') as f:
            f.write(json.dumps(self.users))

    def receive(self, msg):
        words = msg.body.split(' ')
        cmd = words[0]
        
        if cmd != '!tz':
            return

        if len(words) == 2:
            if words[1] in self.users:
                self.reply(msg, body=time_for(self.users[words[1]]))
            else:<commit_msg>try formatting strings close to correctly<commit_after>from halibot import HalModule
from datetime import datetime, timedelta
from pytz import timezone, UnknownTimeZoneError
import json

def is_valid_tz(tz):
    try:
        timezone(tz)
        return True
    except UnknownTimeZoneError:
        return False

FMT = '%Y-%m-%d %H:%M:%S %Z%z'

def time_for(tz):
    return timezone(tz).localize(datetime.utcnow()).strftime(FMT)


TZLINK = 'https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'

class TZ(HalModule):
    def init(self):
        self.dbpath = self.config['tz-path']
        self.load()

    def load(self):
        try:
            with open(self.dbpath, 'r') as f:
                self.users = json.loads(f.read())
        except FileNotFoundError:
            self.users = {}
            self.save()
    
    def save(self):
        with open(self.dbpath, 'w') as f:
            f.write(json.dumps(self.users))

    def receive(self, msg):
        words = msg.body.split(' ')
        cmd = words[0]
        
        if cmd != '!tz':
            return

        if len(words) == 2:
            if words[1] in self.users:
                self.reply(msg, body=time_for(self.users[words[1]]))
            else:
{'fraction_non_alphanumeric': 0.12197159565580618, 'fraction_numerical': 0.003341687552213868, 'mean_word_length': 2.094315245478036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1925823', 'n_tokens_mistral': 779, 'n_tokens_neox': 759, 'n_words': 172}