mirror of
				https://github.com/searxng/searxng
				synced 2024-01-01 19:24:07 +01:00 
			
		
		
		
	[fix] yahoo news date parsing
This commit is contained in:
		
							parent
							
								
									12d91c1d67
								
							
						
					
					
						commit
						46a2c63f8e
					
				
					 1 changed files with 11 additions and 8 deletions
				
			
		|  | @ -80,16 +80,19 @@ def response(resp): | ||||||
| 
 | 
 | ||||||
|         # still useful ? |         # still useful ? | ||||||
|         if re.match("^[0-9]+ minute(s|) ago$", publishedDate): |         if re.match("^[0-9]+ minute(s|) ago$", publishedDate): | ||||||
|             publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group()))  # noqa |             publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group())) | ||||||
|  |         elif re.match("^[0-9]+ days? ago$", publishedDate): | ||||||
|  |             publishedDate = datetime.now() - timedelta(days=int(re.match(r'\d+', publishedDate).group())) | ||||||
|  |         elif re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", publishedDate): | ||||||
|  |             timeNumbers = re.findall(r'\d+', publishedDate) | ||||||
|  |             publishedDate = datetime.now()\ | ||||||
|  |                 - timedelta(hours=int(timeNumbers[0]))\ | ||||||
|  |                 - timedelta(minutes=int(timeNumbers[1])) | ||||||
|         else: |         else: | ||||||
|             if re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", |             try: | ||||||
|                         publishedDate): |  | ||||||
|                 timeNumbers = re.findall(r'\d+', publishedDate) |  | ||||||
|                 publishedDate = datetime.now()\ |  | ||||||
|                     - timedelta(hours=int(timeNumbers[0]))\ |  | ||||||
|                     - timedelta(minutes=int(timeNumbers[1])) |  | ||||||
|             else: |  | ||||||
|                 publishedDate = parser.parse(publishedDate) |                 publishedDate = parser.parse(publishedDate) | ||||||
|  |             except: | ||||||
|  |                 publishedDate = datetime.now() | ||||||
| 
 | 
 | ||||||
|         if publishedDate.year == 1900: |         if publishedDate.year == 1900: | ||||||
|             publishedDate = publishedDate.replace(year=datetime.now().year) |             publishedDate = publishedDate.replace(year=datetime.now().year) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Adam Tauber
						Adam Tauber