コード例 #1
0
    def find_or_create(cls, session, user: User, _url, _title: str, _language):
        """

            create a new object and add it to the db if it's not already there
            otherwise retrieve the existing object and update

            in case of creation, the created object is incomplete

\        """

        language = Language.find(_language)
        url = Url.find_or_create(session, _url, _title)

        try:
            return cls.query.filter_by(user=user, url=url).one()
        except NoResultFound:
            try:
                new = cls(user, url, _title, language)
                session.add(new)
                session.commit()
                return new
            except Exception as e:
                from sentry_sdk import capture_exception
                capture_exception(e)
                print("seems we avoided a race condition")
                session.rollback()
                return cls.query.filter_by(user=user, url=url).one()
コード例 #2
0
    def test_languages_exists(self):
        language_should_be = LanguageRule().random

        try:
            language_to_check = Language.find(language_should_be.code)
        except NoResultFound:
            assert False, "No Language found in database"

        assert language_should_be.code == language_to_check.code \
               and language_should_be.name == language_to_check.name
コード例 #3
0
 def get_or_create_language(cls, language_id):
     try:
         return Language.find(language_id)
     except (NoResultFound, OperationalError, ObjectDeletedError):
         return cls.__create_new_language(language_id)
コード例 #4
0
ファイル: feed.py プロジェクト: kindaninja/Zeeguu-Core
 def find_for_language_id(cls, language_code):
     language = Language.find(language_code)
     return cls.query.filter(cls.language == language).all()
コード例 #5
0
    this has been added, one can run the
    'tag_existing_articles' script to tag them.


"""

import zeeguu_core
from zeeguu_core.model.topic import Topic
from zeeguu_core.model.language import Language
from zeeguu_core.model.localized_topic import LocalizedTopic

session = zeeguu_core.db.session

count = 0
TOPICS = ["Sport", "Health", "Technology", "Politics", "Science", "Culture", "Travel", "Food"]
LANGUAGES = [Language.find("es"), Language.find("fr"), Language.find("nl"), Language.find("de")
            , Language.find("en"), Language.find("it")]
SPANISH_TOPICS = [["Sport", "juego sport deporte"], ["Salud", "salud hospital"]
    , ["Technologia", "tech technologia"], ["Politica", "politica diplomatico"], ["Ciencia", "ciencia"]
    , ["Cultura", "cultura"], ["Viaje", "viaje viajes"], ["Comida", "comida alimento"]]
FRENCH_TOPICS = [["Sport", "sport divertissement jouer"], ["Sante", "sante hopital"]
    , ["Technologie", "tech technologie"], ["Politique", "politique politologie"], ["Science", "science savoir"]
    , ["Culture", "culture"], ["Voyage", "voyager voyage"], ["Aliments", "nourriture aliments"]]
DUTCH_TOPICS = [["Sport", "sport spel"], ["Gezondheid", "gezondheid ziekenhuis gezond"]
    , ["Technologie", "tech technologie"], ["Politiek", "politiek politisch"], ["Wetenschap", "wetenschap"]
    , ["Cultuur", "cultuur cultureel"], ["Reizen", "reizen reis"], ["Eten", "eten voedsel eet"]]
GERMAN_TOPICS = [["Sport", "sport sportart spielart abart"], ["Gesundheit", "gesundheit gesundheitszustand"]
    , ["Technologie", "technologie technik"], ["Politik", "politik politologie"], ["Wissenschaft", "wissenschaft"]
    , ["Kultur", "kultur bildung"], ["Reise", "reise reisen"], ["Essen", "lebensmittel essen"]]
ENGLISH_TOPICS = [["Sport", "sport playing"], ["Health", "health hospital healthy"]
    , ["Technology", "tech technology"], ["Politics", "politics politic"], ["Science", "science scientist"]
コード例 #6
0
ファイル: user.py プロジェクト: jonsnielsen/Zeeguu-Core
 def set_native_language(self, code):
     self.native_language = Language.find(code)
コード例 #7
0
ファイル: user.py プロジェクト: jonsnielsen/Zeeguu-Core
 def set_learned_language(self, code):
     self.learned_language = Language.find(code)