@@ -38,7 +38,7 @@ class Feed(object):
3838 def __init__ (self , url ):
3939 self .url = encodeValue (url )
4040 self .rss = None
41- # TODO self.dom = None ;; speed up Feedparser
41+ # TODO self.dom = None, speed up Feedparser
4242
4343
4444class Source (object ):
@@ -107,35 +107,21 @@ def build(self):
107107
108108 self .generate_articles ()
109109
110- def purge_articles (self , reason , in_articles = None ):
110+ def purge_articles (self , reason , articles ):
111111 """
112112 Delete rejected articles, if there is an articles param, we
113113 purge from there, otherwise purge from our source instance.
114+
115+ Reference this excellent StackOverflow post for some of the wonky
116+ syntax below:
117+ http://stackoverflow.com/questions/1207406/remove-items-from-a-
118+ list-while-iterating-in-python
114119 """
115- # TODO Figure out why using the 'del' command on input list reference
116- # isn't actually filtering the list?!
117- # cur_articles = self.articles if in_articles is None else in_articles
118- new_articles = []
119-
120- for index , article in enumerate (in_articles ):
121- if reason == 'url' and not article .is_valid_url ():
122- #print 'deleting article', cur_articles[index].url
123- #del cur_articles[index]
124- #del in_articles[index]
125- pass
126- elif reason == 'url' :
127- new_articles .append (in_articles [index ])
128-
129- if reason == 'body' and not article .is_valid_body ():
130- #del cur_articles[index]
131- pass
132- elif reason == 'body' :
133- new_articles .append (in_articles [index ])
134-
135- if in_articles is not None : # if they give an input, output filtered
136- return new_articles
137- #else: # no input, we are playing with self.articles
138- # self.articles = new_articles
120+ if reason == 'url' :
121+ articles [:] = [a for a in articles if a .is_valid_url ()]
122+ elif reason == 'body' :
123+ articles [:] = [a for a in articles if a .is_valid_body ()]
124+ return articles
139125
140126 @cache_disk (seconds = (86400 * 1 ), cache_folder = ANCHOR_DIRECTORY )
141127 def _get_category_urls (self , domain ):
@@ -270,7 +256,7 @@ def feeds_to_articles(self):
270256 url = url ,
271257 source_url = self .url ,
272258 config = self .config
273- # title=? # TODO: It **must** be fast
259+ # (pre) title=? # TODO: It **must** be fast
274260 )
275261 cur_articles .append (article )
276262
@@ -343,10 +329,7 @@ def generate_articles(self, limit=5000):
343329 """
344330 articles = self ._generate_articles ()
345331 self .articles = articles [:limit ]
346-
347- # for a in self.articles:
348- # print 'test examine url:', a.url
349- # log.critical('total', len(articles), 'articles and cutoff was at', limit)
332+ # log.debug('total', len(articles), 'articles and cutoff was at', limit)
350333
351334 # @print_duration
352335 def download_articles (self , threads = 1 ):
@@ -387,7 +370,7 @@ def download_articles(self, threads=1):
387370
388371 def parse_articles (self ):
389372 """
390- Sync parse all articles, delete if too small.
373+ Parse all articles, delete if too small.
391374 """
392375 for index , article in enumerate (self .articles ):
393376 article .parse ()
0 commit comments