示例#1
0
class Team(BasicModel):
    name = CharField()
    crest_url = CharField(null=True)
    crest_path = CharField(null=True)
    national = BooleanField()
    api_id = IntegerField(unique=True)
    created = DateTimeField(default=now())
    updated = DateTimeField(default=now())

    @property
    def competitions(self):
        fixtures = self.fixtures.select(Fixture.competition)
        fixtures = fixtures.distinct(Fixture.competition).tuples()
        comp_ids = list(sum(fixtures, ()))
        competitions = Competition.select().where(Competition.id << comp_ids)

        return competitions

    @property
    def fixtures(self):
        query = (Fixture.home_team == self) | (Fixture.away_team == self)
        fixtures = Fixture.select().where(query)

        return fixtures

    @property
    def crest(self):
        stock = relative_path('images/team-emblem.svg')
        path = str(self.crest_path)
        path = path if os.path.exists(path) else stock

        return path
示例#2
0
class SkinOffer(BaseModel):
    title = CharField(null=True)
    AssetID = CharField()
    game = CharField(null=True)
    buyPrice = FloatField(null=True)
    buyTime = DateTimeField(null=True)
    OfferID = CharField(null=True)
    sellTime = DateTimeField(null=True)
    sellPrice = FloatField(null=True)
    fee = IntegerField(default=7)
示例#3
0
class NodeConfig(Model):
    node_id = TextField(primary_key=True)
    config = JSONField(null=True)
    access_key = DateTimeField(null=True)

    class Meta:
        database = cdb
示例#4
0
class Fixture(BasicModel):
    date = DateTimeField()
    minute = IntegerField(null=True)
    period = CharField(null=True)
    home_team = ForeignKeyField(Team, related_name='home_team')
    away_team = ForeignKeyField(Team, related_name='away_team')
    score_home = IntegerField(null=True)
    score_away = IntegerField(null=True)
    competition = ForeignKeyField(Competition, related_name='competition')
    api_id = IntegerField(unique=True)
    created = DateTimeField(default=now())
    updated = DateTimeField(default=now())

    @property
    def events(self):
        return Event.select().where(Event.fixture == self)

    @property
    def live(self):
        pastp = ['PreMatch', 'FullTime', 'Postponed']
        fdate = parse_date(date=self.date, localize=False).date()
        fdate = fdate == today() and self.period not in pastp

        return fdate

    @property
    def today(self):
        fdate = parse_date(date=self.date, localize=False).date()
        fdate = fdate == today() and self.period != 'Postponed'

        return fdate

    @property
    def past(self):
        return self.period == 'FullTime'

    @property
    def score(self):
        posts = format_date(date=self.date, date_format="%d/%m/%Y\nPostponed")
        times = format_date(date=self.date, date_format="%H:%M")
        dates = format_date(date=self.date, date_format="%d/%m/%Y\n%H:%M")
        score = str(self.score_home) + ' - ' + str(self.score_away)
        score = times if self.period == 'PreMatch' else score
        score = score if self.today or self.past else dates
        score = posts if self.period == 'Postponed' else score

        return score
示例#5
0
class Stream(BasicModel):
    host = CharField()
    rate = IntegerField()
    language = CharField()
    url = CharField()
    hd_url = CharField(null=True)
    ch_id = CharField(unique=True)
    channel = ForeignKeyField(Channel, related_name='channel')
    watched = DateTimeField(null=True)
    created = DateTimeField(default=now())
    updated = DateTimeField(default=now())

    @property
    def logo(self):
        fname = str(self.host).lower()
        image = relative_path("images/%s.svg" % fname)

        return image
示例#6
0
class Channel(BasicModel):
    name = CharField(unique=True)
    language = CharField()
    logo_url = CharField(null=True)
    logo_path = CharField(null=True)
    created = DateTimeField(default=now())
    updated = DateTimeField(default=now())

    @property
    def logo(self):
        path = str(self.logo_path)
        path = path if os.path.exists(path) else 'images/channel-logo.svg'

        return path

    @property
    def streams(self):
        streams = Stream.select().where(Stream.channel == self).limit(2)
        streams = streams.distinct(Stream.host).order_by(Stream.created)

        return streams
示例#7
0
class Cacheable(Model):
  key     = CharField(unique=True)
  value   = CharField()
  ttl     = IntegerField(default=0)
  created = DateTimeField(default=now())
  updated = DateTimeField(default=now())

  class Meta:
    database = database_connection('cache.db')

  @property

  def text(self):
    return '' if self.value is None else str(self.value)

  @property

  def json(self):
    data = '[]' if self.value is None else str(self.value)
    data = json.loads(data)

    return data
示例#8
0
class Competition(BasicModel):
    name = CharField()
    short_name = CharField()
    section_code = CharField()
    section_name = CharField()
    season_id = IntegerField()
    api_id = IntegerField(unique=True)
    created = DateTimeField(default=now())
    updated = DateTimeField(default=now())

    @property
    def teams(self):
        fixtures = self.fixtures.select(Fixture.home_team, Fixture.away_team)
        fixtures = fixtures.distinct().tuples()
        team_ids = list(set(sum(fixtures, ())))
        teams = Team.select().where(Team.id << team_ids)

        return teams

    @property
    def fixtures(self):
        return Fixture.select().where((Fixture.competition == self))
示例#9
0
class Entry(flask_db.Model):
    title = CharField()
    slug = CharField(unique=True)
    content = TextField()
    published = BooleanField(index=True)
    timestamp = DateTimeField(default=datetime.datetime.now, index=True)

    @property
    def html_content(self):
        """
        Generate HTML representation of the markdown-formatted blog entry,
        and also convert any media URLs into rich media objects such as video
        players or images.
        """
        hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
        extras = ExtraExtension()
        markdown_content = markdown(self.content, extensions=[hilite, extras])
        oembed_content = parse_html(markdown_content,
                                    oembed_providers,
                                    urlize_all=True,
                                    maxwidth=app.config['SITE_WIDTH'])
        return Markup(oembed_content)

    def save(self, *args, **kwargs):
        # Generate a URL-friendly representation of the entry's title.
        if not self.slug:
            self.slug = re.sub(r'[^\w]+', '-', self.title.lower()).strip('-')
        ret = super(Entry, self).save(*args, **kwargs)

        # Store search content.
        self.update_search_index()
        return ret

    def update_search_index(self):
        # Create a row in the FTSEntry table with the post content. This will
        # allow us to use SQLite's awesome full-text search extension to
        # search our entries.
        exists = (FTSEntry.select(
            FTSEntry.docid).where(FTSEntry.docid == self.id).exists())
        content = '\n'.join((self.title, self.content))
        if exists:
            (FTSEntry.update({
                FTSEntry.content: content
            }).where(FTSEntry.docid == self.id).execute())
        else:
            FTSEntry.insert({
                FTSEntry.docid: self.id,
                FTSEntry.content: content
            }).execute(None)

    @classmethod
    def public(cls):
        return Entry.select().where(Entry.published)

    @classmethod
    def drafts(cls):
        return Entry.select().where(Entry.published is False)

    @classmethod
    def search(cls, query):
        words = [word.strip() for word in query.split() if word.strip()]
        if not words:
            # Return an empty query.
            return Entry.noop()
        search = ' '.join(words)

        # Query the full-text search index for entries matching the given
        # search query, then join the actual Entry data on the matching
        # search result.
        return (Entry.select(
            Entry,
            FTSEntry.rank().alias('score')).join(
                FTSEntry,
                on=(Entry.id == FTSEntry.docid
                    )).where(FTSEntry.match(search)
                             & (Entry.published)).order_by(SQL('score')))
示例#10
0
class Skin(BaseModel):
    title = CharField()
    game = CharField()
    LastSales = JSONField()
    avg_price = FloatField()
    update_time = DateTimeField()
示例#11
0
class Event(BasicModel):
    fs_id = CharField(unique=True)
    fixture = ForeignKeyField(Fixture, related_name='fixture')
    stream = ForeignKeyField(Stream, related_name='stream')
    created = DateTimeField(default=now())
    updated = DateTimeField(default=now())