Commits

Gregory Petukhov committed 5eb6d94

Fix tags parsing

Comments (0)

Files changed (1)

feedzilla/management/commands/feedzilla_update.py

 from feedzilla.models import Feed, Post
 from feedzilla import settings
 
-REX_TAGS_TAIL = re.compile(',[^,]*')
-
 class Command(BaseCommand):
     help = u'Update feeds'
 
             proc = getattr(module, cls)()
             processors.append(proc)
 
-        for feed in Feed.objects.filter(active=True):
+        qs = Feed.objects.filter(active=True)
+        if len(args):
+            qs = qs.filter(feed_url__icontains=args[0])
+
+        for feed in qs:
             logging.debug('parsing %s' % feed.feed_url)
 
             resp = parse_feed(feed.feed_url, etag=feed.etag,
             else:
                 new_posts = 0
                 for entry in resp['entries']:
+
                     try:
                         Post.objects.get(guid=entry['guid'])
                     except Post.DoesNotExist:
+
                         tags = entry['tags']
                         if settings.FEEDZILLA_TAGS_LOWERCASE:
                             tags = set(x.lower() for x in tags)
-
-                        # Strip tags to 255 chars string
-                        # because of TagField limitation
-                        tags = ', '.join(tags)
-                        tags = REX_TAGS_TAIL.sub('', tags)[:255]
+                        # Sum of tags lengths should not be
+                        # more than 255 chars
+                        newtags = []
+                        size = 0
+                        for tag in tags:
+                            size += len(tag)
+                            if size <= 255:
+                                newtags.append(tag)
+                        tags = newtags
 
                         post = Post(
                             feed=feed,