def test_to_business_day(): assert datetime.date(2015, 12, 1) == \ to_biz_date(datetime.datetime(2015, 12, 1, 23, 59, 59)) assert datetime.date(2015, 12, 1) == \ to_biz_date(datetime.datetime(2015, 12, 2, 0, 0, 0)) assert datetime.date(2015, 12, 1) == \ to_biz_date(datetime.datetime(2015, 12, 2, 5, 59, 59)) assert datetime.date(2015, 12, 2) == \ to_biz_date(datetime.datetime(2015, 12, 2, 6, 0, 0))
def process_attendance(self, data): """:rtype: (Attendance, bool)""" if data.get('clock_in') is None or data.get('clock_out') is None: raise NotOurDataException try: pk = Attendance.composite_pk( data['girl_id'], to_biz_date(data['checked_term'])) return Attendance.find_by_pk_with_cache(pk), False except Attendance.DoesNotExist: atnd = Attendance() atnd.girl = Girl.find_by_pk_with_cache(data['girl_id']) atnd.date = to_biz_date(data['checked_term']) atnd.clock_in = data['clock_in'] atnd.clock_out = data['clock_out'] self.save_or_raise(atnd) return atnd, True
def handle(self, *args, **options): biz_date = to_biz_date(datetime.datetime.now()) file_path = jsonl_file_path(biz_date) reader = Reader(file_path) organizer = Organizer() for data in reader.readlines(): try: organizer.organize(data) except InvalidDataException: print "invalid-data\t" + str(data)
def handle(self, *args, **options): biz_date = to_biz_date(datetime.datetime.now()) file_path = jsonl_file_path(biz_date) writer = Writer(file_path) for shop in Shop.scrapeable(): print shop.id # TODO django-logging page = Page(shop) scr = Scraper(page) data = scr.extract_data() writer.write(data) writer.file.close()
def process_status_log(self, data): """:rtype: (StatusLog, bool)""" if not data.get('status') in ('off', 'work', 'wait'): raise NotOurDataException checked_at = data.get('checked_term') atnd_id = Attendance.composite_pk( data['girl_id'], to_biz_date(checked_at)) try: pk = StatusLog.composite_pk(atnd_id, checked_at) return StatusLog.find_by_pk_with_cache(pk), False except StatusLog.DoesNotExist: stat = StatusLog() stat.attendance = Attendance.find_by_pk_with_cache(atnd_id) stat.checked_at = checked_at stat.status = data['status'] self.save_or_raise(stat) return stat, True