Better content insertion
Also takes care of description, by creating one, when missing.
This commit is contained in:
		
							
								
								
									
										20
									
								
								morss.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								morss.py
									
									
									
									
									
								
							@@ -81,6 +81,22 @@ def countWord(txt):
 | 
				
			|||||||
	else:
 | 
						else:
 | 
				
			||||||
		return 0
 | 
							return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def makeDesc(txt, length, suffix='...'):
 | 
				
			||||||
 | 
						' '.join(txt.split()[:length]) + suffix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def setContent(item, txt):
 | 
				
			||||||
 | 
						if not item.desc:
 | 
				
			||||||
 | 
							if item.content:
 | 
				
			||||||
 | 
								log('content alone')
 | 
				
			||||||
 | 
								item.desc = item.content
 | 
				
			||||||
 | 
								item.content = txt
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								log('empty')
 | 
				
			||||||
 | 
								item.desc = makeDesc(txt, 30)
 | 
				
			||||||
 | 
								item.content = txt
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							item.content = txt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def parseOptions(available):
 | 
					def parseOptions(available):
 | 
				
			||||||
	options = None
 | 
						options = None
 | 
				
			||||||
	if 'REQUEST_URI' in os.environ:
 | 
						if 'REQUEST_URI' in os.environ:
 | 
				
			||||||
@@ -268,7 +284,7 @@ def Fill(item, cache, feedurl="/", fast=False):
 | 
				
			|||||||
				log('old error')
 | 
									log('old error')
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			log('cached')
 | 
								log('cached')
 | 
				
			||||||
			item.content = cache.get(item.link)
 | 
								setContent(item, cache.get(item.link))
 | 
				
			||||||
			return True
 | 
								return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# super-fast mode
 | 
						# super-fast mode
 | 
				
			||||||
@@ -288,7 +304,7 @@ def Fill(item, cache, feedurl="/", fast=False):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	out = readability.Document(data, url=url).summary(True)
 | 
						out = readability.Document(data, url=url).summary(True)
 | 
				
			||||||
	if countWord(out) > max(count_content, count_desc) > 0:
 | 
						if countWord(out) > max(count_content, count_desc) > 0:
 | 
				
			||||||
		item.content = out
 | 
							setContent(item, out)
 | 
				
			||||||
		cache.set(item.link, out)
 | 
							cache.set(item.link, out)
 | 
				
			||||||
	else:
 | 
						else:
 | 
				
			||||||
		log('not bigger enough')
 | 
							log('not bigger enough')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user