本文整理汇总了Python中praw.Reddit.login方法的典型用法代码示例。如果您正苦于以下问题:Python Reddit.login方法的具体用法?Python Reddit.login怎么用?Python Reddit.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类praw.Reddit
的用法示例。
在下文中一共展示了Reddit.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mark_as_read
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def test_mark_as_read(self):
oth = Reddit(USER_AGENT)
oth.login('PyApiTestUser3', '1111')
# pylint: disable-msg=E1101
msg = six_next(oth.user.get_unread(limit=1))
msg.mark_as_read()
self.assertTrue(msg not in oth.user.get_unread(limit=5))
示例2: reddit_parser
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def reddit_parser():
args = build_reddit_parser().parse_args()
db_connection = create_connection(args.db_host, args.db_password)
reddit = Reddit(user_agent=args.user_agent)
subreddit = reddit.get_subreddit(args.subreddit)
if args.username:
password = getpass("Enter reddit password: ")
reddit.login(args.username, password)
single_threaded_impl(subreddit, db_connection, args.sub_limit, args.method)
示例3: update_reddit
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def update_reddit(self):
#Initialize PRAW and login
r = Reddit(user_agent='/r/reddevils bot by /u/Hubwub')
r.login(self.username,self.password)
#Grab the current settings
settings = r.get_subreddit(self.subreddit).get_settings()
#Update the sidebar
#print sidebar
settings['description'] = sidebar
settings = r.get_subreddit(self.subreddit).update_settings(description=settings['description'])
示例4: __init__
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
class Snitch:
def __init__(self, username, passwd, url, subreddit):
self.rh = Reddit('Release the Snitch v 0.1 by Kolpa')
self.rh.login(username, passwd)
self.css = self.__load_css()
self.desc = self.__load_desc()
self.url = url
self.subreddit = subreddit
def __load_css(self):
with open('raw.css', 'r') as f:
return f.read()
def __load_desc(self):
with open('descripiton.txt', 'r') as f:
return f.read()
def __get_last_id(self):
with open('current', 'r') as f:
return f.read()
def __set_new_id(self):
id = randrange(0, 999999)
with open('current', 'w') as f:
f.write(str(id))
return id
def _get_random_pos(self):
return randrange(0, 100, 10), randrange(0, 100, 10)
def __update_desc(self, desc):
self.rh.update_settings(self.rh.get_subreddit(self.subreddit), description=desc)
def can_move(self, id):
if not os.path.exists('current'):
return True
return id == self.__get_last_id()
def move(self, id):
try:
if self.can_move(id):
new_id = self.__set_new_id()
desc = self.desc.format(new_id)
x, y = self._get_random_pos()
css = self.css.format(x, y, self.url)
self.rh.set_stylesheet(self.subreddit, css)
self.__update_desc(desc)
return True
except Exception:
return False
示例5: test_mark_as_unread
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def test_mark_as_unread(self):
oth = Reddit(USER_AGENT)
oth.login('PyApiTestUser3', '1111')
found = None
for msg in oth.user.get_inbox():
if not msg.new:
found = msg
msg.mark_as_unread()
break
else:
self.fail('Could not find a read message.')
self.assertTrue(found in oth.user.get_unread())
示例6: test_mark_multiple_as_read
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def test_mark_multiple_as_read(self):
oth = Reddit(USER_AGENT)
oth.login('PyApiTestUser3', '1111')
messages = []
for msg in oth.user.get_unread(limit=None):
if msg.author != oth.user.name:
messages.append(msg)
if len(messages) >= 2:
return
self.assertEqual(2, len(messages))
self.r.user.mark_as_read(messages)
unread = oth.user.get_unread(limit=5)
for msg in messages:
self.assertTrue(msg not in unread)
示例7: main
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def main():
parser = argparse.ArgumentParser(
prog='modbot.py',
description="Subreddit automoderating script")
parser.add_argument('subreddit')
parser.add_argument('-r', '--rulesdir', default='./rules')
parser.add_argument('-u', '--user')
parser.add_argument('-p', '--password')
args = parser.parse_args()
rh = RuleHandler(args.rulesdir, '*.rule')
logging.config.fileConfig('logging.conf')
reddit = Reddit('%s/%s' % (NAME, VERSION))
try:
reddit.login(args.user, args.password)
except praw.errors.InvalidUserPass:
logging.critical("Login failure")
sys.exit(1)
sub = reddit.get_subreddit(args.subreddit)
read_thinglists()
comments_ph = None
submissions_ph = None
while True:
logging.debug("Loop start")
loopstart = time.time()
try:
modqueue_items = sub.get_mod_queue(limit=100)
except Exception, e:
modqueue_items = []
num = 0
for modqueue_item in modqueue_items:
num += 1
matchrules(modqueue_item, rh.rules, is_modqueue=True)
logging.info("Checked %d modqueue items" % num)
try:
if comments_ph == None:
comments = sub.get_comments(limit=100)
else:
comments = sub.get_comments(place_holder=comments_ph,
limit=500)
except Exception, e:
comments = []
示例8: update_countdown
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def update_countdown(username, password, subreddit_name, target):
user_agent = '/r/{0} countdown'.format(subreddit_name)
reddit = Reddit(user_agent)
reddit.login(username, password, disable_warning=True)
# reddit access
subreddit = reddit.get_subreddit(subreddit_name)
settings = subreddit.get_settings()
description = HTMLParser().unescape(settings['description'])
# time matches
countdown_delta = target - datetime.now()
days_left = countdown_delta.days
hours_left = countdown_delta.seconds // 3600
# regex and strings
# countdownSearch = re.compile("(\[\d?\d?\]\([#][a-z]*\)\s[a-z]*[!]?\s?)+", re.I) # old regex
countdownSearch = re.compile("((\s([a-z]{4})*)*\s?\[\d?\d?\]\([#][a-z]*\)\s[a-z]*[!]?\s?)+", re.I)
origStr = " less than [](#days) days [](#hours) hours\n"
noDaysStr = " less than [](#hours) hours\n"
noHoursStr = " less than [](#minutes) minutes\n"
raceLiveStr = " [](#days) Racing [](#hours) is [](#minutes) live\n"
updatemeStr = " [](#days) Current [](#hours) event [](#minutes) ended\n"
# make sure our event hasn't happened yet
if target > datetime.now():
if days_left > 0:
description = re.sub(countdownSearch, origStr, description)
elif hours_left > 0 and days_left == 0:
description = re.sub(countdownSearch, noDaysStr, description)
else:
description = re.sub(countdownSearch, noHoursStr, description)
for key, value in compute_time_ago_params(target).iteritems():
pattern = "\\[[^\\]]*\\]\\(#{0}\\)".format(key) # replace [<anything>](#<key>)
repl = "[{0}](#{1})".format(value, key) # with [<value>](#<key>)
description = re.sub(pattern, repl, description)
# if race is happening, show raceLiveStr, else race is over, show updatemeStr
else:
countdownSearch.search(description)
if target.hour > datetime.now().hour - 3:
description = re.sub(countdownSearch, raceLiveStr, description)
else:
description = re.sub(countdownSearch, updatemeStr, description)
subreddit.update_settings(description=description)
示例9: update_countdown
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def update_countdown(username, password, subreddit_name, target):
user_agent = '/r/{0} countdown bot'.format(subreddit_name)
reddit = Reddit(user_agent)
reddit.login(username, password)
subreddit = reddit.get_subreddit(subreddit_name)
settings = subreddit.get_settings()
description = HTMLParser().unescape(settings['description'])
for key, value in compute_time_ago_params(target).iteritems():
pattern = "\\[[^\\]]*\\]\\(#{0}\\)".format(key) # replace [<anything>](#<key>)
repl = "[{0}](#{1})".format(value, key) # with [<value>](#<key>)
description = re.sub(pattern, repl, description)
print(description)
subreddit.update_settings(description=description)
示例10: create_sidebar
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def create_sidebar(self):
h = HTMLParser.HTMLParser()
#Initialize PRAW and login
r = Reddit(user_agent='/r/reddevils bot by /u/Hubwub')
r.login(self.username,self.password)
#Grab the sidebar template from the wiki
sidebar = r.get_subreddit(self.subreddit).get_wiki_page('edit_sidebar').content_md
#Create list from sidebar by splitting at ####
sidebar_list = sidebar.split('####')
#Sidebar
#print sidebar_list
#sidebar = (sidebar_list[0]+league+sidebar_list[1])
sidebar = (sidebar_list[0]+league+rfixtures+goals+sidebar_list[1])
#Fix characters in sidebar
sidebar = h.unescape(sidebar)
return sidebar
示例11: test_report
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def test_report(self):
# login as new user to report submission
oth = Reddit(USER_AGENT)
oth.login('PyApiTestUser3', '1111')
subreddit = oth.get_subreddit(self.sr)
submission = None
for submission in subreddit.get_new_by_date():
if not submission.hidden:
break
else:
self.fail('Could not find a non-reported submission.')
submission.report()
# check if submission was reported
for report in self.r.get_subreddit(self.sr).get_reports():
if report.id == submission.id:
break
else:
self.fail('Could not find reported submission.')
示例12: verify
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def verify(moderator_username, moderator_password,
username, subreddit,
flair_text=None, flair_css=None):
api = Reddit(user_agent=settings.USER_AGENT)
try:
api.login(moderator_username, moderator_password)
subreddit = api.get_subreddit(subreddit)
subreddit.add_contributor(username)
api.set_flair(subreddit, username, flair_text, flair_css)
except praw.errors.RateLimitExceeded:
raise RateLimitExceededException
except praw.errors.ModeratorRequired:
raise ModeratorRequiredException
except praw.errors.InvalidUserPass:
raise InvalidLoginException
except praw.errors.BadCSS:
raise InvalidCSSException
except praw.errors.InvalidUser:
raise InvalidUserException
except praw.errors.APIException as e:
raise RedditAPIException(e)
except praw.errors.ClientException as e:
raise RedditAPIException(e)
示例13: Reddit
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
# /r/AFL Subreddit Flair Statistics
#!/usr/bin/env python
import sys
from datetime import datetime
from praw import Reddit
user = 'rAFLgamethread'
password = 'ENTERPASSWORDHERE'
srname = 'AFL'
edit_reason = 'Updated by /u/rAFLgamethread bot'
r = Reddit('AFL-flairstats/0.1')
r.login(user, password)
sr = r.get_subreddit(srname)
flair_templates = {
'adelaide': 'Adelaide',
'adelaide2': 'Adelaide 2',
'adelaide3': 'Adelaide 3',
'adelaide5': 'Adelaide 5',
'brisbane': 'Brisbane',
'brisbane2': 'Brisbane 2',
'brisbane3': 'Brisbane 3',
'brisbane5': 'Brisbane 5',
'carlton': 'Carlton',
'carlton2': 'Carlton 2',
'carlton3': 'Carlton 3',
'carlton4': 'Carlton 4',
'collingwood': 'Collingwood',
'collingwood2': 'Collingwood 2',
示例14: debug
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
# logging settings
logging.basicConfig(format='%(asctime)-15s [%(name)s] %(levelname)s | %(message)s',
level=logging.DEBUG)
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.WARNING)
debug("Initializing parser...")
# init reddit session
reddit = Reddit(user_agent=REDDIT_USERAGENT)
try:
debug("Logging in to Reddit...")
reddit.login(**REDDIT_CREDENTIALS)
except HTTPError as e:
error("Couldn't login to reddit: {0}".format(e))
# create DB session
engine = create_engine(DB_PATH)
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
if __name__ == '__main__':
request_session = requests.session()
for post in session.query(Post).all():
示例15: set_up_reddit
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import login [as 别名]
def set_up_reddit(username, password):
r = Reddit(user_agent='linux:net.dosaki.subreddit_header_countdown:0.0.2 (by /u/dosaki)')
r.login(username, password)
return r