<commit_before>import datetime
import uuid

import jsonpickle
import skygear
from skygear.container import SkygearContainer
from skygear.utils.context import current_user_id
from skygear.utils import db
from skygear import pubsub
from psycopg2.extensions import AsIs


container = SkygearContainer()
container.api_key = "my_skygear_key"
container.app_name = "my_skygear_app"
schema_name = "app_%s" % container.app_name


class SkygearChatException(Exception):
    pass


@skygear.before_save("conversation", async=False)
def handle_conversation_before_save(record, original_record, conn):
    if len(record['participant_ids']) == 0:
        raise SkygearChatException("no participants")

    if len(record['admin_ids']) == 0 and not record.get('is_direct_message'):
        raise SkygearChatException("no admin assigned")

    if original_record is not None:
        if current_user_id() not in original_record['admin_ids']:
            raise SkygearChatException("no permission to edit conversation")

    if original_record is None and record.get('is_direct_message'):
        if current_user_id() not in record['participant_ids']:
            raise SkygearChatException(
                "cannot create direct conversations for other users")

        if len(record['participant_ids']) != 2:
            raise SkygearChatException(
                "direct message must only have two participants")

        record['admin_ids'] = []

<commit_msg>Respect envvar on setting the skygear container<commit_after>import os
import datetime
import uuid

import jsonpickle
import skygear
from skygear.container import SkygearContainer
from skygear.utils.context import current_user_id
from skygear.utils import db
from skygear import pubsub
from psycopg2.extensions import AsIs


container = SkygearContainer()
container.api_key = os.getenv('API_KEY', "my_skygear_key")
container.app_name = os.getenv('APP_NAME', "my_skygear_app")
schema_name = "app_%s" % container.app_name


class SkygearChatException(Exception):
    pass


@skygear.before_save("conversation", async=False)
def handle_conversation_before_save(record, original_record, conn):
    if len(record['participant_ids']) == 0:
        raise SkygearChatException("no participants")

    if len(record['admin_ids']) == 0 and not record.get('is_direct_message'):
        raise SkygearChatException("no admin assigned")

    if original_record is not None:
        if current_user_id() not in original_record['admin_ids']:
            raise SkygearChatException("no permission to edit conversation")

    if original_record is None and record.get('is_direct_message'):
        if current_user_id() not in record['participant_ids']:
            raise SkygearChatException(
                "cannot create direct conversations for other users")

        if len(record['participant_ids']) != 2:
            raise SkygearChatException(
                "direct message must only have two participants")

        record['admin_ids'] = []


{'fraction_non_alphanumeric': 0.08520630660852063, 'fraction_numerical': 0.0026836632002683663, 'mean_word_length': 4.18608695652174, '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': '6573667', 'n_tokens_mistral': 872, 'n_tokens_neox': 838, 'n_words': 234}