<gh_stars>0
"""
Django settings for ohmyrss project.

Generated by 'django-admin startproject' using Django 2.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

from redislite import Redis



# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<PASSWORD> secret'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = [
    '127.0.0.1',
    'reiwarss.pythonanywhere.com',
    'http://reiwarss.pythonanywhere.com/',
    'www.reiwarss.pythonanywhere.com',
]

# Application definition

INSTALLED_APPS = [
    'django_crontab',
    'web.apps.WebConfig',
    "django_cron",

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'web.middlewares.StatsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'ohmyrss.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'tmpl')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.static',
            ],
        },
    },
]

WSGI_APPLICATION = 'ohmyrss.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'reiwarss.sqlite3'),
        #'ENGINE':'django.db.backends.mysql',
        #'NAME':'reiwarss',
        #'USER':'root',
        #'HOST':'',
        #'PORT':'',
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Tokyo'

USE_I18N = True

USE_L10N = True

USE_TZ = True



CRONJOBS = [
   ('1 0-23 * * *', 'web.cron.update_all_user_feed'),
   ('*/5 * * * *', 'web.djangocron.my_sheduled_job'),

   ('*/30 * * * *', 'web.djangocron.my_sheduled_30minjob'),
   ('*/60 * * * *', 'web.djangocron.my_sheduled_60minjob'),
   #('*/1 * * * *', 'web.cron.update_all_user_feed', '>>' +os.path.join(BASE_DIR,'log/debug7.log')),
   ('11 3 * * *', 'web.cron.clean_history_data')
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/assets/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "assets"),
]

# redis service
REDIS_HOST = '127.0.0.1'
REDIS_PORT = '6379'

# for scrapy use db
REDIS_FEED_DB = 0
# for web use db
REDIS_WEB_DB = 1

# crete a redis instance using redislite
REDIS_DB_PATH = os.path.join(BASE_DIR, 'my_redis.db')
#rdb = Redis(REDIS_DB_PATH)
#REDIS_SOCKET_PATH = 'redis+socket://%s' % (rdb.socket_file, )
#BROKER_URL = REDIS_SOCKET_PATH



# page view count, thumb count, open page count
REDIS_VIEW_KEY = 'VIEW/%s'
REDIS_THUMB_KEY = 'THUMB/%s'
REDIS_OPEN_KEY = 'OPEN/%s'

# for dashboard statistics
REDIS_WEEK_KEY = 'WEEK/%s'
REDIS_VISIT_KEY = 'VISIT/%s/%s'
REDIS_UV_ALL_KEY = 'UV/ALL/%s'
REDIS_UV_NEW_KEY = 'UV/NEW/%s'

# http referer
REDIS_REFER_ALL_KEY = 'REFER/ALL'
REDIS_REFER_PV_KEY = 'REFER/%s'
REDIS_REFER_PV_DAY_KEY = 'REFER/%s/%s'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'web': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
    },
}

"""
Django settings for ohmyrss project.

Generated by 'django-admin startproject' using Django 2.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

from redislite import Redis



# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<PASSWORD> secret'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = [
    '127.0.0.1',
    'reiwarss.pythonanywhere.com',
    'http://reiwarss.pythonanywhere.com/',
    'www.reiwarss.pythonanywhere.com',
]

# Application definition

INSTALLED_APPS = [
    'django_crontab',
    'web.apps.WebConfig',
    "django_cron",

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'web.middlewares.StatsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'ohmyrss.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'tmpl')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.static',
            ],
        },
    },
]

WSGI_APPLICATION = 'ohmyrss.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'reiwarss.sqlite3'),
        #'ENGINE':'django.db.backends.mysql',
        #'NAME':'reiwarss',
        #'USER':'root',
        #'HOST':'',
        #'PORT':'',
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Tokyo'

USE_I18N = True

USE_L10N = True

USE_TZ = True



CRONJOBS = [
   ('1 0-23 * * *', 'web.cron.update_all_user_feed'),
   ('*/5 * * * *', 'web.djangocron.my_sheduled_job'),

   ('*/30 * * * *', 'web.djangocron.my_sheduled_30minjob'),
   ('*/60 * * * *', 'web.djangocron.my_sheduled_60minjob'),
   #('*/1 * * * *', 'web.cron.update_all_user_feed', '>>' +os.path.join(BASE_DIR,'log/debug7.log')),
   ('11 3 * * *', 'web.cron.clean_history_data')
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/assets/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "assets"),
]

# redis service
REDIS_HOST = '127.0.0.1'
REDIS_PORT = '6379'

# for scrapy use db
REDIS_FEED_DB = 0
# for web use db
REDIS_WEB_DB = 1

# crete a redis instance using redislite
REDIS_DB_PATH = os.path.join(BASE_DIR, 'my_redis.db')
#rdb = Redis(REDIS_DB_PATH)
#REDIS_SOCKET_PATH = 'redis+socket://%s' % (rdb.socket_file, )
#BROKER_URL = REDIS_SOCKET_PATH



# page view count, thumb count, open page count
REDIS_VIEW_KEY = 'VIEW/%s'
REDIS_THUMB_KEY = 'THUMB/%s'
REDIS_OPEN_KEY = 'OPEN/%s'

# for dashboard statistics
REDIS_WEEK_KEY = 'WEEK/%s'
REDIS_VISIT_KEY = 'VISIT/%s/%s'
REDIS_UV_ALL_KEY = 'UV/ALL/%s'
REDIS_UV_NEW_KEY = 'UV/NEW/%s'

# http referer
REDIS_REFER_ALL_KEY = 'REFER/ALL'
REDIS_REFER_PV_KEY = 'REFER/%s'
REDIS_REFER_PV_DAY_KEY = 'REFER/%s/%s'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'web': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
    },
}
Django settings for ohmyrss project.  Generated by 'django-admin startproject' using Django 2.2.  For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # Application definition # 'django.middleware.csrf.CsrfViewMiddleware', # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases #'ENGINE':'django.db.backends.mysql', #'NAME':'reiwarss', #'USER':'root', #'HOST':'', #'PORT':'', # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ #('*/1 * * * *', 'web.cron.update_all_user_feed', '>>' +os.path.join(BASE_DIR,'log/debug7.log')), # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ # redis service # for scrapy use db # for web use db # crete a redis instance using redislite #rdb = Redis(REDIS_DB_PATH) #REDIS_SOCKET_PATH = 'redis+socket://%s' % (rdb.socket_file, ) #BROKER_URL = REDIS_SOCKET_PATH # page view count, thumb count, open page count # for dashboard statistics # http referer