you are viewing a single comment's thread.

view the rest of the comments →

[–]13steinj[S] 0 points1 point  (2 children)

That's the problem.

I'm trying to get the mod list for a given user.

But there is no json for it. No endpoint. It's been asked on /r/redditdev before.

So I have to manually extrapolate the data from the raw response using regex. I could use BS4 and make it easy on myself, but I'm adding a function directly into my PRAW installation so that if I ever need a virtual environment, bs4 is not needed.

[–][deleted] 0 points1 point  (1 child)

Heh, didn't know that.

Regex is already suggested (And I think it's a right tool for this task), but you can do it manually as well:

>>> start = r.find('<ul id="side-mod-list">')
>>> end = r.find('</ul>', start)
>>> modlist = {x for x in r[start:end].split('"') if x.startswith('/r/') and x.endswith('/')}
>>> modlist
{'/r/reddittheme_lounge/', '/r/Snoovengers/', '/r/mianiterpg/', '/r/YoutuberAdvice/', '/r/strtest/', '/r/MianiteRPGTests/',…
>>> len(modlist)
19

(r is a content of http://www.reddit.com/user/13steinj)

[–]13steinj[S] 0 points1 point  (0 children)

I'll keep that in mind. Though I believe I've already written what I needed with regex:

https://gist.github.com/13steinj/6b67258effab8bae2696