# Path: wagtailsocialfeed/utils/feed/facebook.py
# class FacebookFeed(AbstractFeed):
#     item_cls = FacebookFeedItem
#     query_cls = FacebookFeedQuery
# 
# class FacebookFeedItem(FeedItem):
#     """Implements facebook-specific behaviour."""
# 
#     @classmethod
#     def get_post_date(cls, raw):
#         if 'created_time' in raw:
#             return dateparser.parse(raw.get('created_time'))
#         return None
# 
#     @classmethod
#     def from_raw(cls, raw):
#         item_type = PostType(raw['type'])
#         image = {}
#         if 'picture' in raw:
#             image = {
#                 'thumb': {'url': raw['picture']},
#                 # 'small': raw['images']['low_resolution'],
#                 # 'medium': raw['images']['standard_resolution'],
#                 # 'largel': None,
#             }
# 
#         return cls(
#             id=raw['id'],
#             type='facebook',
#             text=item_type.get_text_from(raw),
#             image_dict=image,
#             posted=cls.get_post_date(raw),
#             original_data=raw,
#         )
# 
# Path: wagtailsocialfeed/utils/feed/instagram.py
# class InstagramFeed(AbstractFeed):
#     item_cls = InstagramFeedItem
#     query_cls = InstagramFeedQuery
# 
# class InstagramFeedItem(FeedItem):
#     """Implements instagram-specific behaviour"""
# 
#     @classmethod
#     def get_post_date(cls, raw):
#         if 'date' in raw:
#             timestamp = None
#             try:
#                 timestamp = float(raw['date'])
#             except ValueError:
#                 return None
#             return timezone.make_aware(
#                 datetime.datetime.fromtimestamp(timestamp), timezone=timezone.utc)
# 
#         return None
# 
#     @classmethod
#     def from_raw(cls, raw):
#         image = {}
#         caption = None
#         if 'display_src' in raw:
#             image = {
#                 'thumb': raw['thumbnail_resources'][1],
#                 'small': raw['thumbnail_resources'][2],
#                 'medium': raw['thumbnail_resources'][3],
#                 'large': raw['thumbnail_resources'][4],
#                 'original_link': "https://www.instagram.com/p/" + raw['code']
#             }
# 
#         if 'caption' in raw:
#             caption = raw['caption']
# 
#         return cls(
#             id=raw['id'],
#             type='instagram',
#             text=caption,
#             image_dict=image,
#             posted=cls.get_post_date(raw),
#             original_data=raw,
#         )
# 
# Path: wagtailsocialfeed/utils/feed/twitter.py
# class TwitterFeed(AbstractFeed):
#     item_cls = TwitterFeedItem
#     query_cls = TwitterFeedQuery
# 
# class TwitterFeedItem(FeedItem):
#     @classmethod
#     def get_post_date(cls, raw):
#         # Use the dateutil parser because on some platforms
#         # python's own strptime doesn't support the %z directive.
#         # Format: '%a %b %d %H:%M:%S %z %Y'
#         return dateparser.parse(raw.get('created_at'))
# 
#     @classmethod
#     def from_raw(cls, raw):
#         image = None
#         extended = raw.get('extended_entities', None)
#         if extended:
#             image = process_images(extended.get('media', None))
#         date = cls.get_post_date(raw)
#         return cls(
#             id=raw['id'],
#             type='twitter',
#             text=raw['text'],
#             image_dict=image,
#             posted=date,
#             original_data=raw
#         )


from collections import namedtuple
from .facebook import FacebookFeed, FacebookFeedItem
from .instagram import InstagramFeed, InstagramFeedItem
from .twitter import TwitterFeed, TwitterFeedItem


FeedClasses = namedtuple('FeedClasses', ['feed', 'item'])

FEED_CONFIG = {
    'twitter': FeedClasses(TwitterFeed, TwitterFeedItem),
    'instagram': FeedClasses(InstagramFeed, InstagramFeedItem),
    'facebook': FeedClasses(FacebookFeed, FacebookFeedItem)
}


class FeedFactory(object):
    @classmethod
    def create(cls, source):
        try:
            return FEED_CONFIG[source].feed()
        except KeyError:
            raise NotImplementedError(
                "Feed class for type '{}' not available".format(source))


class FeedItemFactory(object):
    @classmethod
    def get_class(cls, source):

# Path: wagtailsocialfeed/utils/feed/facebook.py
# class FacebookFeed(AbstractFeed):
#     item_cls = FacebookFeedItem
#     query_cls = FacebookFeedQuery
# 
# class FacebookFeedItem(FeedItem):
#     """Implements facebook-specific behaviour."""
# 
#     @classmethod
#     def get_post_date(cls, raw):
#         if 'created_time' in raw:
#             return dateparser.parse(raw.get('created_time'))
#         return None
# 
#     @classmethod
#     def from_raw(cls, raw):
#         item_type = PostType(raw['type'])
#         image = {}
#         if 'picture' in raw:
#             image = {
#                 'thumb': {'url': raw['picture']},
#                 # 'small': raw['images']['low_resolution'],
#                 # 'medium': raw['images']['standard_resolution'],
#                 # 'largel': None,
#             }
# 
#         return cls(
#             id=raw['id'],
#             type='facebook',
#             text=item_type.get_text_from(raw),
#             image_dict=image,
#             posted=cls.get_post_date(raw),
#             original_data=raw,
#         )
# 
# Path: wagtailsocialfeed/utils/feed/instagram.py
# class InstagramFeed(AbstractFeed):
#     item_cls = InstagramFeedItem
#     query_cls = InstagramFeedQuery
# 
# class InstagramFeedItem(FeedItem):
#     """Implements instagram-specific behaviour"""
# 
#     @classmethod
#     def get_post_date(cls, raw):
#         if 'date' in raw:
#             timestamp = None
#             try:
#                 timestamp = float(raw['date'])
#             except ValueError:
#                 return None
#             return timezone.make_aware(
#                 datetime.datetime.fromtimestamp(timestamp), timezone=timezone.utc)
# 
#         return None
# 
#     @classmethod
#     def from_raw(cls, raw):
#         image = {}
#         caption = None
#         if 'display_src' in raw:
#             image = {
#                 'thumb': raw['thumbnail_resources'][1],
#                 'small': raw['thumbnail_resources'][2],
#                 'medium': raw['thumbnail_resources'][3],
#                 'large': raw['thumbnail_resources'][4],
#                 'original_link': "https://www.instagram.com/p/" + raw['code']
#             }
# 
#         if 'caption' in raw:
#             caption = raw['caption']
# 
#         return cls(
#             id=raw['id'],
#             type='instagram',
#             text=caption,
#             image_dict=image,
#             posted=cls.get_post_date(raw),
#             original_data=raw,
#         )
# 
# Path: wagtailsocialfeed/utils/feed/twitter.py
# class TwitterFeed(AbstractFeed):
#     item_cls = TwitterFeedItem
#     query_cls = TwitterFeedQuery
# 
# class TwitterFeedItem(FeedItem):
#     @classmethod
#     def get_post_date(cls, raw):
#         # Use the dateutil parser because on some platforms
#         # python's own strptime doesn't support the %z directive.
#         # Format: '%a %b %d %H:%M:%S %z %Y'
#         return dateparser.parse(raw.get('created_at'))
# 
#     @classmethod
#     def from_raw(cls, raw):
#         image = None
#         extended = raw.get('extended_entities', None)
#         if extended:
#             image = process_images(extended.get('media', None))
#         date = cls.get_post_date(raw)
#         return cls(
#             id=raw['id'],
#             type='twitter',
#             text=raw['text'],
#             image_dict=image,
#             posted=date,
#             original_data=raw
#         )


# Path: wagtailsocialfeed/utils/feed/factory.py
from collections import namedtuple
from .facebook import FacebookFeed, FacebookFeedItem
from .instagram import InstagramFeed, InstagramFeedItem
from .twitter import TwitterFeed, TwitterFeedItem



FeedClasses = namedtuple('FeedClasses', ['feed', 'item'])

FEED_CONFIG = {
    'twitter': FeedClasses(TwitterFeed, TwitterFeedItem),
    'instagram': FeedClasses(InstagramFeed, InstagramFeedItem),
    'facebook': FeedClasses(FacebookFeed, FacebookFeedItem)
}


class FeedFactory(object):
    @classmethod
    def create(cls, source):
        try:
            return FEED_CONFIG[source].feed()
        except KeyError:
            raise NotImplementedError(
                "Feed class for type '{}' not available".format(source))


class FeedItemFactory(object):
    @classmethod
    def get_class(cls, source):

        try: