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)
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()
def test_get_matching_cookies_dict(self): cookies = {} cookies["0"] = yarss2.yarss_config.get_fresh_cookie_config() cookies["0"]["site"] = "basename.com" cookies["0"]["value"]["key1"] = "value1" cookies["0"]["value"]["key2"] = "value2" cookies["1"] = yarss2.yarss_config.get_fresh_cookie_config() cookies["1"]["site"] = "non-matching_url.com" cookies["1"]["value"]["key3"] = "value3" matching_cookies = http.get_matching_cookies_dict(cookies, "http://basename.com/blabla") self.assertTrue(matching_cookies.has_key("key1")) self.assertEquals(matching_cookies["key1"], cookies["0"]["value"]["key1"]) self.assertTrue(matching_cookies.has_key("key2")) self.assertEquals(matching_cookies["key2"], cookies["0"]["value"]["key2"]) self.assertFalse(matching_cookies.has_key("key3"))
def test_get_matching_cookies_dict(self): cookies = {} cookies["0"] = yarss2.yarss_config.get_fresh_cookie_config() cookies["0"]["site"] = "basename.com" cookies["0"]["value"]["key1"] = "value1" cookies["0"]["value"]["key2"] = "value2" cookies["1"] = yarss2.yarss_config.get_fresh_cookie_config() cookies["1"]["site"] = "non-matching_url.com" cookies["1"]["value"]["key3"] = "value3" matching_cookies = http.get_matching_cookies_dict(cookies, "http://basename.com/blabla") self.assertTrue("key1" in matching_cookies) self.assertEquals(matching_cookies["key1"], cookies["0"]["value"]["key1"]) self.assertTrue("key2" in matching_cookies) self.assertEquals(matching_cookies["key2"], cookies["0"]["value"]["key2"]) self.assertFalse("key3" in matching_cookies)
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
def populate_data_fields(self): if self.rssfeed: self.glade.get_widget("txt_name").set_text(self.rssfeed["name"]) self.glade.get_widget("txt_url").set_text(self.rssfeed["url"]) self.glade.get_widget("spinbutton_updatetime").set_value( self.rssfeed["update_interval"]) self.glade.get_widget("checkbutton_on_startup").set_active( self.rssfeed["update_on_startup"]) self.glade.get_widget("checkbox_obey_ttl").set_active( self.rssfeed["obey_ttl"]) self.glade.get_widget("checkbox_prefer_magnet").set_active( self.rssfeed["prefer_magnet"]) cookies = http.get_matching_cookies_dict(self.gtkUI.cookies, self.rssfeed["site"]) cookies_hdr = http.get_cookie_header(cookies) self.glade.get_widget("txt_cookies").set_text( cookies_hdr.get("Cookie", "")) # Disable the fields field if "key" in self.rssfeed and self.rssfeed[ "key"] == yarss2.yarss_config.DUMMY_RSSFEED_KEY: self.glade.get_widget("txt_name").set_property( "editable", False) self.glade.get_widget("txt_name").unset_flags(gtk.CAN_FOCUS) self.glade.get_widget("txt_url").set_property( "editable", False) self.glade.get_widget("txt_url").unset_flags(gtk.CAN_FOCUS) self.glade.get_widget("spinbutton_updatetime").set_sensitive( False) self.glade.get_widget("checkbutton_on_startup").set_active( False) self.glade.get_widget("checkbutton_on_startup").set_sensitive( False) self.glade.get_widget("checkbox_obey_ttl").set_active(False) self.glade.get_widget("checkbox_obey_ttl").set_sensitive(False) self.glade.get_widget("checkbox_prefer_magnet").set_active( False) self.glade.get_widget("checkbox_prefer_magnet").set_sensitive( False) self.glade.get_widget("button_save").set_sensitive(False)
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.warn("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"]) 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"] == 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
def get_and_update_rssfeed_results(self, rssfeed_key): site_cookies = http.get_matching_cookies_dict(self.cookies, self.rssfeeds[rssfeed_key]["site"]) rssfeeds_parsed = self.rssfeedhandler.get_rssfeed_parsed(self.rssfeeds[rssfeed_key], site_cookies_dict=site_cookies) return rssfeeds_parsed
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 torrent_download = self.torrent_handler.add_torrent(torrent_info) return torrent_download.to_dict()