本文整理匯總了Python中source.Source.add_to_queue方法的典型用法代碼示例。如果您正苦於以下問題:Python Source.add_to_queue方法的具體用法?Python Source.add_to_queue怎麽用?Python Source.add_to_queue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類source.Source
的用法示例。
在下文中一共展示了Source.add_to_queue方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from source import Source [as 別名]
# 或者: from source.Source import add_to_queue [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)