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