当前位置: 首页>>代码示例>>Python>>正文


Python Source.mark_searched方法代码示例

本文整理汇总了Python中source.Source.mark_searched方法的典型用法代码示例。如果您正苦于以下问题:Python Source.mark_searched方法的具体用法?Python Source.mark_searched怎么用?Python Source.mark_searched使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在source.Source的用法示例。


在下文中一共展示了Source.mark_searched方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from source import Source [as 别名]
# 或者: from source.Source import mark_searched [as 别名]
class Transverse:
    def __init__(self, events):
        config = Conf()
        self.reddit = praw.Reddit(user_agent='Switcharoo Cartographer v.0.2.1')
        self.reddit.login(config.r_username, config.r_password, disable_warning=True)
        self.events = events
        self.queue = None
        self.data = Access(self.events)
        self.source = Source(self)
        self._port = config.com_port
        self._share_port = config.share_port
        self._auth = config.auth
        self._should_stop = False
        self._threshold = 10

    def init_queue(self):
        if self.queue is None:
            self.queue = EntryQueue(self)

    def build_graph(self, current_entry):
        entry_point = True
        stop = False
        found = False
        found_list = []
        while current_entry is not None and not stop:
            current_entry.set_next()
            if current_entry.next_entry is None and entry_point:
                self.source.mark_searched(current_entry)
                return found, found_list
            entry_point = False
            # Check if item is already in graph
            node, stop = self.data.is_new_node(current_entry)
            # New node
            if not stop:
                found = True
                found_list.append(node)
            parents = self.data.get_parents(current_entry)
            for parent in parents:
                created = self.data.add_link(parent, node)
                if created:
                    found = True
            self.source.mark_searched(current_entry)
            current_entry = current_entry.next_entry
        return found, found_list

    def analyze_found(self, list):
        if len(list) > 0:
            manager = BaseManager(address=('', self._share_port), authkey=self._auth)
            manager.register('get_meta_data')
            manager.connect()
            distances, max_dist = manager.get_meta_data()
            for n in list:
                try:
                    if max_dist - distances[n._id] > self._threshold:
                        # Do something here
                        print "*** Node " + str(n._id) + " hit the threshold"
                except KeyError:
                    # Do query here to see if node exists. If it does than node
                    # does not link to origin
                    print "*** Node " + str(n._id) + " may not link to origin"

    def loop(self, limit, sleep=10):
        while 1:
            current_entry = self.source.add_to_queue(limit, sleep)
            found, found_list = self.build_graph(current_entry)
            if found:
                self.events.on_clearing_cache()
                clear_cache(self._port)
                self.analyze_found(found_list)
开发者ID:admgrn,项目名称:Switcharoo,代码行数:71,代码来源:transverse.py


注:本文中的source.Source.mark_searched方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。