MarseyWorld/files/classes/sub.py

68 lines
1.7 KiB
Python
Raw Normal View History

2022-02-05 21:09:17 +00:00
from sqlalchemy import *
2022-03-06 00:21:13 +00:00
from sqlalchemy.orm import relationship
2022-02-05 21:09:17 +00:00
from files.__main__ import Base
2022-02-10 20:35:16 +00:00
from files.helpers.lazy import lazy
2022-07-08 18:13:18 +00:00
from os import environ
2022-03-06 01:53:11 +00:00
from .sub_block import *
from .sub_subscription import *
2022-09-12 10:19:35 +00:00
import time
2022-02-10 20:35:16 +00:00
2022-07-08 18:13:18 +00:00
SITE_NAME = environ.get("SITE_NAME", '').strip()
SITE = environ.get("DOMAIN", '').strip()
if SITE == "localhost": SITE_FULL = 'http://' + SITE
else: SITE_FULL = 'https://' + SITE
2022-02-05 21:09:17 +00:00
class Sub(Base):
__tablename__ = "subs"
name = Column(String, primary_key=True)
sidebar = Column(String)
sidebar_html = Column(String)
2022-02-10 20:35:16 +00:00
sidebarurl = Column(String)
bannerurl = Column(String)
marseyurl = Column(String)
2022-02-11 23:32:14 +00:00
css = Column(String)
stealth = Column(Boolean)
created_utc = Column(Integer)
2022-02-05 21:09:17 +00:00
blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name")
followers = relationship("SubSubscription", primaryjoin="SubSubscription.sub==Sub.name")
2022-03-06 00:21:13 +00:00
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
super().__init__(*args, **kwargs)
2022-02-05 21:09:17 +00:00
def __repr__(self):
2022-09-11 14:32:04 +00:00
return self.name
2022-02-10 20:35:16 +00:00
@property
@lazy
def sidebar_url(self):
2022-02-11 20:01:07 +00:00
if self.sidebarurl: return SITE_FULL + self.sidebarurl
return f'/i/{SITE_NAME}/sidebar.webp?v=3009'
2022-02-10 20:35:16 +00:00
@property
@lazy
def banner_url(self):
2022-02-11 20:01:07 +00:00
if self.bannerurl: return SITE_FULL + self.bannerurl
return f'/i/{SITE_NAME}/banner.webp?v=3009'
@property
@lazy
def marsey_url(self):
if self.marseyurl: return SITE_FULL + self.marseyurl
return f'/i/{SITE_NAME}/headericon.webp?v=3009'
2022-03-06 00:21:13 +00:00
@property
@lazy
def subscription_num(self):
2022-03-06 01:53:11 +00:00
return self.subscriptions.count()
@property
@lazy
def block_num(self):
2022-06-10 10:06:34 +00:00
return len(self.blocks)
@property
@lazy
def follow_num(self):
return len(self.followers)