开发者

HTML Tag Cloud in Python

开发者 https://www.devze.com 2023-01-06 06:26 出处:网络
I am looking for a simple library which can be given a set of items:value pair and which can generate a tag cloud as output.

I am looking for a simple library which can be given a set of items:value pair and which can generate a tag cloud as output.

Library can preferably be i开发者_如何学运维n python


Define font-sizes in your css-file. Use classes from

size-0{
   font-size: 11px;
}

size-1{
   font-size: 12px;
}

etc. up to the font-size you need.

And then simply use this snippet:

CSS_SIZES = range(1, 7) # 1,2...6 for use in your css-file size-1, size-2, etc.

TAGS = {
    'python' : 28059,
    'html' : 19160,
    'tag-cloud' : 40,
}

MAX = max(TAGS.values()) # Needed to calculate the steps for the font-size

STEP = MAX / len(CSS_SIZES)

for tag, count in TAGS.items():
    css = count / STEP        
    print '<a href="%s" class="size-%s">%s</a>' % (tag, css, tag),

That's all. No need for a library ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号