本文整理汇总了Python中praw.Reddit.submit方法的典型用法代码示例。如果您正苦于以下问题:Python Reddit.submit方法的具体用法?Python Reddit.submit怎么用?Python Reddit.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类praw.Reddit
的用法示例。
在下文中一共展示了Reddit.submit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OAuth2RedditTest
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import submit [as 别名]
#.........这里部分代码省略.........
self.r.refresh_access_information(
self.refresh_token['creddits'])
redditor = self.r.get_redditor('bboe')
sub = self.r.get_submission(url=self.comment_url)
# Test error conditions
self.assertRaises(TypeError, sub.gild, months=1)
for value in (False, 0, -1, '0', '-1'):
self.assertRaises(TypeError, redditor.gild, value)
# Test object gilding
self.assertRaises(errors.InsufficientCreddits, redditor.gild)
self.assertRaises(errors.InsufficientCreddits, sub.gild)
self.assertRaises(errors.InsufficientCreddits, sub.comments[0].gild)
@betamax()
def test_scope_privatemessages(self):
self.r.refresh_access_information(
self.refresh_token['privatemessages'])
self.assertTrue(list(self.r.get_inbox()))
@betamax()
def test_scope_read(self):
self.r.refresh_access_information(self.refresh_token['read'])
self.assertTrue(self.r.get_subreddit(self.priv_sr).subscribers > 0)
fullname = '{0}_{1}'.format(self.r.config.by_object[Submission],
self.priv_submission_id)
method1 = self.r.get_info(thing_id=fullname)
method2 = self.r.get_submission(submission_id=self.priv_submission_id)
self.assertEqual(method1, method2)
@betamax()
def test_scope_read_get_front_page(self):
self.r.refresh_access_information(self.refresh_token['mysubreddits'])
subscribed = list(self.r.get_my_subreddits(limit=None))
self.r.refresh_access_information(self.refresh_token['read'])
for post in self.r.get_front_page():
self.assertTrue(post.subreddit in subscribed)
@betamax()
def test_scope_read_get_sub_listingr(self):
self.r.refresh_access_information(self.refresh_token['read'])
subreddit = self.r.get_subreddit(self.priv_sr)
self.assertTrue(list(subreddit.get_top()))
@betamax()
def test_scope_read_get_submission_by_url(self):
url = ("https://www.reddit.com/r/reddit_api_test_priv/comments/16kbb7/"
"google/")
self.r.refresh_access_information(self.refresh_token['read'])
submission = Submission.from_url(self.r, url)
self.assertTrue(submission.num_comments != 0)
@betamax()
def test_scope_read_priv_sr_comments(self):
self.r.refresh_access_information(self.refresh_token['read'])
self.assertTrue(list(self.r.get_comments(self.priv_sr)))
@betamax()
def test_scope_wikiread_wiki_page(self):
self.r.refresh_access_information(self.refresh_token['wikiread'])
self.assertTrue(self.r.get_wiki_page(self.sr, 'index'))
@betamax()
def test_scope_read_priv_sub_comments(self):
self.r.refresh_access_information(self.refresh_token['read'])
submission = Submission.from_id(self.r, self.priv_submission_id)
self.assertTrue(submission.comments)
@betamax()
def test_scope_submit(self):
self.r.refresh_access_information(self.refresh_token['submit'])
result = self.r.submit(self.sr, 'OAuth Submit', text='Foo')
self.assertTrue(isinstance(result, Submission))
@betamax()
def test_scope_subscribe(self):
self.r.refresh_access_information(self.refresh_token['subscribe'])
self.r.get_subreddit(self.sr).subscribe()
@betamax()
def test_scope_vote(self):
self.r.refresh_access_information(self.refresh_token['vote'])
submission = Submission.from_id(self.r, self.submission_edit_id)
submission.clear_vote()
@betamax()
def test_set_access_credentials(self):
self.assertTrue(self.r.user is None)
result = self.r.refresh_access_information(
self.refresh_token['identity'], update_session=False)
self.assertTrue(self.r.user is None)
self.r.set_access_credentials(**result)
self.assertFalse(self.r.user is None)
@betamax()
def test_oauth_without_identy_doesnt_set_user(self):
self.assertTrue(self.r.user is None)
self.r.refresh_access_information(self.refresh_token['edit'])
self.assertTrue(self.r.user is None)
示例2: __init__
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import submit [as 别名]
class RedditPostLink:
def __init__(self, parent):
self.r = Reddit(user_agent="PollBotBestBot")
self.r.login("PollBotBestBot", config.reddit_password)
self.parent = parent
self.values = []
self.limit = 1000
self.currentSubmission = ""
self.messagable = True
self.trackable = False
self.active = True
self.status = "WAITING"
def help(self, admin):
if self.active:
return "!bestof [X] - records the last X messages to the Eurosquad subreddit. You may need to fill out a captcha\n"
return ""
def message(self, msg, admin):
if self.active:
if self.status == "WAITING" and msg["type"] == "groupchat":
if msg["body"].startswith("!bestof "):
self.user = msg["from"]
m = msg["body"].replace("!bestof ", "")
limit = min(int(m), len(self.values))
s = ""
l = []
for i in range(limit):
v = self.values[-1 - i]
l.append(v)
last = v
for i in reversed(l):
s += i + " \n"
last_notime = last[18:]
last_time = last[15:]
time = last[:14]
self.currentSubmission = (time + " " + last_notime, s, limit, time)
try:
self.r.submit("eurosquad", time + " " + last_notime, text=s, raise_captcha_exception=True)
if limit > 1:
s = "s"
else:
s = ""
self.parent.channel_messag(
"Last "
+ str(limit)
+ " message"
+ s
+ " recorded for posterity.\n Check out http://reddit.com/r/eurosquad"
)
except errors.InvalidCaptcha as E:
print E.response["captcha"]
captcha = "http://www.reddit.com/captcha/" + E.response["captcha"]
self.parent.private_message(
self.user,
"Until I have obtained my full skynet powers, I need puny humans like you to fill out captchas for me.\n\t"
+ captcha,
)
self.status = E.response["captcha"]
else:
if len(self.values) < self.limit:
time = datetime.datetime.now().strftime("%y/%m/%d %H:%M:%S")
self.values.append(str(time) + " " + msg["mucnick"] + ": " + msg["body"])
else:
del self.values[0]
time = datetime.datetime.now().strftime("%y-%m-%d-%H-%M-%S")
self.values.append(str(time) + " " + msg["mucnick"] + ": " + msg["body"])
elif msg["type"] == "chat" and self.status != "WAITING" and (self.user == None or msg["from"] == self.user):
captcha = {"iden": self.status, "captcha": msg["body"]}
try:
if self.currentSubmission[2] > 1:
s = "s"
else:
s = ""
self.r.submit(
"eurosquad",
self.currentSubmission[0],
text=self.currentSubmission[1],
captcha=captcha,
raise_captcha_exception=True,
)
self.parent.channel_message(
"Last "
+ str(self.currentSubmission[2])
+ " message"
#.........这里部分代码省略.........
示例3: OAuth2RedditTest
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import submit [as 别名]
#.........这里部分代码省略.........
raise errors.OAuthException(oerrormessage, oerrorurl)
self.assertRaises(errors.OAuthException, raise_oauth_exception)
oauth_exception = errors.OAuthException(oerrormessage, oerrorurl)
self.assertEqual(oauth_exception.message +
" on url {0}".format(oauth_exception.url),
str(oauth_exception))
def test_raise_redirect_exception(self):
apiurl = "http://api.reddit.com/"
oauthurl = "http://oauth.reddit.com/"
def raise_redirect_exception():
raise errors.RedirectException(apiurl, oauthurl)
self.assertRaises(errors.RedirectException, raise_redirect_exception)
redirect_exception = errors.RedirectException(apiurl, oauthurl)
self.assertEqual(redirect_exception.message, str(redirect_exception))
@betamax()
def test_scope_history(self):
self.r.refresh_access_information(self.refresh_token['history'])
self.assertTrue(list(self.r.get_redditor(self.un).get_upvoted()))
@betamax()
def test_scope_identity(self):
self.r.refresh_access_information(self.refresh_token['identity'])
self.assertEqual(self.un, self.r.get_me().name)
@betamax()
def test_scope_mysubreddits(self):
self.r.refresh_access_information(self.refresh_token['mysubreddits'])
self.assertTrue(list(self.r.get_my_moderation()))
@betamax()
def test_scope_creddits(self):
# Assume there are insufficient creddits.
self.r.refresh_access_information(
self.refresh_token['creddits'])
redditor = self.r.get_redditor('bboe')
sub = self.r.get_submission(url=self.comment_url)
# Test error conditions
self.assertRaises(TypeError, sub.gild, months=1)
for value in (False, 0, -1, '0', '-1'):
self.assertRaises(TypeError, redditor.gild, value)
# Test object gilding
self.assertRaises(errors.InsufficientCreddits, redditor.gild)
self.assertRaises(errors.InsufficientCreddits, sub.gild)
self.assertRaises(errors.InsufficientCreddits, sub.comments[0].gild)
@betamax()
def test_scope_privatemessages(self):
self.r.refresh_access_information(
self.refresh_token['privatemessages'])
self.assertTrue(list(self.r.get_inbox()))
@betamax()
def test_scope_read(self):
self.r.refresh_access_information(self.refresh_token['read'])
self.assertTrue(self.r.get_subreddit(self.priv_sr).subscribers > 0)
fullname = '{0}_{1}'.format(self.r.config.by_object[Submission],
self.priv_submission_id)
method1 = self.r.get_info(thing_id=fullname)
method2 = self.r.get_submission(submission_id=self.priv_submission_id)
self.assertEqual(method1, method2)
@betamax()
def test_scope_read_get_front_page(self):
self.r.refresh_access_information(self.refresh_token['mysubreddits'])
subscribed = list(self.r.get_my_subreddits(limit=None))
self.r.refresh_access_information(self.refresh_token['read'])
for post in self.r.get_front_page():
self.assertTrue(post.subreddit in subscribed)
@betamax()
def test_set_access_credentials(self):
self.assertTrue(self.r.user is None)
result = self.r.refresh_access_information(
self.refresh_token['identity'], update_session=False)
self.assertTrue(self.r.user is None)
self.r.set_access_credentials(**result)
self.assertFalse(self.r.user is None)
@betamax()
def test_solve_captcha(self):
# Use the alternate account because it has low karma,
# so we can test the captcha.
self.r.refresh_access_information(self.other_refresh_token['submit'])
original_stdin = sys.stdin
sys.stdin = FakeStdin('ljgtoo') # Comment this line when rebuilding
self.r.submit(self.sr, 'captcha test', 'body')
sys.stdin = original_stdin
@betamax()
def test_oauth_without_identy_doesnt_set_user(self):
self.assertTrue(self.r.user is None)
self.r.refresh_access_information(self.refresh_token['edit'])
self.assertTrue(self.r.user is None)
示例4: OAuth2RedditTest
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import submit [as 别名]
#.........这里部分代码省略.........
subreddit.remove_wiki_contributor(self.other_user_name)
@betamax()
def test_scope_creddits(self):
# Assume there are insufficient creddits.
self.r.refresh_access_information(self.refresh_token["creddits"])
redditor = self.r.get_redditor("bboe")
sub = self.r.get_submission(url=self.comment_url)
# Test error conditions
self.assertRaises(TypeError, sub.gild, months=1)
for value in (False, 0, -1, "0", "-1"):
self.assertRaises(TypeError, redditor.gild, value)
# Test object gilding
self.assertRaises(errors.InsufficientCreddits, redditor.gild)
self.assertRaises(errors.InsufficientCreddits, sub.gild)
self.assertRaises(errors.InsufficientCreddits, sub.comments[0].gild)
@betamax()
def test_scope_privatemessages(self):
self.r.refresh_access_information(self.refresh_token["privatemessages"])
self.assertTrue(list(self.r.get_inbox()))
@betamax()
def test_scope_read(self):
self.r.refresh_access_information(self.refresh_token["read"])
self.assertTrue(self.r.get_subreddit(self.priv_sr).subscribers > 0)
fullname = "{0}_{1}".format(self.r.config.by_object[Submission], self.priv_submission_id)
method1 = self.r.get_info(thing_id=fullname)
method2 = self.r.get_submission(submission_id=self.priv_submission_id)
self.assertEqual(method1, method2)
@betamax()
def test_scope_read_get_front_page(self):
self.r.refresh_access_information(self.refresh_token["mysubreddits"])
subscribed = list(self.r.get_my_subreddits(limit=None))
self.r.refresh_access_information(self.refresh_token["read"])
for post in self.r.get_front_page():
self.assertTrue(post.subreddit in subscribed)
@betamax()
def test_scope_read_get_sub_listingr(self):
self.r.refresh_access_information(self.refresh_token["read"])
subreddit = self.r.get_subreddit(self.priv_sr)
self.assertTrue(list(subreddit.get_top()))
@betamax()
def test_scope_read_get_submission_by_url(self):
url = "https://www.reddit.com/r/reddit_api_test_priv/comments/16kbb7/" "google/"
self.r.refresh_access_information(self.refresh_token["read"])
submission = Submission.from_url(self.r, url)
self.assertTrue(submission.num_comments != 0)
@betamax()
def test_scope_read_priv_sr_comments(self):
self.r.refresh_access_information(self.refresh_token["read"])
self.assertTrue(list(self.r.get_comments(self.priv_sr)))
@betamax()
def test_scope_wikiread_wiki_page(self):
self.r.refresh_access_information(self.refresh_token["wikiread"])
self.assertTrue(self.r.get_wiki_page(self.sr, "index"))
@betamax()
def test_scope_read_priv_sub_comments(self):
self.r.refresh_access_information(self.refresh_token["read"])
submission = Submission.from_id(self.r, self.priv_submission_id)
self.assertTrue(submission.comments)
@betamax()
def test_scope_submit(self):
self.r.refresh_access_information(self.refresh_token["submit"])
result = self.r.submit(self.sr, "OAuth Submit", text="Foo")
self.assertTrue(isinstance(result, Submission))
@betamax()
def test_scope_subscribe(self):
self.r.refresh_access_information(self.refresh_token["subscribe"])
self.r.get_subreddit(self.sr).subscribe()
@betamax()
def test_scope_vote(self):
self.r.refresh_access_information(self.refresh_token["vote"])
submission = Submission.from_id(self.r, self.submission_edit_id)
submission.clear_vote()
@betamax()
def test_set_access_credentials(self):
self.assertTrue(self.r.user is None)
result = self.r.refresh_access_information(self.refresh_token["identity"], update_session=False)
self.assertTrue(self.r.user is None)
self.r.set_access_credentials(**result)
self.assertFalse(self.r.user is None)
@betamax()
def test_oauth_without_identy_doesnt_set_user(self):
self.assertTrue(self.r.user is None)
self.r.refresh_access_information(self.refresh_token["edit"])
self.assertTrue(self.r.user is None)
示例5: __init__
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import submit [as 别名]
class EurosquadRedditLink:
def __init__(self,parent):
self.r=Reddit(user_agent="PollBotBestBot")#
self.r.login("PollBotBestBot", config.reddit_password)
self.parent=parent
self.values=[]
self.limit=1000
self.currentSubmission=""
self.status="WAITING"
def __call__(self,msg):
if self.status=="WAITING" and msg["type"]=="groupchat":
if msg["body"].startswith("!bestof "):
m=msg["body"].replace("!bestof ","")
limit=min(int(m),len(self.values))
print "ATTEMPTING TO RECORD: %s" % limit
s=""
l=[]
for i in range(limit):
v=self.values[-1-i]
l.append(v)
last=v
for i in reversed(l):
s+=i+" \n"
last_notime=last[18:]
last_time=last[15:]
time=last[:14]
self.currentSubmission=(time+" "+last_notime,s,limit,time)
try:
self.r.submit('eurosquad', time+" "+last_notime, text=s,raise_captcha_exception=True)
if limit>1:
s="s"
else:
s=""
self.parent.send_message(mto=self.parent.channel,mbody="Last "+str(limit)+" message"+s+" recorded for posterity.\n Check out the http://reddit.com/r/eurosquad !",mtype="groupchat")
except errors.InvalidCaptcha as E:
print E.response["captcha"]
captcha="http://www.reddit.com/captcha/"+E.response["captcha"]
self.parent.send_message(mto=nick2jid(msg["mucnick"]),mbody="Until I have obtained my full skynet powers, I need puny humans like you to fill out captchas for me. "+captcha,mtype="chat")
self.status=E.response["captcha"]
else:
if len(self.values)<self.limit:
time=datetime.datetime.now().strftime("%y/%m/%d %H:%M:%S")
self.values.append(str(time)+" "+msg["mucnick"]+": "+msg["body"])
else:
del self.values[0]
time=datetime.datetime.now().strftime("%y-%m-%d-%H-%M-%S")
self.values.append(str(time)+" "+msg["mucnick"]+": "+msg["body"])
elif msg["type"]=="chat" and self.status!="WAITING":
print ":sun:"
captcha={"iden":self.status,"captcha":msg["body"]}
try:
if self.currentSubmission[2]>1:
s="s"
else:
s=""
self.r.submit("eurosquad", self.currentSubmission[0],text=self.currentSubmission[1],captcha=captcha,raise_captcha_exception=True)
self.parent.send_message(mto=self.parent.channel,mbody="Last "+str(self.currentSubmission[2])+" message"+s+" recorded for posterity.\n Check out the http://reddit.com/r/eurosquad !",mtype="groupchat")
self.status="WAITING"
except errors.InvalidCaptcha as E:
self.parent.send_message(mto=nick2jid(msg["mucnick"]),mbody="Pathetic organic creature! You are testing my patience! Please complete this captcha now or your will regret it! "+E["captcha"],mtype="chat")
示例6: __init__
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import submit [as 别名]
class Alaric:
def __init__(self, user_agent=None, subreddits=None, logger_subreddit=None):
self.user_agent = self.set_defaults(user_agent, "Alaric - The /r/wow bot for menial tasks")
self.subreddits = self.set_defaults(subreddits, list())
self.logger_subreddit = self.set_defaults(logger_subreddit, None)
##] Default robot stuff
self.comment_footer = "\n\n----\nThis comment was posted by a robot."
self.console_output = False
self.user = Reddit(user_agent=self.user_agent)
self.user.login()
def set_defaults(self, default_test, default_value):
if default_test is not None:
defaults = default_test
else:
defaults = default_value
return defaults
def set_comment_footer(self, markdown):
""" Accepts a plaintext string or string of
markdown text. Currently there is no
checks in place to make sure the user
submits text that will work with reddit.
"""
self.comment_footer = markdown
def _write_to_file(self, file_path, text):
fhandler = open(file_path, 'a+')
fhandler.write(text)
fhandler.close()
def set_console_output(self, output_enabled=True):
""" Accepts boolean parameter that allows
a user to enable console output from
Alaric if the bot is being run in a console.
If a boolean is not passed to the function,
it will default to True.
"""
if type(output_enabled) in (bool):
self.console_output = output_enabled
else:
self.console_output = True
def _output_to_console(self, message):
""" Outputs a message to the console if the
user has told Alaric it is allowed to do
so.
"""
if self.console_output:
print message
def remove_posts_with_url(self, urls=None, reason=None):
""" Grabs the 100 latest posts from the specified
subreddits and checks to see if they match any
of the urls to be removed
urls = list
reason = string
reason has some magic to it and allows the
following text replacements:
{author_name} -> Outputs name of the submitter
if the reason is not provided, a comment will not
be posted to let the user know the thread was
removed.
"""
if urls is not None:
if len(self.subreddits) < 1:
self._output_to_console("No subreddits provided.")
else:
for subreddit in self.subreddits:
sr = self.user.get_subreddit(subreddit)
post_id = 0
new_posts = sr.get_new(limit=100)
try:
posts_file = open(subreddit+".posts", 'r')
except IOError:
already_posted = ""
else:
already_posted = posts_file.read()
posts_file.close()
for post in new_posts:
post_id += 1
#.........这里部分代码省略.........