Exemplo n.º 1
0
 def get_and_update_rssfeed_results(self, rssfeed_key):
     site_cookies = http.get_matching_cookies_dict(
         self.cookies, self.rssfeeds[rssfeed_key]["site"])
     user_agent = get_user_agent(rssfeed_data=self.rssfeeds[rssfeed_key])
     rssfeeds_parsed = self.rssfeedhandler.get_rssfeed_parsed(
         self.rssfeeds[rssfeed_key],
         site_cookies_dict=site_cookies,
         user_agent=user_agent)
     return rssfeeds_parsed
 def get_and_update_rssfeed_results(self, rssfeed_key):
     """
     Returns:
         Deferred:
     """
     site_cookies_dict = http.get_matching_cookies_dict(self.cookies, self.rssfeeds[rssfeed_key]["site"])
     user_agent = get_user_agent(rssfeed_data=self.rssfeeds[rssfeed_key])
     return self.get_rssfeed_parsed(self.rssfeeds[rssfeed_key],
                                    site_cookies_dict=site_cookies_dict,
                                    user_agent=user_agent)
Exemplo n.º 3
0
 def add_torrent(self, torrent_info):
     site_cookies_dict = get_matching_cookies_dict(
         self.yarss_config.get_config()["cookies"], torrent_info["link"])
     torrent_info["site_cookies_dict"] = site_cookies_dict
     if "rssfeed_key" in torrent_info:
         rssfeed_data = self.yarss_config.get_config()["rssfeeds"][
             torrent_info["rssfeed_key"]]
         torrent_info["user_agent"] = get_user_agent(
             rssfeed_data=rssfeed_data)
     torrent_download = self.torrent_handler.add_torrent(torrent_info)
     return torrent_download.to_dict()
Exemplo n.º 4
0
    def test_add_torrent_default_user_agent(self):
        torrent_name = "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent"
        torrent_url = yarss2.util.common.get_resource(torrent_name,
                                                      path="tests/data/")
        torrent_info = {"link": torrent_url, "rssfeed_key": "0"}
        config = common.get_test_config_dict()
        default_user_agent = get_user_agent()
        self.config.set_config(config)
        self.core.yarss_config = self.config

        download_dict = self.core.add_torrent(torrent_info)
        self.assertEquals(download_dict["headers"]["User-Agent"],
                          default_user_agent)
    def fetch_feed_torrents(self, config, rssfeed_key, subscription_key=None):
        """Called to fetch torrents for a feed
        If rssfeed_key is not None, all subscriptions linked to that RSS Feed
        will be run.
        If rssfeed_key is None, only the subscription with key == subscription_key
        will be run
        """
        fetch_data = {}
        fetch_data["matching_torrents"] = []
        fetch_data["rssfeed_items"] = None

        if rssfeed_key is None:
            if subscription_key is None:
                self.log.warning("rssfeed_key and subscription_key cannot both be None")
                return fetch_data
            rssfeed_key = config["subscriptions"][subscription_key]["rssfeed_key"]
        else:
            # RSS Feed is not enabled
            if config["rssfeeds"][rssfeed_key]["active"] is False:
                return fetch_data

        rssfeed_data = config["rssfeeds"][rssfeed_key]
        fetch_data["site_cookies_dict"] = http.get_matching_cookies_dict(config["cookies"], rssfeed_data["site"])
        fetch_data["user_agent"] = get_user_agent(rssfeed_data=rssfeed_data)

        self.log.info("Update handler executed on RSS Feed '%s (%s)' (Update interval %d min)" %
                      (rssfeed_data["name"], rssfeed_data["site"], rssfeed_data["update_interval"]))

        for key in config["subscriptions"].keys():
            # subscription_key is given, only that subscription will be run
            if subscription_key is not None and subscription_key != key:
                continue
            subscription_data = config["subscriptions"][key]
            if subscription_data["rssfeed_key"] == rssfeed_key and subscription_data["active"] is True:
                self.fetch_feed(subscription_data, rssfeed_data, fetch_data)

        if subscription_key is None:
            # Update last_update value of the rssfeed only when rssfeed is run by the timer,
            # not when a subscription is run manually by the user.
            # Don't need microseconds. Remove because it requires changes to the GUI to not display them
            dt = common.get_current_date().replace(microsecond=0)
            rssfeed_data["last_update"] = dt.isoformat()
        return fetch_data