<commit_before>import feedparser
from alfred.modules.api.a_base_model import AbstractABaseModel
from alfred.modules.api.a_base_module import ABaseModule
from alfred.modules.api.a_heading import AHeading

from .db import make_session
from .models import Source, create_new_database

create_new_database()


class BaseModel(AbstractABaseModel):
    pass


class Article(BaseModel):
    def __init__(self, title, body):
        super().__init__()
        self.title = title
        self.body = body


class AlfredNews(ABaseModule):
    def callback(self):
        pass

    def construct_view(self):
        BaseModel.connect(self.database_path)

        h1 = AHeading(1, "News module")
        self.add_component(h1)

        try:
            fetch_articles()
        except:
            pass

        articles = Article.all()
        for article in articles:
            self.add_component(AHeading(2, article.title))
            self.add_component(AHeading(3, article.body))


def fetch_articles():
    session = make_session()
    all_sources = session.query(Source).all()
    for source in all_sources:
        print(f'Getting feeds from {source.url}')
        feed = feedparser.parse(source.url)
        for entry in feed['entries']:
            title = entry.get('title', '')
            body = entry.get('summary', '')

            if Article.find_by(title=title) is None:
                article = Article(title, body)
                print(f'Saving article "{title}"')<commit_msg>Update class names<commit_after>import feedparser
from alfred.modules.api.a_base_model import ABaseModel
from alfred.modules.api.a_base_module import ABaseModule
from alfred.modules.api.a_heading import AHeading

from .db import make_session
from .models import Source, create_new_database


# create_new_database()


class BaseModel(ABaseModel):
    pass


class Article(BaseModel):
    def __init__(self, title, body):
        super().__init__()
        self.title = title
        self.body = body


class AlfredNews(ABaseModule):
    def callback(self):
        pass

    def construct_view(self):
        BaseModel.connect(self.database_path)

        h1 = AHeading(1, "News module")
        self.add_component(h1)

        try:
            fetch_articles()
        except:
            pass

        articles = Article.all()
        for article in articles:
            self.add_component(AHeading(2, article.title))
            self.add_component(AHeading(3, article.body))


def fetch_articles():
    session = make_session()
    all_sources = session.query(Source).all()
    for source in all_sources:
        print(f'Getting feeds from {source.url}')
        feed = feedparser.parse(source.url)
        if 'bozo_exception' in feed:
            print(f'ERROR: Exception while fetching from {source.url}')
            continue

        for entry in feed['entries']:
            title = entry.get('title', '')
            body = entry.get('summary', '')

            if Article.find_by(title=title) is None:
                article = Article(title, body)
                print(f'Saving article "{title}"')
{'fraction_non_alphanumeric': 0.09945108169195996, 'fraction_numerical': 0.0032289312237649337, 'mean_word_length': 2.552752293577982, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2069445', 'n_tokens_mistral': 912, 'n_tokens_neox': 879, 'n_words': 210}