def getmaildata(): print('=====Get Mail Data %s====='%datetime.now()) imbox = Imbox(config('IMAP_ADDRESS'), username=config('USER_NAME'), password=config('PASSWORD'), ssl=True, ssl_context=None) messages_from = imbox.messages(date__gt=when.yesterday(),sent_from=config('SENT_FROM')) #messages_from = imbox.messages(sent_from='*****@*****.**') ldata = [] c,n = 0,0 #解析数据 for uid,message in messages_from: if message.subject == '信用管家消费提醒': html = str(message.body['html']) a = html[2:-2] soup = BeautifulSoup(a,'html.parser') b = soup.find_all('font') for s in b: if s.string is not None: ldata.append(s.string) print('=====Praser Data Success Size:%s ====='%str(len(ldata)/6)) # for m in ldata: # print(m) # print(m,file = open('a123.txt','a')) #写入数据库 while n < len(ldata)/6: try: pid =ldata[1+c]+ldata[2+c].replace(':','') de = DailyExpense.create(cardno=ldata[0+c],exDate=ldata[1+c],exTime=ldata[2+c],currency=ldata[3+c],exRecord=ldata[4+c],fee=float(ldata[5+c].replace(',','')),pid=pid) de.save() except Exception as e: print(e) n,c = n+1,c+6
def test_how_many_leap_days_valueerror(self): """Test ValueError raised by when.how_many_leap_days()""" d1 = when.today() d2 = when.yesterday() # from_date must be before to_date self.assertRaises(ValueError, when.how_many_leap_days, d1, d2)
def test_how_many_leap_days_typeerror(self): """Test TypeError raised by when.how_many_leap_days()""" d1 = when.today() d2 = when.yesterday() # from_date must be valid self.assertRaises(TypeError, when.how_many_leap_days, "a", d2) # to_date must be valid self.assertRaises(TypeError, when.how_many_leap_days, d1, "b")
def test_how_many_leap_days_typeerror(self): """Test TypeError raised by when.how_many_leap_days()""" d1 = when.today() d2 = when.yesterday() # from_date must be valid self.assertRaises(TypeError, when.how_many_leap_days, 'a', d2) # to_date must be valid self.assertRaises(TypeError, when.how_many_leap_days, d1, 'b')
def test_how_many_leap_days_assert(self): """Test AssertionError raised by when.how_many_leap_days()""" d1 = when.today() d2 = when.yesterday() # from_date must be valid self.assertRaises(AssertionError, when.how_many_leap_days, 'a', d2) # to_date must be valid self.assertRaises(AssertionError, when.how_many_leap_days, d1, 'b') # from_date must be before to_date self.assertRaises(AssertionError, when.how_many_leap_days, d1, d2)
def get_yesterday_start_end_time(st, ed): yesterday = when.yesterday() format_str = '%s %s' if st < ed: st_time_str = format_str % (yesterday, st) ed_time_str = format_str % (yesterday, ed) return st_time_str, ed_time_str today = when.today() st_time_str = format_str % (yesterday, st) ed_time_str = format_str % (today, ed) return st_time_str, ed_time_str
async def get(self): res = {} try: ktv_id = self.ktv_id date = self.get_argument('date', '2016-10') except: raise utils.APIError(errcode=10001) data = date.split('-') year = data[0] month = data[1] start_date = '%s-%s-01' % (year, month) monthRange = calendar.monthrange(int(year), int(month))[1] end_date = '%s-%s-%s' % (year, month, monthRange) res['list'] = [] yesterday = when.yesterday() if int(year) == yesterday.year and int(month) == yesterday.month:# 昨日营收 ktv = await ctrl.pay.get_ktv_ctl(ktv_id) y_time = ctrl.mch.get_yeterday_income_time_ctl(ktv) if y_time: y_sum_fee = ctrl.mch.get_yesterday_order_sum_fee_ctl(ktv_id=ktv_id, tp=ORDER_TP['normal'], start_time=y_time['start_time'], end_time=y_time['end_time'], pos_start_time=y_time['pos_start_time'], pos_end_time=y_time['pos_end_time']) y_income = { 'start_time': y_time['start_time'], 'end_time': y_time['end_time'], 'pos_start_time': y_time['pos_start_time'], 'pos_end_time': y_time['pos_end_time'], 'normal_fee': y_sum_fee['total_fee'], 'normal_rate': y_sum_fee['total_rate'], 'normal_money': y_sum_fee['total_fee'] - y_sum_fee['total_rate'], 'state': 0, 'income_id': -1 } res['list'].append(y_income) res['list'] += ctrl.mch.get_normal_incomes_ctl(ktv_id=ktv_id, start_date=start_date, end_date=end_date) res['date'] = date self.send_json(res)
def test_yesterday(self): self.assertEqual(when.yesterday(), self.today - self.one_day)
def test_yesterday(self): """Test when.yesterday()""" self.assertEqual(when.yesterday(), self.today - self.one_day)