Skip to content

Commit

Permalink
reddit: updating reddit module praw dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyBower committed Mar 16, 2019
1 parent dafa08a commit 9d6cbc1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
xmltodict
pytz
praw<6.0.0
praw>=4.0.0,<6.0.0
pyenchant; python_version < '3.7'
geoip2
ipython<6.0; python_version < '3.3'
Expand Down
60 changes: 30 additions & 30 deletions sopel/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sopel.tools import SopelMemory, time
import datetime as dt
import praw
import prawcore
import re
import sys
if sys.version_info.major >= 3:
Expand Down Expand Up @@ -123,43 +124,42 @@ def redditor_info(bot, trigger, match=None):
match = match or trigger
try:
u = r.get_redditor(match.group(2))
except Exception: # TODO: Be specific
message = '[REDDITOR] ' + u.name
now = dt.datetime.utcnow()
cakeday_start = dt.datetime.utcfromtimestamp(u.created_utc)
cakeday_start = cakeday_start.replace(year=now.year)
day = dt.timedelta(days=1)
year_div_by_400 = now.year % 400 == 0
year_div_by_100 = now.year % 100 == 0
year_div_by_4 = now.year % 4 == 0
is_leap = year_div_by_400 or ((not year_div_by_100) and year_div_by_4)
if (not is_leap) and ((cakeday_start.month, cakeday_start.day) == (2, 29)):
# If cake day is 2/29 and it's not a leap year, cake day is 1/3.
# Cake day begins at exact account creation time.
is_cakeday = cakeday_start + day <= now <= cakeday_start + (2 * day)
else:
is_cakeday = cakeday_start <= now <= cakeday_start + day

if is_cakeday:
message = message + ' | 13Cake day'
if commanded:
message = message + ' | https://reddit.com/u/' + u.name
if u.is_gold:
message = message + ' | 08Gold'
if u.is_mod:
message = message + ' | 05Mod'
message = message + (' | Link: ' + str(u.link_karma) +
' | Comment: ' + str(u.comment_karma))

bot.say(message)
except prawcore.exceptions.NotFound:
if commanded:
bot.say('No such Redditor.')
return NOLIMIT
else:
return
# Fail silently if it wasn't an explicit command.

message = '[REDDITOR] ' + u.name
now = dt.datetime.utcnow()
cakeday_start = dt.datetime.utcfromtimestamp(u.created_utc)
cakeday_start = cakeday_start.replace(year=now.year)
day = dt.timedelta(days=1)
year_div_by_400 = now.year % 400 == 0
year_div_by_100 = now.year % 100 == 0
year_div_by_4 = now.year % 4 == 0
is_leap = year_div_by_400 or ((not year_div_by_100) and year_div_by_4)
if (not is_leap) and ((cakeday_start.month, cakeday_start.day) == (2, 29)):
# If cake day is 2/29 and it's not a leap year, cake day is 1/3.
# Cake day begins at exact account creation time.
is_cakeday = cakeday_start + day <= now <= cakeday_start + (2 * day)
else:
is_cakeday = cakeday_start <= now <= cakeday_start + day

if is_cakeday:
message = message + ' | 13Cake day'
if commanded:
message = message + ' | https://reddit.com/u/' + u.name
if u.is_gold:
message = message + ' | 08Gold'
if u.is_mod:
message = message + ' | 05Mod'
message = message + (' | Link: ' + str(u.link_karma) +
' | Comment: ' + str(u.comment_karma))

bot.say(message)


# If you change the groups here, you'll have to change some things above.
@rule('.*%s.*' % user_url)
Expand Down

0 comments on commit 9d6cbc1

Please sign in to comment.