Esempio n. 1
0
    def subscribe(self, url):
        """Create and return a subscription to the given url."""
        root = self.data_dir
        feeds_dir = os.path.join(root, 'feeds')
        mkdirs(feeds_dir)
        feeds_index = os.path.join(feeds_dir, 'index.json')
        feeds = json_load(feeds_index, [])

        # FIXME Check for duplicates

        resp = feedparser.parse(url)
        feeds.append(resp.feed)
        json_dump(feeds_index, feeds)
        return 1
Esempio n. 2
0
    def initialize(self):
        """Initialize the data_dir.

        Note that the method does not take the directory as an argument, but
        operates instead on the Manager.data_dir.
        """
        # Things need creating: .feedcollectr.json index.json feeds/index.json
        collection_file = os.path.join(self.data_dir, '.feedcollectr.json')
        index = os.path.join(self.data_dir, 'index.json')
        feeds_dir = os.path.join(self.data_dir, 'feeds')
        feeds_index = os.path.join(feeds_dir, 'index.json')

        if not os.path.isfile(collection_file):
            json_dump(collection_file, {})

        if not os.path.isfile(index):
            json_dump(index, {})

        mkdirs(feeds_dir)
        if not os.path.isfile(feeds_index):
            json_dump(feeds_index, {'feeds': []})

        self.is_initialized = True
        return self.is_initialized