[fix] brave.news
This commit is contained in:
		
							parent
							
								
									140125e641
								
							
						
					
					
						commit
						27477f51fd
					
				| @ -219,8 +219,7 @@ def response(resp): | |||||||
|     json_resp = json_data[1]['data']['body']['response'] |     json_resp = json_data[1]['data']['body']['response'] | ||||||
| 
 | 
 | ||||||
|     if brave_category == 'news': |     if brave_category == 'news': | ||||||
|         json_resp = json_resp['news'] |         return _parse_news(json_resp['news']) | ||||||
|         return _parse_news(json_resp) |  | ||||||
| 
 | 
 | ||||||
|     if brave_category == 'images': |     if brave_category == 'images': | ||||||
|         return _parse_images(json_resp) |         return _parse_images(json_resp) | ||||||
| @ -299,7 +298,7 @@ def _parse_news(json_resp): | |||||||
|             'title': result['title'], |             'title': result['title'], | ||||||
|             'content': result['description'], |             'content': result['description'], | ||||||
|         } |         } | ||||||
|         if result['thumbnail'] != "null": |         if result['thumbnail'] is not None: | ||||||
|             item['img_src'] = result['thumbnail']['src'] |             item['img_src'] = result['thumbnail']['src'] | ||||||
|         result_list.append(item) |         result_list.append(item) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -40,6 +40,7 @@ _ECMA_UNESCAPE2_RE = re.compile(r'%([0-9a-fA-F]{2})', re.UNICODE) | |||||||
| 
 | 
 | ||||||
| _JS_QUOTE_KEYS_RE = re.compile(r'([\{\s,])(\w+)(:)') | _JS_QUOTE_KEYS_RE = re.compile(r'([\{\s,])(\w+)(:)') | ||||||
| _JS_VOID_RE = re.compile(r'void\s+[0-9]+|void\s*\([0-9]+\)') | _JS_VOID_RE = re.compile(r'void\s+[0-9]+|void\s*\([0-9]+\)') | ||||||
|  | _JS_DECIMAL_RE = re.compile(r":\s*\.") | ||||||
| 
 | 
 | ||||||
| _STORAGE_UNIT_VALUE: Dict[str, int] = { | _STORAGE_UNIT_VALUE: Dict[str, int] = { | ||||||
|     'TB': 1024 * 1024 * 1024 * 1024, |     'TB': 1024 * 1024 * 1024 * 1024, | ||||||
| @ -699,7 +700,7 @@ def js_variable_to_python(js_variable): | |||||||
|             # replace simple quote by double quote |             # replace simple quote by double quote | ||||||
|             parts[i] = '"' |             parts[i] = '"' | ||||||
|             in_string = None |             in_string = None | ||||||
|         # | 
 | ||||||
|         if not in_string: |         if not in_string: | ||||||
|             # replace void 0 by null |             # replace void 0 by null | ||||||
|             # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void |             # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void | ||||||
| @ -714,6 +715,7 @@ def js_variable_to_python(js_variable): | |||||||
|     # becomes |     # becomes | ||||||
|     # { "a": 12 } |     # { "a": 12 } | ||||||
|     s = _JS_QUOTE_KEYS_RE.sub(r'\1"\2"\3', s) |     s = _JS_QUOTE_KEYS_RE.sub(r'\1"\2"\3', s) | ||||||
|  |     s = _JS_DECIMAL_RE.sub(":0.", s) | ||||||
|     # replace the surogate character by colon |     # replace the surogate character by colon | ||||||
|     s = s.replace(chr(1), ':') |     s = s.replace(chr(1), ':') | ||||||
|     # load the JSON and return the result |     # load the JSON and return the result | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 jazzzooo
						jazzzooo