comparison publish_edition.py @ 28:6e2038000082

added dry-run cmdline option
author Atul Varma <varmaa@toolness.com>
date Sun, 03 Jan 2010 09:20:29 -0800
parents 83091b7b3e59
children 6fbd38dd976a
comparison
equal deleted inserted replaced
27:83091b7b3e59 28:6e2038000082
137 137
138 return normalize(filtered_articles) 138 return normalize(filtered_articles)
139 139
140 def publish_edition(update_whoisi=False, 140 def publish_edition(update_whoisi=False,
141 update_urls=False, 141 update_urls=False,
142 update_articles=False): 142 update_articles=False,
143 dry_run=False):
143 if update_whoisi: 144 if update_whoisi:
144 update_urls = True 145 update_urls = True
145 if update_urls: 146 if update_urls:
146 update_articles = True 147 update_articles = True
147 148
168 169
169 if update_whoisi: 170 if update_whoisi:
170 people_indexes = [people.index(person) 171 people_indexes = [people.index(person)
171 for person in following] 172 for person in following]
172 wicache.refresh_people(people_indexes) 173 wicache.refresh_people(people_indexes)
173 save(people, WHOISI_FILENAME) 174 if not dry_run:
175 save(people, WHOISI_FILENAME)
174 176
175 feeds = {} 177 feeds = {}
176 178
177 for person in following: 179 for person in following:
178 person_feeds = [] 180 person_feeds = []
183 185
184 urls = load(URLS_FILENAME, {}) 186 urls = load(URLS_FILENAME, {})
185 187
186 if update_urls: 188 if update_urls:
187 refresh_urls(feeds=feeds, urls=urls) 189 refresh_urls(feeds=feeds, urls=urls)
188 save(urls, URLS_FILENAME) 190 if not dry_run:
191 save(urls, URLS_FILENAME)
189 192
190 articles = load(ARTICLES_FILENAME, {}) 193 articles = load(ARTICLES_FILENAME, {})
191 194
192 if update_articles: 195 if update_articles:
193 refresh_articles(articles=articles, 196 refresh_articles(articles=articles,
194 feeds=feeds, 197 feeds=feeds,
195 urls=urls) 198 urls=urls)
196 save(articles, ARTICLES_FILENAME) 199 if not dry_run:
200 save(articles, ARTICLES_FILENAME)
197 201
198 issues = load(ISSUES_FILENAME, {'urls': {}, 202 issues = load(ISSUES_FILENAME, {'urls': {},
199 'pub_dates': []}) 203 'pub_dates': []})
200 204
201 filtered_articles = filter_articles(names=names, 205 filtered_articles = filter_articles(names=names,
205 issue_id = len(issues['pub_dates']) 209 issue_id = len(issues['pub_dates'])
206 issues['pub_dates'].append(datetime.now()) 210 issues['pub_dates'].append(datetime.now())
207 for author in filtered_articles: 211 for author in filtered_articles:
208 for article in filtered_articles[author]: 212 for article in filtered_articles[author]:
209 issues['urls'][article['url']] = issue_id 213 issues['urls'][article['url']] = issue_id
210 save(issues, ISSUES_FILENAME) 214 if not dry_run:
211 215 save(issues, ISSUES_FILENAME)
212 json.dump({'authors': names, 'articles': filtered_articles}, 216
213 open(JSON_FILENAME, 'w')) 217 if not dry_run:
214 218 json.dump({'authors': names, 'articles': filtered_articles},
215 logging.info('wrote %s (issue #%d).' % (JSON_FILENAME, issue_id)) 219 open(JSON_FILENAME, 'w'))
220
221 logging.info('wrote %s (issue #%d).' % (JSON_FILENAME, issue_id))
216 222
217 parser_options = { 223 parser_options = {
218 ('-w', '--refresh-whoisi',): 224 ('-w', '--refresh-whoisi',):
219 dict(dest='update_whoisi', 225 dict(dest='update_whoisi',
220 help='re-sync with whoisi.com', 226 help='re-sync with whoisi.com',
230 ('-p', '--reparse-feeds',): 236 ('-p', '--reparse-feeds',):
231 dict(dest='update_articles', 237 dict(dest='update_articles',
232 help='re-parse feeds', 238 help='re-parse feeds',
233 action='store_true', 239 action='store_true',
234 default=False), 240 default=False),
241
242 ('-d', '--dry-run',):
243 dict(dest='dry_run',
244 help='do not write anything to disk',
245 action='store_true',
246 default=False),
235 } 247 }
236 248
237 if __name__ == '__main__': 249 if __name__ == '__main__':
238 logging.basicConfig(level=logging.DEBUG) 250 logging.basicConfig(level=logging.DEBUG)
239 251