You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: plugins/reddit_info.py
+37-52Lines changed: 37 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -1,38 +1,22 @@
1
-
importrequests
2
-
3
1
fromcollectionsimportdefaultdict
4
2
fromdatetimeimportdatetime
3
+
4
+
importrequests
5
5
frombs4importBeautifulSoup
6
+
6
7
fromcloudbotimporthook
7
8
fromcloudbot.utilimportcolors
8
9
fromcloudbot.util.formattingimportpluralize
10
+
fromcloudbot.util.pagerimportpaginated_list
9
11
10
-
search_pages=defaultdict(list)
11
-
search_page_indexes= {}
12
+
search_pages=defaultdict(dict)
12
13
13
14
user_url="http://reddit.com/user/{}/"
14
15
subreddit_url="http://reddit.com/r/{}/"
15
16
# This agent should be unique for your cloudbot instance
16
17
agent= {"User-Agent": "gonzobot a cloudbot (IRCbot) implementation for snoonet.org by /u/bloodygonzo"}
17
18
18
19
19
-
deftwo_lines(bigstring, chan):
20
-
"""Receives a string with new lines. Groups the string into a list of strings with up to 2 new lines per string element. Returns first string element then stores the remaining list in search_pages."""
"""if a sub or mod list has lots of results the results are pagintated. If the most recent search is paginated the pages are stored for retreival. If no argument is given the next page will be returned else a page number can be specified."""
54
-
ifnotsearch_pages[chan]:
38
+
chan_cf=chan.casefold()
39
+
pages=search_pages[conn.name].get(chan_cf)
40
+
ifnotpages:
55
41
return"There are modlist pages to show."
56
42
iftext:
57
43
try:
58
44
index=int(text)
59
45
exceptValueError:
60
46
return"Please specify an integer value."
61
-
ifabs(index) >len(search_pages[chan]) orindex==0:
47
+
page=pages[index-1]
48
+
ifpageisNone:
62
49
return"please specify a valid page number between 1 and {}.".format(len(search_pages[chan]))
0 commit comments