def readFromAddrBar(self): if len(str(self.addressInput.text())) > 1: if self.selected != False: self.selected = False; source = Source(); source = source.fromURL(str(self.addressInput.text())); if(source != False): try: feed = Feed(source); self.rssContentView.setHtml(unicode(FeedBox.FeedBox.showFeeds(feed.feedTitle, feed.toHTML()))); self.updateTitle(str(feed.feedTitle).replace("'", "'")); self.rmFeedButton.setEnabled(False); #self.reloadOneFeedButton.setEnabled(False); self.saveFromAddrButton.setEnabled(True); self.addFeedPopup.name.setText(feed.feedTitle); except: self.rssContentView.setHtml(unicode(FeedBox.FeedBox.parseError())); self.updateTitle("Unable to load RSS feed"); else: self.rssContentView.setHtml(unicode(FeedBox.FeedBox.downloadError())); self.updateTitle("Unable to load RSS feed"); self.feedListWidget.clearSelection();
def fromFile(self): rssFile = QFileDialog.getOpenFileName(self, 'rss', '*.rss'); source = Source(); self.saveFromAddrButton.setEnabled(False); self.addressInput.clear(); self.feedListWidget.clearSelection(); try: feed = Feed(source.fromFile(str(rssFile)), "file"); self.updateTitle(str(feed.feedTitle).replace("'", "'")); self.rssContentView.setHtml(unicode(FeedBox.FeedBox.showFeeds(feed.feedTitle, feed.toHTML()))); except: self.rssContentView.setHtml(unicode(FeedBox.FeedBox.parseError())); self.updateTitle("Unable to open RSS feed");
def readSettings(self, settings): """ Read Feeds from a Settings object. Feeds are read from a 'feeds' group under the current group, and each subgroup of the 'feeds' group is taken as a Feed name. """ with settings.groupGuard(self.__SETTINGS_FEEDS): groupNames = settings.getChildGroups() for groupName in groupNames: feed = Feed(groupName) with settings.groupGuard(groupName): feed.readSettings(settings) self.addFeed(feed) log.debug('Loaded feeds: %s' % [f.getName() for f in self.__feeds])
def __getFeeds(self, file): """ `Author`: Eliakah kakou This method generates a Feed instance from the file given `file`: full file path `return`: Feed generated from file """ title = self.__getFileName(file) input_file = open(file) try: content = input_file.read() finally: input_file.close() stamp = time.ctime(self.__creation_date(file)) f = { 'id': file, 'published': stamp, 'title': title, 'link': file, 'summary': content } f = Feed(f) return f
def dict_to_feed(self, feed_dict): feed = Feed(feed_id=feed_dict["feed_id"], title=feed_dict["title"], description=feed_dict["description"], link=feed_dict["link"], date_updated=feed_dict["date_updated"], feed_copyright=feed_dict["feed_copyright"]) return feed
def convert(self): for feed in self.feeds_index_dict: converted_feed = Feed( feed_id=feed["feed_id"], title=feed["title"], description=feed["description"], link=feed["link"], date_updated=feed["date_updated"], feed_copyright=feed["feed_copyright"] ) self.items.append(converted_feed)
def loading_feeds(self): feed = Feed(self.engine) print("Check for new feeds: ", end="", flush=True) feed.load_new_feeds_from_file("sites") print("Done") print("Loading feeds: ") feed.load_new_articles() print("Loading articles: ") # Article(self.engine).check_articles_limited() feed.check_articles_limited()
def getSitesAndFeeds(): doc = xml.dom.minidom.parse(_pwd + '/sites.xml') # Iterate through the list of sites in the XML feed. for node_site in doc.getElementsByTagName('site'): # Instantiate a Site object and assign its name. site = Site() site.name = node_site.getAttribute('name') site.image = node_site.getAttribute('image') # Retrieve the name of each feed to build the top-level menu. for node_feed in node_site.getElementsByTagName('feed'): feed = Feed() feed.name = node_feed.getAttribute('name') feed.type = node_feed.getAttribute('type') for node_url in node_feed.getElementsByTagName('url'): url_quality = node_url.getAttribute('quality') feed.urls[url_quality] = SimplerXML.getText(node_url, 'url') site.feeds.append(feed) array_sites.append(site)
def main(): # set a name to a feed yasmin = Feed.Feed("yasmin") esther = Feed.Feed("esther") vera = Feed.Feed("vera") # Feed erstellen yasmin.generateOwnFeed() esther.generateOwnFeed() vera.generateOwnFeed() # set person yasminPerson = Person.Person(yasmin.id, yasmin.name, yasmin) yasminPerson.follow(esther.id, esther.name) yasminPerson.follow(vera.id, vera.name) yasminPerson.printFollowList() yasminPerson.unfollow(vera.id) yasminPerson.printFollowList() veraPerson = Person.Person(vera.id, vera.name, vera) veraPerson.follow(esther.id, esther.name) veraPerson.follow(yasmin.id, yasmin.name) veraPerson.printFollowList()
def getBestFeed(feedList): maxScore = 0.0 maxFeed = Feed("", -1, -2, -3) tmpDict = {} for feed in feedList: if (tmpDict.get(feed.getScore(), 0) == 1): continue else: tmpDict[feed.getScore()] = 1 sumScore = 0.0 for tmp in feedList: tmpScore = feed.calculateDelta(tmp) sumScore = sumScore + tmpScore if sumScore > maxScore: maxScore = sumScore maxFeed = feed return maxFeed
def __init__(self): try: logger.info('Initializing directories...') dirs = self.init_dirs() os.chdir(dirs.user_cache_dir) logger.debug('* Cache: ' + dirs.user_cache_dir) logger.info('* Data: ' + dirs.user_data_dir) plugin_dirs = [] plugin_dirs.append(os.path.join(self.program_dir, 'plugins')) plugin_dirs.append(os.path.join(dirs.user_data_dir, 'plugins')) for d in plugin_dirs: logger.info('* Plugins: ' + d) print('') logger.info('Initializing configuration...') conf_file_path = os.path.join(dirs.user_data_dir, 'fbnotify.conf') logger.info('* File: ' + conf_file_path) self.conf = Config(conf_file_path) print('') logger.info('Initializing feed...') self.feed = Feed(self.conf.feed.url) print('') logger.info('Initializing plugins...') logger.debug('* Blacklisted: ' + str(self.conf.program.plugin_blacklist)) self.plugin_man = PluginManager(plugin_dirs, self.conf.program.plugin_blacklist) self.plugin_man.load_by_role('notify') self.plugin_man.load_by_role('list') self.plugin_man.load_by_role('status') self.plugin_context = self.plugin_man.messaging.register_plugin(self, 'fbnotify') print('') logger.debug('Work dir: ' + os.getcwd()) print except Exception as e: logger.error(traceback.format_exc()) self.bad_stop()
def __getFeeds(self, url): """ `Author`: Eliakah kakou This method generates a Feed instance from the url given `file`: full file path `return`: Feed generated from file """ flag = validators.url(url) if flag: feeds = feedparser.parse(url) else: sys.exit("Invalid Url: Please try again!") list = feeds['entries'] for i in range(len(list)): list[i] = Feed(list[i]) feeds = list return feeds
import MySQLdb import MySQLdb.cursors import json from Feed import Feed db = MySQLdb.connect(host="localhost", user="******", passwd="", db="emoncms", cursorclass=MySQLdb.cursors.DictCursor) cursor = db.cursor() feed = Feed(cursor) print json.dumps(feed.list(3))
def get_feed(self): return Feed(self.data_miner_with_cache(['feed', self.student_id]))
# 读入数据 while 1: line = file.readline() if not line: break arr = line.split("\t") if (len(arr) < 6): continue uid = arr[0] repost_count = int(arr[3]) comment_count = int(arr[4]) like_count = int(arr[5]) feed = Feed(uid, int(repost_count), int(comment_count), int(like_count)) feedList = feed_dict.get(uid, []) if (feedList == []): feedList.append(feed) else: feedList.append(feed) feed_dict[uid] = feedList pass print("read over") count = 0 for uid in feed_dict.keys(): feedList = feed_dict.get(uid, "0,0,0") result_dict[uid] = getBestFeed(feedList).getScore() count = count + 1
def GET(self): web.header('Content-Type', 'application/json') feed = Feed(mysql) return json.dumps(feed.list(3))
feedGroup.readSettings(settings) doUpdate = not any([options.add, options.delete, options.list]) if not (doUpdate or options.list) and args: parser.error(('positional arguments legal only when updating' + ' or listing (with --list): %s') % args) if options.add: if not options.rssurl: parser.error('--add requires --rss-url') if not options.openurl: log.warning(("new feed '%s' will open the RSS URL " + "(use --open-url to specify a different URL to open") % options.rssurl) feed = Feed(options.add) feed.setRSSURL(options.rssurl) if options.openurl: feed.setOpenURL(options.openurl) feedGroup.addFeed(feed) if options.delete: feed = feedGroup.getFeed(options.delete) if not feed: parser.error("not found: '%s'" % options.delete) feedGroup.removeFeed(feed) settings.clear() # otherwise the deleted feed persists in settings if options.list: kwargs = {} if args: kwargs['feedNames'] = args for feed in feedGroup.getFeeds(**kwargs):
def main(): feed = Feed("http://www.engadget.com/rss.xml") feed.refresh() feed.print_all() print 0
import MySQLdb import MySQLdb.cursors import json from Feed import Feed db = MySQLdb.connect(host="localhost",user="******",passwd="",db="emoncms",cursorclass=MySQLdb.cursors.DictCursor) cursor = db.cursor() feed = Feed(cursor) print json.dumps(feed.list(3))
class Notifier: ''' main class ''' program_dir = os.path.dirname(os.path.realpath(__file__)) plugin_man = None plugin_context = None conf = None feed = None do_refresh = False def __init__(self): try: logger.info('Initializing directories...') dirs = self.init_dirs() os.chdir(dirs.user_cache_dir) logger.debug('* Cache: ' + dirs.user_cache_dir) logger.info('* Data: ' + dirs.user_data_dir) plugin_dirs = [] plugin_dirs.append(os.path.join(self.program_dir, 'plugins')) plugin_dirs.append(os.path.join(dirs.user_data_dir, 'plugins')) for d in plugin_dirs: logger.info('* Plugins: ' + d) print('') logger.info('Initializing configuration...') conf_file_path = os.path.join(dirs.user_data_dir, 'fbnotify.conf') logger.info('* File: ' + conf_file_path) self.conf = Config(conf_file_path) print('') logger.info('Initializing feed...') self.feed = Feed(self.conf.feed.url) print('') logger.info('Initializing plugins...') logger.debug('* Blacklisted: ' + str(self.conf.program.plugin_blacklist)) self.plugin_man = PluginManager(plugin_dirs, self.conf.program.plugin_blacklist) self.plugin_man.load_by_role('notify') self.plugin_man.load_by_role('list') self.plugin_man.load_by_role('status') self.plugin_context = self.plugin_man.messaging.register_plugin(self, 'fbnotify') print('') logger.debug('Work dir: ' + os.getcwd()) print except Exception as e: logger.error(traceback.format_exc()) self.bad_stop() def start(self): ''' main loop ''' try: while True: logger.info('Updating...' + ' [' + email.utils.formatdate(time.mktime(time.localtime()), True) + ']') # Update the feed self.plugin_man.messaging.send( 'status', status='updating', description='Updating' ) new_items = None try: new_items = self.feed.get_new_items() except IOError: # Error self.plugin_man.messaging.send( 'status', status='error', description='Unable to load feed URL' ) self.adjust_interval(0) # If new items are loaded if new_items is not None: self.plugin_man.messaging.send( 'status', status='idle', description='Waiting' ) self.notify_items(new_items) self.adjust_interval(len(new_items)) # Wait count = 0 while count < self.conf.feed.check_interval: time.sleep(0.25) count += 0.25 self.plugin_context.receive() if self.do_refresh: break self.do_refresh = False print('') except KeyboardInterrupt: print('') logger.info('Stopped') self.stop() except Exception as e: logger.error(traceback.format_exc()) self.bad_stop() self.bad_stop(); def plugin_receive(self, channel, message): # Receiving a message from the 'fbnotify' channel if 'quit' in message: logger.debug('Quit requested') self.stop() elif 'refresh' in message: logger.debug('Refresh requested') self.do_refresh = True def bad_stop(self): ''' bad things happened, so bad that the application must stop ''' logger.error('Bad Exit!') self.stop() def stop(self): ''' stop the application ''' if self.plugin_man: logger.info('Unloading all plugins...') self.plugin_man.unload_all() logger.info('Exit') quit() def notify_items(self, items): ''' shows notifications about items ''' n = len(items) n_new_notifications = '{0} new notification{1}'.format(n, '' if n == 1 else 's') logger.info(n_new_notifications) if n == 0: return # Update item list self.plugin_man.messaging.send( 'list', items = items ) if n > 1: # Many notifications if self.conf.notification.itemize >= n: # Show individual notifications interval = self.conf.notification.item_interval for item in sorted(items, key=lambda x: x.dt): if item.image_path == None: self.notify(item.text, self.format_time(item.dt), timeout=interval, link=item.link) else: self.notify(item.text, self.format_time(item.dt), icon='file://' + item.image_path, timeout=interval, link=item.link) time.sleep(interval + 1) else: # Declare multiple notifications dt = items[n-1].dt # Earliest notification date self.notify(n_new_notifications, self.format_time(dt), link='www.facebook.com/notifications') else: # Single notification item = items[0] if self.conf.notification.show_content: if item.image_path == None: self.notify(item.text, self.format_time(item.dt), link=item.link) else: self.notify(item.text, self.format_time(item.dt), icon='file://' + item.image_path, link=item.link) else: self.notify(n_new_notifications, self.format_time(item.dt)) def notify(self, title, body, icon=icons.xdg_icon, timeout=10, link=None): ''' requests to show a notification ''' logger.debug('Notify: ' + title + ' ' + body) # This will send a message to any plugin # listening to the 'notify' channel self.plugin_man.messaging.send( 'notify', title = title, body = body, icon = icon, timeout = timeout, link = link ) def adjust_interval(self, new): ''' automatically adjust the feed check interval ''' if self.conf.feed.dynamic_interval: ci = self.conf.feed.check_interval if new: min_interval = 15 # 15 seconds if ci > min_interval: ci = ci * 1/5 if ci < min_interval: ci = min_interval logger.info('Decreased check interval to {0}s'.format(ci)) else: max_interval = 60 * 20 # 20 minutes if ci < max_interval: ci = ci * 8/7 if ci > max_interval: ci = max_interval logger.info('Increased check interval to {0}s'.format(ci)) self.conf.feed.check_interval = ci def init_dirs(self): ''' creates, if not existing, application directories ''' dirs = appdirs.AppDirs('fbnotify', 'Kalabasa') conf_dir = dirs.user_data_dir cache_dir = dirs.user_cache_dir if not os.path.isdir(conf_dir): logger.info('Created configuration directory ' + conf_dir) os.makedirs(conf_dir) if not os.path.isdir(cache_dir): logger.info('Created cache directory ' + cache_dir) os.makedirs(cache_dir) return dirs def format_time(self, then): ''' Formats relative time to the specified time ''' now = datetime.now() if then >= now: text = 'Just now' else: delta = now - then if delta.days >= 1: text = '{0} day{1} ago'.format(delta.days, '' if delta.days == 1 else 's') elif delta.seconds >= 3600: hours = delta.seconds / 3600 text = '{0} hour{1} ago'.format(hours, '' if hours == 1 else 's') elif delta.seconds >= 60: minutes = delta.seconds / 60 text = '{0} minute{1} ago'.format(minutes, '' if minutes == 1 else 's') elif delta.seconds >= 30: text = '{0} second{1} ago'.format(delta.seconds, '' if delta.seconds == 1 else 's') else: text = 'Just now' return text
from Feed import Feed if __name__ == "__main__": print("hello") feed1 = Feed("1", int("3"), int("4"), int("5")) feed2 = Feed("2", int("3"), int("6"), int("7")) a = [] print(a == []) a.append(feed1) print(a) feed1.printFeed() print(feed1.calculateDelta(feed2)) print(feed1.getScore())
def getFeed(self,feedId = config.ALLDATA_FEEDID): from Feed import Feed return Feed({"feedId": feedId, "filter": {"byCategories": self.name}})