Handle more errors
This commit is contained in:
		
							
								
								
									
										20
									
								
								morss
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								morss
									
									
									
									
									
								
							@@ -21,7 +21,7 @@ items =	rss.xpath('//item')
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
cache = expanduser("~") + "/.cache/morss"
 | 
					cache = expanduser("~") + "/.cache/morss"
 | 
				
			||||||
if not os.path.exists(cache):
 | 
					if not os.path.exists(cache):
 | 
				
			||||||
    os.makedirs(cache)
 | 
						os.makedirs(cache)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for item in items:
 | 
					for item in items:
 | 
				
			||||||
	title =	item.findtext('title')
 | 
						title =	item.findtext('title')
 | 
				
			||||||
@@ -32,6 +32,7 @@ for item in items:
 | 
				
			|||||||
	log(link)
 | 
						log(link)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	cached = cache + "/" + str(hash(link))
 | 
						cached = cache + "/" + str(hash(link))
 | 
				
			||||||
 | 
						log(cached)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if os.path.exists(cached):
 | 
						if os.path.exists(cached):
 | 
				
			||||||
		log("cached")
 | 
							log("cached")
 | 
				
			||||||
@@ -43,15 +44,22 @@ for item in items:
 | 
				
			|||||||
			match =	html.xpath(node)
 | 
								match =	html.xpath(node)
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
			if len(match):
 | 
								if len(match):
 | 
				
			||||||
				text =	etree.tostring(match[0])
 | 
									try:
 | 
				
			||||||
				log("ok txt")
 | 
										text =	etree.tostring(match[0])
 | 
				
			||||||
				desc.text = text
 | 
										log("ok txt")
 | 
				
			||||||
				open(cached, 'w').write(text)
 | 
									except etree.SerialisationError:
 | 
				
			||||||
 | 
										log('serialisation')
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									try:
 | 
				
			||||||
 | 
										desc.text = text
 | 
				
			||||||
 | 
										open(cached, 'w').write(text)
 | 
				
			||||||
 | 
									except ValueError:
 | 
				
			||||||
 | 
										log('error')
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				log("no match")
 | 
									log("no match")
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		except urllib2.HTTPError, error:
 | 
							except urllib2.HTTPError, error:
 | 
				
			||||||
	    		log("error")
 | 
								log("error")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if len(sys.argv) == 2:
 | 
					if len(sys.argv) == 2:
 | 
				
			||||||
	print etree.tostring(rss)
 | 
						print etree.tostring(rss)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user