Esempio n. 1
0
def get_news():
    timer = Timer(24 * 60 * 60, get_news)
    timer.start()

    session = db.session()
    old = session.query(News).all()

    for one in old:
        session.delete(one)

    session.commit()
    session.close()

    session = db.session()

    info = tushare.get_latest_news(top=30, show_content=True)

    for i in range(30):
        news = News(info.title[i].__str__(), info.content[i].__str__(),
                    info.time[i].__str__())
        session.add(news)

    session.commit()

    session.close()
Esempio n. 2
0
def update_allocation():
    timer = Timer(24 * 60 * 60, update_allocation)
    timer.start()

    session = db.session()
    all_invest = session.query(InvestRequirement).all()

    for invest in all_invest:
        # 生成方案
        allocation = globalAllocationBl.get_allocation(invest.profit,
                                                       invest.risk,
                                                       invest.amount,
                                                       invest.year, False)
        invest_id = invest.id
        # 先把原来的交易建议删了,然后写入新的
        investDao.delete_advice(invest_id)
        # 写入交易建议
        advices = allocation[2]
        for advice in advices:
            advice.request_id = invest_id
            investDao.insert(advice)

        if not invest.defaultConfirm:
            investDao.insert(
                Notice('尊敬的用户:您的资产配置方案已产生变更,请尽快确认交易', invest.username,
                       'Others'))
        else:
            RestDao().generateRecordsAndChange(invest_id)

        pass
Esempio n. 3
0
    def save_stock_asset_allocation(
            self, invreq_id, strategy: StockStrategy,
            portfolio: StockPortfolio,
            transactions_advice: StockTransactionsAdvice):

        try:
            session = db.session()
            session.query(StockAdvice).filter(
                StockAdvice.request_id == invreq_id).delete()
            for code, quantity in strategy.strategy.items():
                session.add(StockAdvice(code, quantity, invreq_id))

            session.query(StockPosition).filter(
                StockPosition.request_id == invreq_id).delete()
            for position in portfolio.portfolio:
                position.request_id = invreq_id
                session.add(position)

            for record in transactions_advice.transactions:
                record.request_id = invreq_id
                session.add(record)

            session.commit()
            session.close()
        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
Esempio n. 4
0
 def insert_validation_code(self, code):
     try:
         session = db.session()
         session.add(code)
         session.commit()
     except:
         traceback.print_exc()
     finally:
         session.close()
Esempio n. 5
0
 def get_user_by_email(self, email) -> User:
     try:
         session = db.session()
         user = session.query(User).filter(User.email == email).first()
         if not user:
             raise EmailNotFoundException
         return user
     finally:
         session.close()
Esempio n. 6
0
 def insert_user(self, user):
     try:
         session = db.session()
         session.add(user)
         session.commit()
     except:
         print("error")
         traceback.print_exc()
     finally:
         session.close()
Esempio n. 7
0
 def get_user_by_username(self, username) -> User:
     try:
         session = db.session()
         user = session.query(User).filter(
             User.username == username).first()
         if not user:
             raise UsernameNotFoundException
         return user
     finally:
         session.close()
Esempio n. 8
0
 def delete(self, object):
     try:
         self.session = db.session()
         self.session.delete(object)
         self.session.commit()
         self.session.close()
     except:
         traceback.print_exc()
     finally:
         self.session.close()
Esempio n. 9
0
 def get_validation_code_by_token(self, token) -> ValidationCode:
     try:
         session = db.session()
         validation_code = session.query(ValidationCode).filter(
             ValidationCode.token == token).first()
         if not validation_code:
             raise Exception('The validation token does not exist!')
         return validation_code
     finally:
         session.close()
Esempio n. 10
0
 def get_all_invest(self):
     try:
         session = db.session()
         history = session.query(InvestRequirement).all()
         return history
     except:
         print("error")
         traceback.print_exc()
     finally:
         session.close()
     pass
Esempio n. 11
0
 def get_all_notice(self, username):
     try:
         session = db.session()
         notice = session.query(Notice).filter(Notice.username == username)
         return notice
     except:
         print("error")
         traceback.print_exc()
     finally:
         session.close()
     pass
Esempio n. 12
0
 def get_one_news(self, id):
     try:
         session = db.session()
         news = session.query(News).filter(News.id == id)[0]
         session.close()
         return news
     except:
         print("error")
         traceback.print_exc()
     finally:
         session.close()
     pass
Esempio n. 13
0
 def delete_notice_by_ID(self, id):
     try:
         session = db.session()
         notice = session.query(Notice).filter(Notice.id == id)[0]
         session.delete(notice)
         session.commit()
     except:
         print("delete error")
         traceback.print_exc()
     finally:
         session.close()
     pass
Esempio n. 14
0
 def modify_user_preference(self, username, profit, risk):
     try:
         session = db.session()
         user = session.query(User).filter(
             User.username == username).first()
         if not user:
             raise UsernameNotFoundException
         user.risk = risk
         user.profit = profit
         session.commit()
     finally:
         session.close()
Esempio n. 15
0
 def modify_user_citi_account(self, username, citi_name, citi_password):
     try:
         session = db.session()
         user = session.query(User).filter(
             User.username == username).first()
         if not user:
             raise UsernameNotFoundException
         user.citi_username = citi_name
         user.citi_password = citi_password
         session.commit()
     finally:
         session.close()
Esempio n. 16
0
 def validate_email(self, username):
     try:
         session = db.session()
         user = session.query(User).filter(
             User.username == username).first()
         if not user:
             raise UsernameNotFoundException
         user.email_validated = True
         session.commit()
     except UsernameNotFoundException:
         traceback.print_exc()
     finally:
         session.close()
Esempio n. 17
0
 def insert(self, object):
     try:
         self.session = db.session()
         self.session.add(object)
         self.session.commit()
         self.session.close()
         # return object.id
     except IntegrityError:
         """产生这个error的可能原因, 已经存在,外健问题"""
         traceback.print_exc()
         raise InsertException
     finally:
         self.session.close()
Esempio n. 18
0
 def get_profits(self, invreq_id):
     # 查询数据库,根据数据库,查询账户为invreq_id 的所有 profit
     try:
         session = db.session()
         profits = session.query(Profit).filter(
             Profit.invreq_id == invreq_id).all()
         return profits
         # profit = Profit(profit)
         # session.add(profit)
         # session.commit()
     except exceptions:
         print('error')
     finally:
         session.close()
     pass
Esempio n. 19
0
    def get_account_by_username(self, username):
        try:
            session = db.session()
            invest = session.query(InvestRequirement).filter(
                InvestRequirement.username == username).all()

            if not invest:
                return []
            return invest
        except:
            print("error")
            traceback.print_exc()
        finally:
            session.close()
        pass
Esempio n. 20
0
    def get_one_invest(self, id):
        try:
            session = db.session()
            invest = session.query(InvestRequirement).filter(
                InvestRequirement.id == id)[0]
            if not invest:
                return NotFoundException
            return invest

        except:
            print("error")
            traceback.print_exc()
        finally:
            session.close()
        pass
Esempio n. 21
0
    def delete_advice(self, request_id):
        try:
            session = db.session()
            advice = session.query(Advice).filter(
                Advice.request_id == request_id).delete()
            session.commit()
            session.close()

            return advice

        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
Esempio n. 22
0
    def modify_invest_state(self, req_id):
        try:
            session = db.session()
            invest = session.query(InvestRequirement).filter(
                InvestRequirement.id == req_id)[0]
            if not invest:
                return []
            invest.is_bought = State.BUY
            session.commit()

        except:
            print("error")
            traceback.print_exc()
        finally:
            session.close()
        pass
Esempio n. 23
0
    def get_transaction_record(self, invreq_id):
        try:
            session = db.session()
            transaction_record = session.query(TransactionRecord).filter(
                TransactionRecord.request_id == invreq_id).all()

            if transaction_record is None:
                return []

            return transaction_record

        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
Esempio n. 24
0
    def modify_profit(self, invreq_id, accu_revenue, today_revenue):
        try:
            session = db.session()
            invest = session.query(InvestRequirement).filter(
                InvestRequirement.id == invreq_id).all()[0]

            if not invest:
                return
            else:
                invest.accu_revenue = accu_revenue
                invest.today_revenue = today_revenue
                session.commit()
        except:
            print("error")
            traceback.print_exc()
        finally:
            session.close()
Esempio n. 25
0
    def get_advice_by_id(self, request_id):
        try:
            session = db.session()
            advice = session.query(Advice).filter(
                Advice.request_id == request_id).all()
            if not advice:
                return []

            return advice

        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
        pass
Esempio n. 26
0
    def get_position(self, id):
        try:
            session = db.session()
            position = session.query(Position).filter(
                Position.request_id == id).all()

            if not position:
                return []

            return position

        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
        pass
Esempio n. 27
0
    def get_username_by_user_type(self, user_type):
        try:
            session = db.session()
            user = session.query(User).filter(User.user_type == user_type)

            if not user:
                raise UsernameNotFoundException

            result = []
            for a_user in user:
                result.append(a_user.username)

            return result

        except UsernameNotFoundException:
            traceback.print_exc()
        finally:
            session.close()
Esempio n. 28
0
    def get_reallowcation_record_by_date(self, invrq_id, date):
        try:
            session = db.session()
            print()
            transcation_record = session.query(ReallowcationRecord).filter(
                str(ReallowcationRecord.time).split(' ')[0] == date).filter(
                    ReallowcationRecord.invreq_id == invrq_id).all()
            if transcation_record is None:
                return []
            return transcation_record

        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
        pass
Esempio n. 29
0
    def modify_advice(self, id):
        try:
            session = db.session()
            advice = session.query(Advice).filter(Advice.id == id)[0]
            if not advice:
                return
            else:
                advice.is_done = False

            return advice

        except:
            print("error")
            traceback.print_exc()

        finally:
            session.close()
        pass
Esempio n. 30
0
 def set_transaction_option(self, plan_tran_time, plan_remind_time,
                            min_confirmed_price, confirm_time,
                            default_confirm, request_id):
     try:
         session = db.session()
         investrequirement = session.query(InvestRequirement).filter(
             InvestRequirement.id == request_id)[0]
         investrequirement.confirm_time = confirm_time
         investrequirement.plan_remind_time = plan_remind_time
         investrequirement.plan_tran_time = plan_tran_time
         investrequirement.min_confirmed_price = min_confirmed_price
         investrequirement.defaultConfirm = default_confirm
         session.commit()
     except:
         print("error")
         traceback.print_exc()
     finally:
         session.close()
     pass
Esempio n. 31
0
            "label":"工程名",
            "validators":[required()]
        },
        "mode_pet":{
            "label":"打包名",
            "validators":[required()]
        },
        "remote_path":{
            "label":"上传地址",
            "validators":[required()]
        },
        "git_url":{
            "label":"gitlab地址",
            "validators":[required()]
        },
    }
    def __init__(self,session):
        super(ModelsAdmin,self).__init__(Models,db.session())

    def is_accessible(self):
        return current_user.is_authenticated()

    def inaccessible_callback(self, name, **kwargs):
        return redirect(url_for("login",next=request.url))



admin=Admin(name="xiniu_admin",template_mode="bootstrap3")
admin.init_app(app)
admin.add_view(UserAdmin(db.session()))
admin.add_view(ModelsAdmin(db.session()))
Esempio n. 32
0
 def __init__(self,session):
     super(ModelsAdmin,self).__init__(Models,db.session())