# Path: cronos/common/exceptions.py
# class CronosError(Exception):
#     '''
#     Custom Exception class for general errors
#     '''
#     def __init__(self, value):
#         self.value = value
#     def __str__(self):
#         return unicode(self.value).encode('utf-8')
# 
# Path: cronos/common/log.py
# def log_extra_data(additional = None):
#     '''
#     Extra data needed by the custom formatter
#     * If the additional argument is a string or unicode, then its value is printed
#     in the log.
#     * If the additiona argument is the request, then from the request it
#     prints the client IP and username if applicable.
#     '''
#     log_extra_data = {
#         'client_ip': '',
#         'id_name': '',
#         'instance_name': settings.INSTANCE_NAME,
#     }
#     if not additional:
#         return log_extra_data
#     if type(additional) == str or type(additional) == unicode:
#         log_extra_data['id_name'] = additional
#     else:
#         request = additional
#         if request.META:
#             log_extra_data['client_ip'] = request.META.get('REMOTE_ADDR', 'None')
#         try:
#             if request.user.is_authenticated():
#                 '''
#                 Handle logged in users
#                 '''
#                 log_extra_data['id_name'] = request.user.name
#         except AttributeError:
#                 pass
#     return log_extra_data
# 
# Path: cronos/posts/models.py
# class Authors(models.Model):
#     content_type = models.ForeignKey(ContentType)
#     object_id = models.PositiveIntegerField()
#     content_object = generic.GenericForeignKey('content_type', 'object_id')
# 
#     def __unicode__(self):
#         return self.content_object.name
# 
# Path: cronos/teilar/models.py
# class Websites(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     rss = models.URLField()
#     email = models.EmailField(null = True)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name


from cronos.common.exceptions import CronosError
from cronos.common.log import log_extra_data
from cronos.posts.models import Authors
from cronos.teilar.models import Websites
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import IntegrityError
import logging
        return

    def deprecate_website_in_db(self, url, websites_from_db_q):
        '''
        Mark websites as inactive
        '''
        website = websites_from_db_q.get(url = url)
        website.is_active = False
        try:
            website.save()
            logger_syslog.info(u'Αλλαγή κατάστασης σε inactive', extra = log_extra_data(url))
        except Exception as error:
            logger_syslog.error(error, extra = log_extra_data(url))
            logger_mail.exception(error)
        return

    def update_websites(self):
        '''
        1) Find websites that were removed and mark them as inactive
        2) Find new websites and add them
        3) In the existing websites, find changes in their attributes and
        update them accordingly
        '''
        websites = self.get_websites()
        '''
        Get all the websites from the DB and put them in a dictionary in the structure:
        websites_from_db = {'url': ['name', 'rss', 'email']}
        '''
        websites_from_db = {}
        try:

# Path: cronos/common/exceptions.py
# class CronosError(Exception):
#     '''
#     Custom Exception class for general errors
#     '''
#     def __init__(self, value):
#         self.value = value
#     def __str__(self):
#         return unicode(self.value).encode('utf-8')
# 
# Path: cronos/common/log.py
# def log_extra_data(additional = None):
#     '''
#     Extra data needed by the custom formatter
#     * If the additional argument is a string or unicode, then its value is printed
#     in the log.
#     * If the additiona argument is the request, then from the request it
#     prints the client IP and username if applicable.
#     '''
#     log_extra_data = {
#         'client_ip': '',
#         'id_name': '',
#         'instance_name': settings.INSTANCE_NAME,
#     }
#     if not additional:
#         return log_extra_data
#     if type(additional) == str or type(additional) == unicode:
#         log_extra_data['id_name'] = additional
#     else:
#         request = additional
#         if request.META:
#             log_extra_data['client_ip'] = request.META.get('REMOTE_ADDR', 'None')
#         try:
#             if request.user.is_authenticated():
#                 '''
#                 Handle logged in users
#                 '''
#                 log_extra_data['id_name'] = request.user.name
#         except AttributeError:
#                 pass
#     return log_extra_data
# 
# Path: cronos/posts/models.py
# class Authors(models.Model):
#     content_type = models.ForeignKey(ContentType)
#     object_id = models.PositiveIntegerField()
#     content_object = generic.GenericForeignKey('content_type', 'object_id')
# 
#     def __unicode__(self):
#         return self.content_object.name
# 
# Path: cronos/teilar/models.py
# class Websites(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     rss = models.URLField()
#     email = models.EmailField(null = True)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name


# Path: cronos/teilar/management/commands/get_websites.py
from cronos.common.exceptions import CronosError
from cronos.common.log import log_extra_data
from cronos.posts.models import Authors
from cronos.teilar.models import Websites
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import IntegrityError
import logging

        return

    def deprecate_website_in_db(self, url, websites_from_db_q):
        '''
        Mark websites as inactive
        '''
        website = websites_from_db_q.get(url = url)
        website.is_active = False
        try:
            website.save()
            logger_syslog.info(u'Αλλαγή κατάστασης σε inactive', extra = log_extra_data(url))
        except Exception as error:
            logger_syslog.error(error, extra = log_extra_data(url))
            logger_mail.exception(error)
        return

    def update_websites(self):
        '''
        1) Find websites that were removed and mark them as inactive
        2) Find new websites and add them
        3) In the existing websites, find changes in their attributes and
        update them accordingly
        '''
        websites = self.get_websites()
        '''
        Get all the websites from the DB and put them in a dictionary in the structure:
        websites_from_db = {'url': ['name', 'rss', 'email']}
        '''
        websites_from_db = {}
        try:

            websites_from_db_q = Websites.objects.filter(is_active = True)