What is the alphanumeric id in a reddit URL?
Asked Answered
G

4

15

What is the 7n5lu in the reddit URL

http://www.reddit.com/r/reddit.com/comments/7n5lu/man_can_fly_if_you_watch_one_video_in_2

...and how is it generated?

Update: @Gerald, I initially thought this is some obfuscation of the id. It is just doing the conversion from integer to a more compact representation. I am thinking, why is this being done? why not use the original integer itself!!

>>> to36(4000)
'334'
>>> to36(4001)
'335'
Gobbler answered 4/1, 2009 at 5:1 Comment(1)
If you use numbers with letters, the final string is shorter. e.g.: to36(9) == '9' to36(10) == 'a'Busey
F
28

The reddit source code is available! Here is what I found for generating that string:

def to_base(q, alphabet):
    if q < 0: raise ValueError, "must supply a positive integer"
    l = len(alphabet)
    converted = []
    while q != 0:
        q, r = divmod(q, l)
        converted.insert(0, alphabet[r])
    return "".join(converted) or '0'

def to36(q):
    return to_base(q, '0123456789abcdefghijklmnopqrstuvwxyz')

and elsewhere, under the "Link" class:

@property
def _id36(self):
    return to36(self._id)
Forehead answered 4/1, 2009 at 5:1 Comment(1)
Note they have a micro-bug: the zero case assumes zero is "0". The last line should end with "or alphabet[0]".Oppress
P
0

It is an integer, just in base 36. The id is generated sequentially. For example, the comment right after id 89 is id 8a, etc. Given this, you don't need any other information from the URL.

Comments, posts, messages, users, and subreddits can in theory have the same ID and count up. You can differentiate them by their "fullname" which is the type of thing, an underscore, and then an underscore.

t1 is a comment, t2 is a user, t3 is a submission, t4 is a message, t5 is a subreddit, t6 is an award, ModAction is a moderator action, ModmailConversation is a modmail conversation, etc.

See the API documentation for more information.

Pyrography answered 4/1, 2009 at 5:1 Comment(0)
R
0

That looks like a unique id for the thread. It's most likely used to find the thread in the database.

Radicel answered 4/1, 2009 at 5:1 Comment(0)
M
-1

Little remark.

It is not sufficient for this example but usually appending to lists

a = []
for i in range(NNN): a.append(i)
a.reverse()

really more efficient than inserting at head.

a = []
for i in range(NNN): a.insert(0,i)

.

Masterpiece answered 4/1, 2009 at 5:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.