本文整理汇总了Python中history.History.add_link_as_posted方法的典型用法代码示例。如果您正苦于以下问题:Python History.add_link_as_posted方法的具体用法?Python History.add_link_as_posted怎么用?Python History.add_link_as_posted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.add_link_as_posted方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add_link_as_posted [as 别名]
def main():
level = 0
# Read program arguments
for arg in sys.argv[1:]:
(param, value) = arg.split('=')
if param == '--level':
level = int(value)
path = os.path.dirname(os.path.realpath(__file__))
loggingConf = open('{0}/configs/logging.yml'.format(path), 'r')
logging.config.dictConfig(yaml.load(loggingConf))
loggingConf.close()
logger = logging.getLogger(LOGGER)
logger.info('Program started')
config = configparser.ConfigParser()
config.read('{0}/configs/bot.ini'.format(path))
username = config['Reddit']['username']
password = config['Reddit']['password']
user_agent = config['Reddit']['user-agent']
dry_run = config['Bot'].getboolean('dry-run')
if dry_run:
logger.info('Running in dry run mode. Nothing will be commited')
reddit = Reddit(username, password, user_agent, dry_run)
history = History('{0}/{1}'.format(path, DATABASE))
news = News()
if level == 0:
level = int(config['Bot']['level'])
news_items = news.get_news_items(level)
for item in news_items:
url = item[0]
title = item[1]
degree = item[2]
if not history.has_link_been_posted(url):
history.add_link_as_posted(url, dry_run)
if not reddit.post_link(get_redirect_url(url), title):
continue
break
logger.info('Program done')