def main(wf): # Get the date format from the configuration update_settings(wf) args = wf.args command_parser = DateParser(wf.settings) try: command = command_parser.parse_command(args[0]) if hasattr(command, "dateTime"): output = do_timespans(command, wf.settings) if hasattr(command, "dateFormat"): setattr(command, "dateTime", output) # and run it through the functions function output = do_formats(command, wf.settings) elif hasattr(command, "dateTime1") and hasattr(command, "dateTime2"): output = do_subtraction(command, wf.settings) else: output = "Invalid Expression" except SyntaxError: output = "Invalid Command" except ValueError: output = "Invalid Date/time" except FormatError: output = "Invalid format" except IncompatibleFunctionError: output = "Invalid command - Don't use exclusions and formats together." except UnknownExclusionTypeError: output = "Invalid exclusion - Try again." except ExclusionNoDaysFoundError: output = "All days excluded" except ExclusionTooFarAheadError: output = "That's too far into the future" if output.startswith("Invalid"): wf.add_item(title=". . .", subtitle=output, valid=False, arg=args[0], icon=ICON_ERROR) else: wf.add_item(title=output, subtitle="Copy to clipboard", valid=True, arg=output) wf.send_feedback()
def __init__(self, settings): # Call super constructor in an oddly clumsy way. DateParser.__init__(self, settings) self.anniversary_name_re = re.compile('[a-z_]{2,}', re.IGNORECASE) self.add_command_re = re.compile('add', re.IGNORECASE) self.delete_command_re = re.compile('delete', re.IGNORECASE) self.edit_command_re = re.compile('edit', re.IGNORECASE)
def get_date(ocr): """Using DateParser this function process given OCR data and returns date :param ocr: as eated OCR data from an image :return: date :raise: need to handle if passing data is empty """ date_parser = DateParser(ocr) found_date = date_parser.get_date() if found_date is None: return datetime.now().strftime('%d-%m-%Y') else: return found_date
def test_bulk_image(self, path): """This function reads all images in a given directory, read OCR Data and returns expected value :param path: Directory path which contain images :return: expected value like date, total, ht, tva etc. :raise: need to handle except""" images = glob2.glob(path + "/*.*") print('--- Start recognize text from image ---') for image in images: print("Date for" + image) str = self.get_string(image) date = DateParser(str) date_found = date.get_date() print(date_found) print("--------------") print("------ Done -------")
def test_bulk_image(): # Path of working folder on Disk src_path = "./receipt/" images = glob2.glob("./receipt/*.*") print('--- Start recognize text from image ---') for image in images: print("Date for" + image) str = get_string(image) date = DateParser(str) date_found = date.get_date() print(date_found) print("--------------") #file = open(src_path + "01.png.txt", "w") #file.write(str) #file.close() print("------ Done -------")
def parser_init(self): self.province_parser = ProvinceParser(self.province_conf_path, self.phonenum_conf_path, self.region_conf_path, self.city_conf_path) self.company_parser = CompanyParser(self.company_pre_path) self.case_cause_parser = CaseCauseParser(self.casecause_conf_path) self.date_parser = DateParser() self.excel_parser = ExcelParser() self.money_parser = MoneyParser() self.caseid_parser = CaseIdParser() self.litigant_util_parser = LitigantUtil(self.litigant_conf_path) self.bid_money_parser = Bid_money_parser() self.bid_company_parser = Bid_company_parser(self.company_parser) self.bid_region_parser = BidRegionParser(self.province_parser) self.bid_close_time_parser = BidCloseTimeParser(self.date_parser) self.fygg_parser = Fygg_parser(self.plaintiff_conf_path,self.defendant_conf_path) self.wenshu_parser = Wenshu_parser() self.court_parser = CourtParser(self.court_conf_path) self.court_place_parser = CourtPlaceParser(self.court_place_conf_path) self.industry_parser = IndustryParser(self.industry_parser_model_path)
def test_date_range(self, test_input, start_date, end_date): date_parser = DateParser() result = date_parser.parse(test_input) assert result[0].start_date.date == date(*start_date) assert result[0].end_date.date == date(*end_date) print("{0} = {1}".format(test_input, result))
def test_simple_date(self, test_input, expected): date_parser = DateParser() result = date_parser.parse(test_input) assert result[0].date == date(*expected) print("{0} = {1}".format(test_input, result))
def get_date(ocr): date_parser = DateParser(ocr) found_date = date_parser.get_date() return found_date