def do(cls, hscei): template_content = FileHandle(os.path.join('templates', 'closing_index_hscei_cn')).read_all() return template_content.format(index_name=hscei.get_name(coding='unicode'), up_or_down=cls.up_verb if hscei.get_closing_change()[ 0] == '+' else cls.down_verb, change_point=hscei.get_closing_change()[1].decode('utf-8'), change_rate=hscei.get_closing_change()[2].decode('utf-8'), closing_point=hscei.get_closing_point().decode('utf-8'))
def do(cls, fx): template_content = FileHandle(os.path.join('templates', 'closing_fx_en')).read_all() return template_content.format(date=fx.get_date(), week=fx.get_week_day(), usd_b=fx.get_rate()['USD'][0], usd_s=fx.get_rate()['USD'][1], aud_b=fx.get_rate()['AUD'][0], aud_s=fx.get_rate()['AUD'][1], cad_b=fx.get_rate()['CAD'][0], cad_s=fx.get_rate()['CAD'][1], chf_b=fx.get_rate()['CHF'][0], chf_s=fx.get_rate()['CHF'][1], eur_b=fx.get_rate()['EUR'][0], eur_s=fx.get_rate()['EUR'][1], gbp_b=fx.get_rate()['GBP'][0], gbp_s=fx.get_rate()['GBP'][1], jpy_b="{:.2f}".format(float(fx.get_rate()['JPY'][0]) / 10), jpy_s="{:.2f}".format(float(fx.get_rate()['JPY'][1]) / 10))
def do(cls, gold, usd_hk_fx): template_content = FileHandle(os.path.join('templates', 'closing_gold_en')).read_all() return template_content.format(date=gold.get_date(), closing_price="{:,}".format(int(gold.get_closing_price())), week=gold.get_week_day(), up_or_down='up' if gold.get_closing_change()[0] == u'+' else 'down', up_or_down_adv='higher' if gold.get_closing_change()[0] == u'+' else 'lower', change_price=gold.get_closing_change()[1], usd_fx_hkd="{:.2f}".format(float(usd_hk_fx)), closing_price_usd="{:,.2f}".format(float(gold.get_closing_price()) / float(usd_hk_fx)) )
def do(cls, individual_stock): """ :param individual_stock: object_of_StockParser :return: """ # print individual_stock.get_name(), individual_stock.get_closing_change()[0], individual_stock.get_closing_change()[1], individual_stock.get_closing_price() template_content = FileHandle(os.path.join('templates', 'closing_individual_stock_cn')).read_all() mix = u'{up_or_down}{change_rate}%'.format( up_or_down=cls.down_verb if individual_stock.get_closing_change()[0] == u'-' else cls.up_verb, change_rate=individual_stock.get_closing_change()[1]) # net_change = flat if individual_stock.get_closing_change()[1] == '0' else return template_content.format(stock_name=individual_stock.get_name(), net_change=cls.flat if individual_stock.get_closing_change()[ 1] == '0.00' else mix, closing_price=individual_stock.get_closing_price())
def do(cls, hsi): ''' :param hsi: month/day: '04'->'4' :return: ''' template_content = FileHandle(os.path.join('templates', 'closing_index_hsi_cn')).read_all() return template_content.format(day=str(int(hsi.get_day())).decode('utf-8'), month=str(int(hsi.get_month())).decode('utf-8'), index_name=hsi.get_name(coding='unicode'), up_or_down=cls.up_verb if hsi.get_closing_change()[ 0] == '+' else cls.down_verb, change_point=hsi.get_closing_change()[1].decode('utf-8'), change_rate=hsi.get_closing_change()[2].decode('utf-8'), closing_point=hsi.get_closing_point().decode('utf-8'), turnover=hsi.get_turnover()[0])
class Maker(object): # pardir_abspath = os.path.abspath(os.path.join(sys.path[0], os.pardir)) def __init__(self, template_name): # template_path = os.path.join(Maker.pardir_abspath, 'templates', template_name) template_path = os.path.join('templates', template_name) self.template_handle = FileHandle(template_path) self.template_content = self.template_handle.read_all().encode('utf-8') def get_template_content(self): return self.template_handle.read_all().encode('utf-8') def do(self, r): """ :param r: object of class Parser out of the http response :return: """ pass
def do(cls, fi): ''' :param fi: month/day: '04' -> '4' :return: ''' template_content = FileHandle(os.path.join('templates', 'closing_future_index_cn')).read_all() hsi = fi['index']['HSI'] hscei = fi['index']['HSCEI'] future = fi['future'] m = str(int(time.strftime("%m", time.localtime()))).decode('utf-8') d = str(int(time.strftime("%d", time.localtime()))).decode('utf-8') return template_content.format(month=m, day=d, turnover=hsi.get_turnover()[0], hsi_opening_point=hsi.get_opening_point_raw(), hsi_closing_point=hsi.get_closing_point(coding='unicode'), hsi_change_point=( hsi.get_closing_change()[0] + hsi.get_closing_change()[1]).decode( 'utf-8') if hsi.get_closing_change()[0] == u'-' else hsi.get_closing_change()[1], hscei_opening_point=hscei.get_opening_point_raw(), hscei_closing_point=hscei.get_closing_point(coding='unicode'), hscei_change_point=( hscei.get_closing_change()[0] + hscei.get_closing_change()[1]).decode( 'utf-8') if hscei.get_closing_change()[0] == u'-' else hscei.get_closing_change()[1], hsif1_closing_point='{:.0f}'.format(float(future.get_closing_point(u'HSIF1'))), hsif1_change_point=future.get_closing_change(u'HSIF1')[1] if future.get_closing_change(u'HSIF1')[0] == u'+' else future.get_closing_change(u'HSIF1')[0] + future.get_closing_change(u'HSIF1')[ 1], hsif1_volume=future.get_volume(u'HSIF1'), hhif1_closing_point='{:.0f}'.format(float(future.get_closing_point(u'HHIF1'))), hhif1_change_point=future.get_closing_change(u'HHIF1')[1] if future.get_closing_change(u'HHIF1')[0] == u'+' else future.get_closing_change(u'HHIF1')[0] + future.get_closing_change(u'HHIF1')[ 1], hhif1_volume=future.get_volume(u'HHIF1'), )
def __init__(self, template_name): # template_path = os.path.join(Maker.pardir_abspath, 'templates', template_name) template_path = os.path.join('templates', template_name) self.template_handle = FileHandle(template_path) self.template_content = self.template_handle.read_all().encode('utf-8')