mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Cleaning up exception handling of feeds to show to users during import.
This commit is contained in:
parent
68b0ae7254
commit
8b9c28e8f8
6 changed files with 35 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import urlparse
|
||||
import time
|
||||
from utils import log as logging
|
||||
import oauth2 as oauth
|
||||
from django.contrib.sites.models import Site
|
||||
|
@ -105,10 +106,9 @@ def reader_callback(request):
|
|||
client = oauth.Client(consumer, token)
|
||||
resp, content = client.request(access_token_url, "POST")
|
||||
access_token = dict(urlparse.parse_qsl(content))
|
||||
original_token = dict(urlparse.parse_qsl(token))
|
||||
logging.info(" ---> [%s] OAuth Reader Content: %s -- %s" % (token, access_token, content))
|
||||
user_token.access_token = access_token.get('oauth_token') or original_token.get('oauth_token')
|
||||
user_token.access_token_secret = access_token.get('oauth_token_secret') or original_token.get('oauth_token_secret')
|
||||
logging.info(" ---> [%s] OAuth Reader Content: %s -- %s" % (request.user, token, access_token))
|
||||
user_token.access_token = access_token.get('oauth_token')
|
||||
user_token.access_token_secret = access_token.get('oauth_token_secret')
|
||||
user_token.save()
|
||||
|
||||
# Fetch imported feeds on next page load
|
||||
|
|
|
@ -33,7 +33,7 @@ class Command(BaseCommand):
|
|||
if options['skip']:
|
||||
feeds = Feed.objects.filter(next_scheduled_update__lte=now,
|
||||
average_stories_per_month__lt=options['skip'],
|
||||
is_active=True)
|
||||
active=True)
|
||||
print " ---> Skipping %s feeds" % feeds.count()
|
||||
for feed in feeds:
|
||||
feed.set_next_scheduled_update()
|
||||
|
|
|
@ -71,9 +71,10 @@ class Feed(models.Model):
|
|||
old_fetch_histories = self.feed_fetch_history.all()[10:]
|
||||
for history in old_fetch_histories:
|
||||
history.delete()
|
||||
|
||||
|
||||
if status_code >= 400:
|
||||
self.count_errors_in_history(self.feed_fetch_history)
|
||||
fetch_history = self.feed_fetch_history.all().values('status_code')
|
||||
self.count_errors_in_history(fetch_history)
|
||||
|
||||
def save_page_history(self, status_code, message, exception=None):
|
||||
PageFetchHistory.objects.create(feed=self,
|
||||
|
@ -85,15 +86,16 @@ class Feed(models.Model):
|
|||
history.delete()
|
||||
|
||||
if status_code >= 400:
|
||||
self.count_errors_in_history(self.page_fetch_history)
|
||||
fetch_history = self.page_fetch_history.all().values('status_code')
|
||||
self.count_errors_in_history(fetch_history)
|
||||
|
||||
def count_errors_in_history(self, history_model):
|
||||
fetch_histories = history_model.all()
|
||||
non_errors = [h for h in fetch_histories if h.status_code < 400]
|
||||
errors = [h for h in fetch_histories if h.status_code >= 400]
|
||||
def count_errors_in_history(self, fetch_history):
|
||||
non_errors = [h for h in fetch_history if h['status_code'] < 400]
|
||||
errors = [h for h in fetch_history if h['status_code'] >= 400]
|
||||
|
||||
if len(non_errors) == 0 and len(errors) >= 1:
|
||||
self.exception = True
|
||||
self.is_active = False
|
||||
self.has_exception = True
|
||||
self.active = False
|
||||
self.save()
|
||||
|
||||
def count_subscribers(self, verbose=False, lock=None):
|
||||
|
@ -257,9 +259,9 @@ class Feed(models.Model):
|
|||
s.save(force_insert=True)
|
||||
ret_values[ENTRY_NEW] += 1
|
||||
cache.set('updated_feed:%s' % self.id, 1)
|
||||
except IntegrityError, e:
|
||||
except IntegrityError:
|
||||
ret_values[ENTRY_ERR] += 1
|
||||
print('Saving new story, IntegrityError: %s - %s: %s' % (self.feed_title, story.get('title'), e))
|
||||
# print('Saving new story, IntegrityError: %s - %s: %s' % (self.feed_title, story.get('title'), e))
|
||||
[s.tags.add(tcat) for tcat in story_tags]
|
||||
elif existing_story and story_has_changed:
|
||||
# update story
|
||||
|
@ -300,9 +302,9 @@ class Feed(models.Model):
|
|||
s.save(force_update=True)
|
||||
ret_values[ENTRY_UPDATED] += 1
|
||||
cache.set('updated_feed:%s' % self.id, 1)
|
||||
except IntegrityError, e:
|
||||
except IntegrityError:
|
||||
ret_values[ENTRY_ERR] += 1
|
||||
print('Saving updated story, IntegrityError: %s - %s' % (self.feed_title, story.get('title')))
|
||||
# print('Saving updated story, IntegrityError: %s - %s' % (self.feed_title, story.get('title')))
|
||||
else:
|
||||
ret_values[ENTRY_SAME] += 1
|
||||
# logging.debug("Unchanged story: %s " % story.get('title'))
|
||||
|
|
|
@ -2698,4 +2698,14 @@ background: transparent;
|
|||
.NB-modal-statistics .NB-statistics-subscribers-count {
|
||||
color: #A8A8A8;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
/* ========================= */
|
||||
/* = Feed Exceptions Modal = */
|
||||
/* ========================= */
|
||||
|
||||
.NB-modal-exception .NB-exception-explanation {
|
||||
color: #606060;
|
||||
font-size: 12px;
|
||||
margin: 24px 0;
|
||||
}
|
|
@ -28,7 +28,7 @@ NEWSBLUR.ReaderFeedException.prototype = {
|
|||
$.make('img', { className: 'NB-modal-feed-image feed_favicon', src: this.google_favicon_url + this.feed.feed_link }),
|
||||
$.make('span', { className: 'NB-modal-feed-title' }, this.feed.feed_title)
|
||||
]),
|
||||
'Not much to do yet. Soon you will be able to fix the URL, delete the feed, or force a retry.',
|
||||
$.make('div', { className: 'NB-exception-explanation' }, 'Not much to do yet. Soon you will be able to fix the URL, delete the feed, or force a retry.'),
|
||||
$.make('form', { className: 'NB-exception-form' }, [
|
||||
$.make('div', { className: 'NB-modal-submit' }, [
|
||||
$.make('input', { type: 'submit', disabled: 'true', className: 'NB-disabled', value: 'Fill out proposed changes...' }),
|
||||
|
|
|
@ -256,6 +256,8 @@ class Dispatcher:
|
|||
ffeed = FetchFeed(feed, self.options)
|
||||
ret_feed, fetched_feed = ffeed.fetch()
|
||||
|
||||
delta = datetime.datetime.now() - start_time
|
||||
|
||||
if fetched_feed and ret_feed == FEED_OK:
|
||||
pfeed = ProcessFeed(feed, fetched_feed, self.options)
|
||||
ret_feed, ret_entries = pfeed.process()
|
||||
|
@ -286,7 +288,8 @@ class Dispatcher:
|
|||
ret_feed = FEED_ERREXC
|
||||
feed.save_feed_history(500, "Error", tb)
|
||||
|
||||
delta = datetime.datetime.now() - start_time
|
||||
if not delta:
|
||||
delta = datetime.datetime.now() - start_time
|
||||
if delta.seconds > SLOWFEED_WARNING:
|
||||
comment = u' (SLOW FEED!)'
|
||||
else:
|
||||
|
|
Loading…
Add table
Reference in a new issue