Пример #1
0
    # Open the cache file directly to get the URL it represents
    try:
        db = dbhash.open(cache_file)
        url = db["url"]
        db.close()
    except dbhash.bsddb._db.DBError, e:
        print >> sys.stderr, cache_file + ":", e.args[1]
        sys.exit(1)
    except KeyError:
        print >> sys.stderr, cache_file + ": Probably not a cache file"
        sys.exit(1)

    # Now do it the right way :-)
    my_planet = planet.Planet(ConfigParser.ConfigParser())
    my_planet.cache_directory = os.path.dirname(cache_file)
    channel = planet.Channel(my_planet, url)

    for item_id in ids:
        if not channel.has_item(item_id):
            print >> sys.stderr, item_id + ": Not in channel"
            sys.exit(1)

    # Do the user's bidding
    if command == "channel":
        print_keys(channel, "Channel Keys")

    elif command == "item":
        for item_id in ids:
            item = channel.get_item(item_id)
            print_keys(item, "Item Keys for %s" % item_id)
 def setUp(self):
     self.url = 'URL'
     self.changed_url = 'Changed URL'
     self.channel = planet.Channel(FakePlanet(), self.url)
Пример #3
0
    log.info("Loading cached data")
    my_planet = planet.Planet()
    if config.has_option("Planet", "cache_directory"):
        my_planet.cache_directory = config.get("Planet", "cache_directory")
    if config.has_option("Planet", "new_feed_items"):
        my_planet.new_feed_items = int(config.get("Planet", "new_feed_items"))
    my_planet.user_agent = "%s +%s %s" % (planet_name, planet_link,
                                          my_planet.user_agent)

    # The other configuration blocks are channels to subscribe to
    for feed_url in config.sections():
        if feed_url == "Planet" or feed_url in template_files:
            continue

        # Create a channel, configure it and subscribe it
        channel = planet.Channel(my_planet, feed_url)
        for option in config.options(feed_url):
            value = config.get(feed_url, option)
            channel.set_as_string(option, value, cached=0)
        my_planet.subscribe(channel)

        # Update it
        try:
            if not offline:
                channel.update()
        except KeyboardInterrupt:
            raise
        except:
            log.exception("Update of <%s> failed", feed_url)

    # Go-go-gadget-template