What is the alphanumeric id in a reddit URL?

后端 未结 4 1129
轮回少年
轮回少年 2020-12-29 08:25

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

4条回答
  •  难免孤独
    2020-12-29 08:35

    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)
    

提交回复
热议问题