有人能告诉我这行代码在执行什么吗?
if __name__ == "__main__":
TwitterHarvester.main(TwitterHarvester, QUEUE, [SEARCH_ROUTING_KEY, TIMELINE_ROUTING_KEY])这是一个python文件,包含一个名为TwitterHarvester的类,它没有定义主函数。有人能告诉我这条电话在打什么吗?
这是功能的起点;
class TwitterHarvester(BaseHarvester):
def __init__(self, working_path, stream_restart_interval_secs=30 * 60, mq_config=None, debug=False,
connection_errors=5, http_errors=5, debug_warcprox=False, tries=3):
BaseHarvester.__init__(self, working_path, mq_config=mq_config,
stream_restart_interval_secs=stream_restart_interval_secs,
debug=debug, debug_warcprox=debug_warcprox, tries=tries)
self.twarc = None
self.connection_errors = connection_errors
self.http_errors = http_errors
def harvest_seeds(self):
# Create a twarc
self._create_twarc()
# Dispatch message based on type.
harvest_type = self.message.get("type")
log.debug("Harvest type is %s", harvest_type)
if harvest_type == "twitter_search":
self.search()
elif harvest_type == "twitter_filter":
self.filter()
elif harvest_type == "twitter_sample":
self.sample()
elif harvest_type == "twitter_user_timeline":
self.user_timeline()
else:
raise KeyError
def _create_twarc(self):发布于 2022-06-16 14:38:37
TwitterHarvester扩展了BaseHarvester。因此,如果TwitterHarvester没有主函数,那么它应该在BaseHarvester中。
谷歌告诉我,基地收割机是sfm-utils包的一部分。导入行是这里
from sfmutils.harvester import BaseHarvester, Msg因此,我在sfm-utls源代码中找到了:
class BaseHarvester(BaseConsumer):
"""
Base class for a harvester, allowing harvesting from a queue or from a file.
...
"""
...
@staticmethod
def main(cls, queue, routing_keys):
"""
A configurable main() for a harvester.给你:)
https://stackoverflow.com/questions/72647447
复制相似问题