def get(self): ticker = self.request.get('ticker') category = self.request.get('category') subcategory = self.request.get('subcategory') entry = stock.get(ticker) entry.category = category entry.subcategory = subcategory stock.put(ticker, entry)
def __update_market_capital(self, market_capital): ticker = self.request.get('ticker') title = self.request.get('title') entry = stock.get(ticker) entry.ticker = ticker entry.title = title entry.market_capital = market_capital entry.market_capital_date = datetime.date.today() stock.put(ticker, entry)
def __update_earnings(self): ticker = self.request.get('ticker') entry = stock.get(ticker) balance = self.__get_balance_earnings() profit = self.__get_profit_earnings() year = datetime.date.today().year for i in range(3): earnings_date = self.__get_recent_earnings_date(year - i, balance, profit) if earnings_date is not None: break if earnings_date is None: logging.warn('There is no earnings date for %s' % (ticker)) return else: try: bank_flag = False if earnings_date.month == 12: this_earnings_date = earnings_date.strftime('%Y%m%d') ebit = self.__get_ebit(profit[this_earnings_date]) income = self.__get_income(profit[this_earnings_date]) enterprise_value = self.__get_enterprise_value(balance[this_earnings_date]) tangible_asset = self.__get_tangible_asset(balance[this_earnings_date]) ownership_interest = self.__get_ownership_interest(balance[this_earnings_date]) net_profit = self.__get_net_profit(profit[this_earnings_date]) total_assets = self.__get_total_assets(balance[this_earnings_date]) total_liability = self.__get_total_liability(balance[this_earnings_date]) else: this_earnings_date = earnings_date.strftime('%Y%m%d') last_earnings_date = earnings_date.replace(earnings_date.year - 1).strftime('%Y%m%d') last_year_date = datetime.date(year=earnings_date.year - 1, month=12, day=31).strftime('%Y%m%d') enterprise_value = self.__get_enterprise_value(balance[this_earnings_date]) tangible_asset = self.__get_tangible_asset(balance[this_earnings_date]) ownership_interest = self.__get_ownership_interest(balance[this_earnings_date]) total_assets = self.__get_total_assets(balance[this_earnings_date]) total_liability = self.__get_total_liability(balance[this_earnings_date]) ebit = (self.__get_ebit(profit[this_earnings_date]) + self.__get_ebit(profit[last_year_date]) - self.__get_ebit(profit[last_earnings_date])) income = (self.__get_income(profit[this_earnings_date]) + self.__get_income(profit[last_year_date]) - self.__get_income(profit[last_earnings_date])) net_profit = (self.__get_net_profit(profit[this_earnings_date]) + self.__get_net_profit(profit[last_year_date]) - self.__get_net_profit(profit[last_earnings_date])) except KeyError as ke: logging.exception(ke) bank_flag = True if earnings_date.month == 12: this_earnings_date = earnings_date.strftime('%Y%m%d') ownership_interest = string.atof(balance[this_earnings_date]['归属于母公司股东的权益']) net_profit = string.atof(profit[this_earnings_date]['归属于母公司的净利润']) total_assets = string.atof(balance[this_earnings_date]['资产总计']) total_liability = string.atof(balance[this_earnings_date]['负债合计']) else: this_earnings_date = earnings_date.strftime('%Y%m%d') last_earnings_date = earnings_date.replace(earnings_date.year - 1).strftime('%Y%m%d') last_year_date = datetime.date(year=earnings_date.year - 1, month=12, day=31).strftime('%Y%m%d') ownership_interest = string.atof(balance[this_earnings_date]['归属于母公司股东的权益']) total_assets = string.atof(balance[this_earnings_date]['资产总计']) total_liability = string.atof(balance[this_earnings_date]['负债合计']) net_profit = (string.atof(profit[this_earnings_date]['归属于母公司的净利润']) + string.atof(profit[last_year_date]['归属于母公司的净利润']) - string.atof(profit[last_earnings_date]['归属于母公司的净利润'])) entry.bank_flag = bank_flag entry.earnings_date = earnings_date entry.ownership_interest = ownership_interest entry.net_profit = net_profit entry.total_assets = total_assets entry.total_liability = total_liability stock.put(ticker, entry) logging.info("Firstly %s is a bank" % (ticker)) return entry.bank_flag = bank_flag entry.earnings_date = earnings_date entry.ebit = ebit entry.income = income entry.enterprise_value = enterprise_value entry.tangible_asset = tangible_asset entry.ownership_interest = ownership_interest entry.net_profit = net_profit entry.total_assets = total_assets entry.total_liability = total_liability stock.put(ticker, entry)
def __update_earnings(self): ticker = self.request.get('ticker') entry = stock.get(ticker) balance = self.__get_balance_earnings() profit = self.__get_profit_earnings() year = datetime.date.today().year for i in range(3): earnings_date = self.__get_recent_earnings_date(year - i, balance, profit) if earnings_date is not None: break if earnings_date is None: logging.warn('There is no earnings date for %s' % (ticker)) return else: try: bank_flag = False if earnings_date.month == 12: this_earnings_date = earnings_date.strftime('%Y%m%d') ebit = self.__get_ebit(profit[this_earnings_date]) income = self.__get_income(profit[this_earnings_date]) enterprise_value = self.__get_enterprise_value(balance[this_earnings_date]) tangible_asset = self.__get_tangible_asset(balance[this_earnings_date]) ownership_interest = self.__get_ownership_interest(balance[this_earnings_date]) net_profit = self.__get_net_profit(profit[this_earnings_date]) total_assets = self.__get_total_assets(balance[this_earnings_date]) total_liability = self.__get_total_liability(balance[this_earnings_date]) current_assets = self.__get_current_assets(balance[this_earnings_date]) else: this_earnings_date = earnings_date.strftime('%Y%m%d') last_earnings_date = earnings_date.replace(earnings_date.year - 1).strftime('%Y%m%d') last_year_date = datetime.date(year=earnings_date.year - 1, month=12, day=31).strftime('%Y%m%d') enterprise_value = self.__get_enterprise_value(balance[this_earnings_date]) tangible_asset = self.__get_tangible_asset(balance[this_earnings_date]) ownership_interest = self.__get_ownership_interest(balance[this_earnings_date]) total_assets = self.__get_total_assets(balance[this_earnings_date]) total_liability = self.__get_total_liability(balance[this_earnings_date]) current_assets = self.__get_current_assets(balance[this_earnings_date]) ebit = (self.__get_ebit(profit[this_earnings_date]) + self.__get_ebit(profit[last_year_date]) - self.__get_ebit(profit[last_earnings_date])) income = (self.__get_income(profit[this_earnings_date]) + self.__get_income(profit[last_year_date]) - self.__get_income(profit[last_earnings_date])) net_profit = (self.__get_net_profit(profit[this_earnings_date]) + self.__get_net_profit(profit[last_year_date]) - self.__get_net_profit(profit[last_earnings_date])) except KeyError as ke: logging.exception(ke) bank_flag = True if earnings_date.month == 12: this_earnings_date = earnings_date.strftime('%Y%m%d') ownership_interest = string.atof(balance[this_earnings_date]['归属于母公司股东的权益']) net_profit = string.atof(profit[this_earnings_date]['归属于母公司的净利润']) total_assets = string.atof(balance[this_earnings_date]['资产总计']) total_liability = string.atof(balance[this_earnings_date]['负债合计']) else: this_earnings_date = earnings_date.strftime('%Y%m%d') last_earnings_date = earnings_date.replace(earnings_date.year - 1).strftime('%Y%m%d') last_year_date = datetime.date(year=earnings_date.year - 1, month=12, day=31).strftime('%Y%m%d') ownership_interest = string.atof(balance[this_earnings_date]['归属于母公司股东的权益']) total_assets = string.atof(balance[this_earnings_date]['资产总计']) total_liability = string.atof(balance[this_earnings_date]['负债合计']) net_profit = (string.atof(profit[this_earnings_date]['归属于母公司的净利润']) + string.atof(profit[last_year_date]['归属于母公司的净利润']) - string.atof(profit[last_earnings_date]['归属于母公司的净利润'])) entry.bank_flag = bank_flag entry.earnings_date = earnings_date entry.ownership_interest = ownership_interest entry.net_profit = net_profit entry.total_assets = total_assets entry.total_liability = total_liability stock.put(ticker, entry) logging.info("Firstly %s is a bank" % (ticker)) return entry.bank_flag = bank_flag entry.earnings_date = earnings_date entry.ebit = ebit entry.income = income entry.enterprise_value = enterprise_value entry.tangible_asset = tangible_asset entry.ownership_interest = ownership_interest entry.net_profit = net_profit entry.total_assets = total_assets entry.total_liability = total_liability entry.current_assets = current_assets stock.put(ticker, entry)