# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)
# 
# Path: jarr/crawler/article_builders/rss_bridge.py
# class RSSBridgeArticleBuilder(ClassicArticleBuilder):
# 
#     @property
#     def do_skip_creation(self):
#         title = self.entry.get('title') or ''
#         if title.startswith('Bridge returned error'):
#             return True
#         return super().do_skip_creation
# 
# class RSSBridgeTwitterArticleBuilder(RSSBridgeArticleBuilder):
# 
#     def enhance(self):
#         try:
#             content = self.entry['content'][0]['value']
#             content_type = self.entry['content'][0].get('type', 'text/html')
#         except (KeyError, IndexError):
#             return
#         if content_type != 'text/html':
#             return
#         soup = BeautifulSoup(content, 'html.parser')
#         og_link = self.article['link']
#         og_comments = self.article.get('comments')
#         try:  # trying to find the last link in the tweet
#             all_links = [link for link in soup.find_all('a')
#                          if not link.find_all('img')  # no image
#                          # and no profil pic
#                          and og_link not in link.attrs['href']]
#             if all_links:
#                 self.article['comments'] = self.article['link']
#                 self.article['link'] = all_links[-1].attrs['href']
#         except (KeyError, AttributeError, TypeError, IndexError):
#             self.article['link'] = og_link
#             self.article['comments'] = og_comments
#         yield from super().enhance()
# 
# Path: jarr/lib/enums.py
# class FeedType(Enum):
#     classic = 'classic'
#     json = 'json'
#     tumblr = 'tumblr'
#     instagram = 'instagram'
#     soundcloud = 'soundcloud'
#     reddit = 'reddit'
#     koreus = 'koreus'
#     twitter = 'twitter'


from typing import Optional
from urllib.parse import SplitResult, urlencode, urlsplit, urlunsplit
from jarr.bootstrap import conf
from jarr.crawler.article_builders.rss_bridge import (
    RSSBridgeArticleBuilder, RSSBridgeTwitterArticleBuilder)
from jarr.crawler.crawlers.classic import ClassicCrawler
from jarr.lib.enums import FeedType



class RssBridgeAbstractCrawler(ClassicCrawler):
    bridge: str
    bridge_format = 'AtomFormat'
    article_builder = RSSBridgeArticleBuilder
    feed_type: Optional[FeedType] = None  # forcing this crawler to be ignored

    def get_url(self):
        split = urlsplit(conf.plugins.rss_bridge) \

# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)
# 
# Path: jarr/crawler/article_builders/rss_bridge.py
# class RSSBridgeArticleBuilder(ClassicArticleBuilder):
# 
#     @property
#     def do_skip_creation(self):
#         title = self.entry.get('title') or ''
#         if title.startswith('Bridge returned error'):
#             return True
#         return super().do_skip_creation
# 
# class RSSBridgeTwitterArticleBuilder(RSSBridgeArticleBuilder):
# 
#     def enhance(self):
#         try:
#             content = self.entry['content'][0]['value']
#             content_type = self.entry['content'][0].get('type', 'text/html')
#         except (KeyError, IndexError):
#             return
#         if content_type != 'text/html':
#             return
#         soup = BeautifulSoup(content, 'html.parser')
#         og_link = self.article['link']
#         og_comments = self.article.get('comments')
#         try:  # trying to find the last link in the tweet
#             all_links = [link for link in soup.find_all('a')
#                          if not link.find_all('img')  # no image
#                          # and no profil pic
#                          and og_link not in link.attrs['href']]
#             if all_links:
#                 self.article['comments'] = self.article['link']
#                 self.article['link'] = all_links[-1].attrs['href']
#         except (KeyError, AttributeError, TypeError, IndexError):
#             self.article['link'] = og_link
#             self.article['comments'] = og_comments
#         yield from super().enhance()
# 
# Path: jarr/lib/enums.py
# class FeedType(Enum):
#     classic = 'classic'
#     json = 'json'
#     tumblr = 'tumblr'
#     instagram = 'instagram'
#     soundcloud = 'soundcloud'
#     reddit = 'reddit'
#     koreus = 'koreus'
#     twitter = 'twitter'


# Path: jarr/crawler/crawlers/rss_bridge.py
from typing import Optional
from urllib.parse import SplitResult, urlencode, urlsplit, urlunsplit
from jarr.bootstrap import conf
from jarr.crawler.article_builders.rss_bridge import (
    RSSBridgeArticleBuilder, RSSBridgeTwitterArticleBuilder)
from jarr.crawler.crawlers.classic import ClassicCrawler
from jarr.lib.enums import FeedType




class RssBridgeAbstractCrawler(ClassicCrawler):
    bridge: str
    bridge_format = 'AtomFormat'
    article_builder = RSSBridgeArticleBuilder
    feed_type: Optional[FeedType] = None  # forcing this crawler to be ignored

    def get_url(self):
        split = urlsplit(conf.plugins.rss_bridge) \

                if conf.plugins.rss_bridge else None