示例#1
0
 def retrieve_data(self):
     session = DBSession()
     result = (session.query(self.model)
               .order_by(self.model.date)
               .all())
     session.close()
     return result
示例#2
0
    def persist_data(self, table):
        session = DBSession()

        for i, row in enumerate(table):
            if len(row) == 0:
                continue

            if i == 0:
                print("skipping header")
                continue

            session.add(self.model.from_csv_line(row))

        session.commit()
        session.close()
示例#3
0
    def retrieve_data(self):
        session = DBSession()

        statement = text("""
            with
                ing_checking as (
                    select distinct
                        date(date, 'start of month') as month,
                        last_value(balance_after_mutation)
                            over (partition by date(date, 'start of month'))
                            as balance
                    from ingtransactions
                    order by date
                ),
                meesman as (
                    select distinct
                        date(date, 'start of month') as month,
                        last_value(value)
                            over (partition by date(date, 'start of month'))
                            as balance
                    from meesmanbalances
                    order by date
                )
            select
                ing_checking.month,
                ing_checking.balance as ing_checking,
                meesman.balance as meesman,
                (
                    coalesce(ing_checking.balance, 0)
                    + coalesce(meesman.balance, 0)
                ) as net_worth
            from ing_checking
            left outer join meesman on ing_checking.month=meesman.month
        """)

        result = list(session.execute(statement))
        session.close()
        return result
示例#4
0
    def session(self):
        if hasattr(self, "_session"):
            return self._session

        self._session = DBSession()
        return self._session
示例#5
0
from telethon.tl.types import PeerChannel, MessageActionChatJoinedByLink, MessageActionPinMessage
from telethon.tl.types import MessageActionChatAddUser, MessageActionChatDeleteUser, MessageActionChannelMigrateFrom
from settings import DBSession, StepLength, api_hash, api_id, proxy_host, proxy_port
from openpyxl import Workbook
import socks
from models import User, AddUsers, Channel, Message

if proxy_host and proxy_port:
    client = TelegramClient('session_name', api_id, api_hash, proxy=(socks.SOCKS5, proxy_host, proxy_port))
else:
    client = TelegramClient('session_name', api_id, api_hash)
client.start()

Base = declarative_base()

session = DBSession()


def save_add_user(message_id, channel_id, inviter_id, invitee_id, date, add_type):
    exist_add_user = session.query(AddUsers).filter_by(message_id=message_id, channel_id=channel_id,
                                                       inviter_id=inviter_id, invitee_id=invitee_id).first()
    if not exist_add_user:
        new_add_user = AddUsers()
        new_add_user.message_id = message_id
        new_add_user.channel_id = channel_id
        new_add_user.inviter_id = inviter_id
        new_add_user.invitee_id = invitee_id
        new_add_user.date = date
        if inviter_id == invitee_id and add_type == 'manually':
            new_add_user.add_type = 'self'
        else: