<commit_before>from datetime import timedelta
import pdb
import re
import logging
from django.utils.datetime_safe import datetime, time
from twitter import Twitter, OAuth, TwitterHTTPError
from bot.libraries.launchlibrarysdk import LaunchLibrarySDK
from bot.libraries.onesignalsdk import OneSignalSdk
from bot.models import Notification
from bot.utils.config import keys
from bot.utils.deserializer import json_to_model

# import the logging library

# Get an instance of a logger
logger = logging.getLogger('bot')

AUTH_TOKEN_HERE = keys['AUTH_TOKEN_HERE']
APP_ID = keys['APP_ID']
DAEMON_SLEEP = 6000


def update_notification_record(launch):
    notification = Notification.objects.get(launch=launch)
    notification.last_daily_digest_post = datetime.now()
    notification.last_net_stamp = launch.netstamp
    notification.last_net_stamp_timestamp = datetime.now()
    logger.info('Updating Notification %s to timestamp %s' % (notification.launch.id,
                                                              notification.last_daily_digest_post
                                                              .strftime("%A %d. %B %Y")))
    notification.save()


def daily_allowed():
    start_date = datetime.today() - timedelta(1)
    end_date = datetime.today()
    notifications = Notification.objects.filter(last_daily_digest_post__range=(start_date, end_date))
    for notification in notifications:
        logger.debug('Time since Digest - %s seconds' % (datetime.now() - notification.last_daily_digest_post)
                     .total_seconds())
        if (datetime.now() - notification.last_daily_digest_post).total_seconds() < 80000:
            return False
    return True


class DailyDigestServer:
    def __init__(self, debug=None, version=None):
        self.one_signal = OneSignalSdk(AUTH_TOKEN_HERE, APP_ID)
        if version is None:
            version = '1.2.1'
        self.launchLibrary = LaunchLibrarySDK(version=version)
        if debug is None:
            self.DEBUG = False
        else:
            self.DEBUG = debug<commit_msg>Improve logic for determining if daily is allowed.<commit_after>from datetime import timedelta
import pdb
import re
import logging
from django.utils.datetime_safe import datetime, time
from twitter import Twitter, OAuth, TwitterHTTPError
from bot.libraries.launchlibrarysdk import LaunchLibrarySDK
from bot.libraries.onesignalsdk import OneSignalSdk
from bot.models import Notification
from bot.utils.config import keys
from bot.utils.deserializer import json_to_model

# import the logging library

# Get an instance of a logger
logger = logging.getLogger('bot')

AUTH_TOKEN_HERE = keys['AUTH_TOKEN_HERE']
APP_ID = keys['APP_ID']
DAEMON_SLEEP = 6000


def update_notification_record(launch):
    notification = Notification.objects.get(launch=launch)
    notification.last_daily_digest_post = datetime.now()
    notification.last_net_stamp = launch.netstamp
    notification.last_net_stamp_timestamp = datetime.now()
    logger.info('Updating Notification %s to timestamp %s' % (notification.launch.id,
                                                              notification.last_daily_digest_post
                                                              .strftime("%A %d. %B %Y")))
    notification.save()


def daily_allowed():
    start_date = datetime.today() - timedelta(1)
    end_date = datetime.today()
    notifications = Notification.objects.filter(last_daily_digest_post__range=(start_date, end_date))
    if any((datetime.now() - notification.last_daily_digest_post).total_seconds() < 80000
           for notification in notifications):
        return False
    else:
        return True


class DailyDigestServer:
    def __init__(self, debug=None, version=None):
        self.one_signal = OneSignalSdk(AUTH_TOKEN_HERE, APP_ID)
        if version is None:
            version = '1.2.1'
        self.launchLibrary = LaunchLibrarySDK(version=version)
        if debug is None:
            self.DEBUG = False
        else:
            self.DEBUG = debug
{'fraction_non_alphanumeric': 0.07991093518060366, 'fraction_numerical': 0.006432459178624443, 'mean_word_length': 3.0309072781655035, 'pattern_counts': {'":': 0, '<': 5, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5965409', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1089, 'n_words': 275}