How to use the dateparser.search function in dateparser

To help you get started, we’ve selected a few dateparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vinayak-mehta / conrad / scrapers / papercall.py View on Github external
location = title_parts[1]
		try:
			url = event.select('.fa-external-link')[0]['title']
		except IndexError:
			url = ''
		cfp_close_label = event.find(lambda elm: elm.name == 'strong' and 'CFP closes at' in elm.string)
		if not cfp_close_label:
			# No real point.
			continue
		cfp_close = dateparser.parse(cfp_close_label.parent.find_next_sibling('td').string.strip())
		start_date = end_date = None
		dates = event.find(lambda elm: elm.name == 'strong' and 'Event Dates' in elm.string)
		if dates:
			dates = dates.next_sibling.string.strip()
		if dates:
			parsed_dates = [d for _, d in dateparser.search.search_dates(dates)]
			if parsed_dates:
				start_date = parsed_dates[0].date()
				end_date = parsed_dates[-1].date()
		tags = [t.string for t in event.select('a[href^="/events?keywords=tags"]')]		
		conrad = {}
		"""
		Conrad Format
		"""
		conrad["cfp_end_date"]= cfp_close.strftime("%Y-%m-%d")
		today = datetime.datetime.now().replace(tzinfo=None)
		if cfp_close > cfp_close:
			conrad["cfp_open"] = False
		else:
			conrad["cfp_open"] = True
		conrad["cfp_start_date"] = "2019-10-01"
		conrad["city"]= location.split(',')[0]
github vinayak-mehta / conrad / crawlers / papercall / papercall_crawler.py View on Github external
lambda elm: elm.name == "strong" and "CFP closes at" in elm.string
        )
        if not cfp_close_label:
            # No real point.
            continue
        cfp_close = dateparser.parse(
            cfp_close_label.parent.find_next_sibling("td").string.strip()
        )
        start_date = end_date = None
        dates = event.find(
            lambda elm: elm.name == "strong" and "Event Dates" in elm.string
        )
        if dates:
            dates = dates.next_sibling.string.strip()
        if dates:
            parsed_dates = [d for _, d in dateparser.search.search_dates(dates)]
            if parsed_dates:
                start_date = parsed_dates[0].date()
                end_date = parsed_dates[-1].date()
        tags = [t.string for t in event.select('a[href^="/events?keywords=tags"]')]

        today = dateparser.parse("now UTC")
        cfp_open = False if today > cfp_close else True
        try:
            city = location.split(",")[0]
            country = location.split(",")[1]
        except IndexError:
            city = country = location

        yield {
            "name": title,
            "url": url,
github MaxValue / Terpene-Profile-Parser-for-Cannabis-Strains / labs / sclabs / parser.py View on Github external
# 	write_to_logfile(
	# 		filepath=logfile_time_tested_noneFound,
	# 		fieldnames=['Filename'],
	# 		data={'Filename':raw_sample_file_name}
	# 	)

	# 7 Receipt Time
	receipt_time = None
	raw_receipt_time = get_single_value(
		tree=tree,
		xpath=xpath_time_received,
		fallback=''
	)
	if raw_receipt_time.lower().startswith('date submitted: '):
		raw_receipt_time = raw_receipt_time[16:]
	possible_dates = dateparser_search.search_dates(
		text=raw_receipt_time,
		languages=['en'],
		settings={'DATE_ORDER':'MDY','STRICT_PARSING':True}
	)
	if type(possible_dates) == list and len(possible_dates) == 1:
		receipt_time = possible_dates[0][1].date().isoformat()
	else:
		write_to_logfile(
			filepath=logfile_time_received_notDate,
			fieldnames=['Filename'],
			data={'Filename':raw_sample_file_name}
		)

	if terpenes_data == {} and cannabinoid_data == {}:
		skip_this_file = True
github MaxValue / Terpene-Profile-Parser-for-Cannabis-Strains / labs / analytical360 / parser.py View on Github external
errparams=[raw_sample_file_name]
		)
		test_uid_match = re_test_uid.match(raw_test_uid)
		if test_uid_match:
			test_uid = test_uid_match.group('uid')

		# 6 Test Time
		test_time = None
		raw_test_time = get_single_value(
			tree=tree,
			xpath=xpath_time_tested,
			fallback=''
		)
		re_date_match = re_date_tested.match(raw_test_time)
		if re_date_match:
			possible_dates = dateparser_search.search_dates(
				text=raw_test_time,
				languages=['en'],
				settings={'DATE_ORDER':'MDY','STRICT_PARSING':True}
			)
			if type(possible_dates) == list and len(possible_dates) == 1:
				test_time = possible_dates[0][1].date().isoformat()
			else:
				logging.warning('%s: Test date (%s) was not understood.', raw_sample_file_name, raw_test_time)
		else:
			logging.error('%s: No test date was found (%s).', raw_sample_file_name, raw_test_time)

		# 7 Receipt Time
		receipt_time = None

		# 8 Post Time
		post_time = None
github MaxValue / Terpene-Profile-Parser-for-Cannabis-Strains / labs / analytical360 / parser.py View on Github external
else:
			logging.error('%s: No test date was found (%s).', raw_sample_file_name, raw_test_time)

		# 7 Receipt Time
		receipt_time = None

		# 8 Post Time
		post_time = None
		raw_post_time = get_single_value(
			tree=tree,
			xpath=xpath_time_posted,
			fallback=''
		)
		re_date_match = re_date_posted.match(raw_post_time)
		if re_date_match:
			possible_dates = dateparser_search.search_dates(
				text=raw_post_time,
				languages=['en'],
				settings={'DATE_ORDER':'MDY','STRICT_PARSING':True}
			)
			if type(possible_dates) == list and len(possible_dates) == 1:
				post_time = possible_dates[0][1].date().isoformat()
			else:
				logging.warning('%s: Post date (%s) was not understood.', raw_sample_file_name, raw_post_time)
		else:
			logging.error('%s: No post date was found (%s).', raw_sample_file_name, raw_post_time)

		if terpenes_data == {} and cannabinoid_data == {}:
			skip_this_file = True

		sample_data = {
			'Test Result UID':test_uid,
github MaxValue / Terpene-Profile-Parser-for-Cannabis-Strains / labs / psilabs / parser.py View on Github external
errparams=[raw_sample_file_name]
		)
		test_uid_match = re_test_uid.match(raw_test_uid)
		if test_uid_match:
			test_uid = test_uid_match.group('uid')

		# 6 Test Time
		test_time = None
		raw_test_time = get_single_value(
			tree=tree,
			xpath=xpath_time_tested,
			fallback=''
		)
		re_date_match = re_date.match(raw_test_time)
		if re_date_match:
			possible_dates = dateparser_search.search_dates(
				text=raw_test_time,
				languages=['en'],
				settings={'DATE_ORDER':'MDY','STRICT_PARSING':True}
			)
			if type(possible_dates) == list and len(possible_dates) == 1:
				test_time = possible_dates[0][1].date().isoformat()
			else:
				logging.warning('%s: Test date (%s) was not understood.', raw_sample_file_name, raw_test_time)
		else:
			logging.error('%s: No test date was found (%s).', raw_sample_file_name, raw_test_time)

		# 7 Receipt Time
		receipt_time = None
		raw_receipt_time = get_single_value(
			tree=tree,
			xpath=xpath_time_received,
github MaxValue / Terpene-Profile-Parser-for-Cannabis-Strains / labs / psilabs / parser.py View on Github external
test_time = possible_dates[0][1].date().isoformat()
			else:
				logging.warning('%s: Test date (%s) was not understood.', raw_sample_file_name, raw_test_time)
		else:
			logging.error('%s: No test date was found (%s).', raw_sample_file_name, raw_test_time)

		# 7 Receipt Time
		receipt_time = None
		raw_receipt_time = get_single_value(
			tree=tree,
			xpath=xpath_time_received,
			fallback=''
		)
		re_date_match = re_date.match(raw_receipt_time)
		if re_date_match:
			possible_dates = dateparser_search.search_dates(
				text=raw_receipt_time,
				languages=['en'],
				settings={'DATE_ORDER':'MDY','STRICT_PARSING':True}
			)
			if type(possible_dates) == list and len(possible_dates) == 1:
				receipt_time = possible_dates[0][1].date().isoformat()
			else:
				logging.warning('%s: Receipt date (%s) was not understood.', raw_sample_file_name, raw_receipt_time)
		else:
			logging.error('%s: No receipt date was found (%s).', raw_sample_file_name, raw_receipt_time)

		if terpenes_data == {} and cannabinoid_data == {}:
			skip_this_file = True

		sample_data = {
			'Test Result UID':test_uid,