예제 #1
0
    def find_or_create(cls, session, text, language, url, article):
        """
        :param text: string
        :param language: Language (object)
        :param url: Url (object)
        :return:
        """

        try:
            return cls.query.filter(
                cls.content_hash == text_hash(text)).filter(
                    cls.article == article).one()
        except sqlalchemy.orm.exc.NoResultFound or sqlalchemy.exc.InterfaceError:
            try:
                new = cls(text, language, url, article)
                session.add(new)
                session.commit()
                return new
            except sqlalchemy.exc.IntegrityError or sqlalchemy.exc.DatabaseError:
                for i in range(10):
                    try:
                        session.rollback()
                        t = cls.query.filter(
                            cls.content_hash == text_hash(text)).one()
                        print("found text after recovering from race")
                        return t
                    except:
                        print("exception of second degree in find text..." +
                              str(i))
                        time.sleep(0.3)
                        continue
                    break
예제 #2
0
 def find(cls, text, language):
     try:
         query = (cls.query.filter(cls.language == language).filter(
             cls.content_hash == util.text_hash(text)))
         if query.count() > 0:
             query = query.filter(cls.content == text)
             try:
                 return query.one()
             except sqlalchemy.orm.exc.NoResultFound:
                 pass
         return cls(text, language)
     except:
         import traceback
         traceback.print_exc()
예제 #3
0
파일: model.py 프로젝트: ZeeGuu/API
 def find(cls, text, language):
     try:
         query = (
             cls.query.filter(cls.language == language)
                      .filter(cls.content_hash == util.text_hash(text))
         )
         if query.count() > 0:
             query = query.filter(cls.content == text)
             try:
                 return query.one()
             except sqlalchemy.orm.exc.NoResultFound:
                 pass
         return cls(text, language)
     except:
         import traceback
         traceback.print_exc()
예제 #4
0
    def find_or_create(cls, text, language, url):
        """
        :param text: string
        :param language: Language (object)
        :param url: Url (object)
        :return:
        """

        try:
            query = (
                cls.query.filter(cls.content_hash == util.text_hash(text))
                # For some reason, here we can't filter by the url...
            )
            if query.count() > 0:
                query = query.filter(cls.content == text)
                try:
                    return query.one()
                except sqlalchemy.orm.exc.NoResultFound:
                    pass
            return cls(text, language, url)
        except:
            import traceback
            traceback.print_exc()
예제 #5
0
 def __init__(self, content, language, url):
     self.content = content
     self.language = language
     self.url = url
     self.content_hash = util.text_hash(content)
예제 #6
0
파일: model.py 프로젝트: ZeeGuu/API
 def __init__(self, content, language):
     self.content = content
     self.language = language
     self.content_hash = util.text_hash(content)
예제 #7
0
 def __init__(self, content, language, url, article):
     self.content = content
     self.language = language
     self.url = url
     self.content_hash = text_hash(content)
     self.article = article
예제 #8
0
# script used to convert the old binary hashes
# to their hex counterparts. binary can not be
# insured UNIQUE by a mysql constraint
from zeeguu.model import Text
from zeeguu import util
import zeeguu
session = zeeguu.db.session

texts = session.query(Text).all()
for t in texts:
    t.content_hash = util.text_hash(t.content)
    session.add(t)
    session.commit()
    #input ("next?/")