Fix to scipy and the icon importer credited entirely to the work of @sbilly.

This commit is contained in:
Samuel Clay 2016-02-04 21:31:49 -08:00
parent 307083fb98
commit 6edbf67a50
4 changed files with 21 additions and 20 deletions

View file

@ -318,7 +318,8 @@ class IconImporter(object):
# Reshape array of values to merge color bands. [[R], [G], [B], [A]] => [R, G, B, A]
if len(shape) > 2:
ar = ar.reshape(scipy.product(shape[:2]), shape[2])
ar = ar.astype(numpy.float)
# Get NUM_CLUSTERS worth of centroids.
codes, _ = scipy.cluster.vq.kmeans(ar, NUM_CLUSTERS)
@ -347,7 +348,7 @@ class IconImporter(object):
# Find the most frequent color, based on the counts.
index_max = scipy.argmax(counts)
peak = codes[index_max]
peak = codes.astype(int)[index_max]
color = ''.join(chr(c) for c in peak).encode('hex')
return color[:6]

View file

@ -400,35 +400,34 @@ class Feed(models.Model):
# Normalize and check for feed_address, dupes, and feed_link
url = urlnorm.normalize(url)
feed = by_url(url)
found_feeds = feedfinder.find_feeds(url)
print found_feeds
found_feed_urls = []
# Create if it looks good
if feed and len(feed) > offset:
feed = feed[offset]
elif create:
create_okay = False
if feedfinder.isFeed(url):
found_feed_urls = feedfinder.find_feeds(url)
if len(found_feed_urls):
create_okay = True
elif fetch:
# Could still be a feed. Just check if there are entries
fp = feedparser.parse(url)
if len(fp.entries):
create_okay = True
# elif fetch:
# # Could still be a feed. Just check if there are entries
# fp = feedparser.parse(url)
# if len(fp.entries):
# create_okay = True
if create_okay:
feed = cls.objects.create(feed_address=url)
feed = feed.update()
# Still nothing? Maybe the URL has some clues.
if not feed and fetch:
feed_finder_url = feedfinder.feed(url)
if feed_finder_url and 'comments' not in feed_finder_url:
feed = by_url(feed_finder_url)
if not feed and create:
feed = cls.objects.create(feed_address=feed_finder_url)
feed = feed.update()
elif feed and len(feed) > offset:
feed = feed[offset]
if not feed and fetch and len(found_feed_urls):
feed_finder_url = found_feed_urls[0]
feed = by_url(feed_finder_url)
if not feed and create:
feed = cls.objects.create(feed_address=feed_finder_url)
feed = feed.update()
elif feed and len(feed) > offset:
feed = feed[offset]
# Not created and not within bounds, so toss results.
if isinstance(feed, QuerySet):

View file

@ -28,6 +28,8 @@ lxml==3.3.5
mongoengine==0.8.2
mysql-python==1.2.5
nltk==2.0.5
numpy==1.10.4
scipy==0.17.0
oauth2==1.5.211
psutil==2.1.0
pyes==0.99.5

1
fabfile.py vendored
View file

@ -453,7 +453,6 @@ def setup_virtualenv():
with cd(env.NEWSBLUR_PATH):
run('virtualenv venv')
run('echo "import sys; sys.setdefaultencoding(\'utf-8\')" | sudo tee venv/lib/python2.7/sitecustomize.py')
@_contextmanager
def virtualenv():