예제 #1
0
    def handle(self, url, **optz):
        # Check if subscriber sites and filters can be found
        if optz.get("subscribe"):
            try:
                subscribe = list(models.Site.get_by_string(name) for name in optz["subscribe"])
            except (ObjectDoesNotExist, MultipleObjectsReturned) as err:
                raise CommandError(err.message)
        else:
            subscribe = list()
        if optz.get("filter"):
            try:
                filters = list(models.Filter.objects.get(id=fid) for fid in optz["filter"])
            except ObjectDoesNotExist as err:
                raise CommandError(err.message)
        else:
            filters = list()

        # Fill in missing feed name fields
        if not optz.get("name"):
            fpf = feedparser.parse(url, agent=fjupdate.USER_AGENT)
            optz["name"] = fpf.feed.get("title", "")[:200]
            if not optz["name"]:
                raise CommandError("Failed to acquire name from the feed ({0})".format(url))
        if not optz.get("shortname"):
            optz["shortname"] = optz["name"][:50]

            # Add Feed / Subscriber objects
        with transaction.commit_on_success():
            feed = models.Feed(feed_url=url, name=optz["name"], shortname=optz["shortname"])
            if optz.get("field_data"):
                try:
                    import yaml as s
                except ImportError:
                    import json as s
                import io

                for k, v in s.load(io.BytesIO(optz["field_data"])).iteritems():
                    setattr(feed, k, v)
            feed.save()
            for f in filters:
                feed.filters.add(f)
            for site in subscribe:
                models.Subscriber.objects.create(feed=feed, site=site)

                # Perform the initial fetch, if requested
        if optz.get("initial_fetch"):
            fetch_optz, fetch_argz = OptionParser(option_list=fjupdate.make_cli_option_list()).parse_args(list())
            fetch_optz.feed = [feed.id]
            fetch_optz.hidden = optz.get("fetch_hidden", False)
            fjupdate.main(fetch_optz)
예제 #2
0
	def handle(self, **opts):
		opts = type(b'Opts', (object,), dict((k.replace('-', '_'), v) for k,v in opts.viewitems()))

		# Check if subscriber sites and filters can be found
		if opts.subscribe:
			try:
				subscribe = list(
					models.Site.objects.get_by_string(name) for name in opts.subscribe )
			except (ObjectDoesNotExist, MultipleObjectsReturned) as err:
				raise CommandError(unicode(err))
		else: subscribe = list()
		if opts.filter:
			try: filters = list(models.Filter.objects.get(id=fid) for fid in opts.filter)
			except ObjectDoesNotExist as err:
				raise CommandError(unicode(err))
		else: filters = list()

		# Fill in missing feed name fields
		if not opts.name:
			fpf = feedparser.parse(opts.feed_url, agent=fjupdate.USER_AGENT)
			opts.name = fpf.feed.get('title', '')[:200]
			if not opts.name:
				raise CommandError('Failed to acquire name from the feed ({0})'.format(opts.feed_url))
		if not opts.shortname: opts.shortname = opts.name[:50]

		# Add Feed / Subscriber objects
		with transaction.atomic():
			feed = models.Feed( feed_url=opts.feed_url,
				name=opts.name, shortname=opts.shortname )
			if opts.field_data:
				try: import yaml as s
				except ImportError: import json as s
				import io
				for k, v in s.load(io.BytesIO(opts.field_data)).iteritems(): setattr(feed, k, v)
			feed.save()
			for f in filters: feed.filters.add(f)
			for site in subscribe:
				models.Subscriber.objects.create(feed=feed, site=site)

		# Perform the initial fetch, if requested
		if opts.initial_fetch:
			fetch_opts = fjupdate.argparse_get_parser().parse_args(list())
			for k, v in [('feed', [feed.id]), ('hidden', opts.fetch_hidden)]:
				assert hasattr(fetch_opts, k), fetch_opts
				setattr(fetch_opts, k, v)
			fetch_opts.verbosity = opts.verbosity
			fjupdate.main(fetch_opts, log_stream=self.stdout)
예제 #3
0
	def handle_noargs(self, **optz):
		fjupdate.main(optz)
예제 #4
0
    def handle(self, **opts):
        opts = type(
            b'Opts', (object, ),
            dict((k.replace('-', '_'), v) for k, v in opts.viewitems()))

        # Check if subscriber sites and filters can be found
        if opts.subscribe:
            try:
                subscribe = list(
                    models.Site.objects.get_by_string(name)
                    for name in opts.subscribe)
            except (ObjectDoesNotExist, MultipleObjectsReturned) as err:
                raise CommandError(unicode(err))
        else:
            subscribe = list()
        if opts.filter:
            try:
                filters = list(
                    models.Filter.objects.get(id=fid) for fid in opts.filter)
            except ObjectDoesNotExist as err:
                raise CommandError(unicode(err))
        else:
            filters = list()

        # Fill in missing feed name fields
        if not opts.name:
            fpf = feedparser.parse(opts.feed_url, agent=fjupdate.USER_AGENT)
            opts.name = fpf.feed.get('title', '')[:200]
            if not opts.name:
                raise CommandError(
                    'Failed to acquire name from the feed ({0})'.format(
                        opts.feed_url))
        if not opts.shortname: opts.shortname = opts.name[:50]

        # Add Feed / Subscriber objects
        with transaction.atomic():
            feed = models.Feed(feed_url=opts.feed_url,
                               name=opts.name,
                               shortname=opts.shortname)
            if opts.field_data:
                try:
                    import yaml as s
                except ImportError:
                    import json as s
                import io
                for k, v in s.load(io.BytesIO(opts.field_data)).iteritems():
                    setattr(feed, k, v)
            feed.save()
            for f in filters:
                feed.filters.add(f)
            for site in subscribe:
                models.Subscriber.objects.create(feed=feed, site=site)

        # Perform the initial fetch, if requested
        if opts.initial_fetch:
            fetch_opts = fjupdate.argparse_get_parser().parse_args(list())
            for k, v in [('feed', [feed.id]), ('hidden', opts.fetch_hidden)]:
                assert hasattr(fetch_opts, k), fetch_opts
                setattr(fetch_opts, k, v)
            fetch_opts.verbosity = opts.verbosity
            fjupdate.main(fetch_opts, log_stream=self.stdout)
예제 #5
0
	def handle(self, **opts):
		return fjupdate.main(opts, log_stream=self.stdout)