Sunday, February 5, 2012

A few more random bits

localshop - "really, really alpha" but promising local PyPI mirror / private repository. Yes, another one. This one might just be the one to meet my specific requirements though...

pytagcloud - is one to watch: make tag clouds as PNG images or HTML. Usage is a bit fiddly at the moment and I couldn't replicate the results they got. I think the key is having a good tag (interesting word) extractor. This bit of code might come in handy when experimenting with it:
import re
from roundup.backends.indexer_common import STOPWORDS
import requests, collections, bs4
soup = requests.get('').text
text = bs4.BeautifulSoup(soup).find('div', id='content-body').get_text()
counts = collections.defaultdict(int)
for word in re.split('\W+', text):
    if word.upper() not in STOPWORDS and len(word)>2:
        counts[word.lower()] += 1
words = sorted((count, word) for word, count in counts.items())
tags = [(word, count) for count, word in words[-30:]]

from pytagcloud import make_tags, create_tag_image
create_tag_image(make_tags(tags), 'cloud.png')
Sadly it doesn't quite work for me. I suspect something might up up with my pygame/platform's TTF support. I also had to add a Font object cache to stop it blowing up on my system (git pull request submitted :-)

slumber - call web RESTful (HTTP) APIs from Python code. Supports JSON, and YAML (with pyyaml installed) and is built on top of the awesome requests. While looking at slumber I picked up this tip for validating and pretty-printing JSON:
$ echo '{"json":"obj"}' | python -m json.tool
    "json": "obj"


  1. Slumber looks a lot like [Dolt]( Full Disclosure: I contributed to Dolt.

    1. Cool, thanks for the tip! I imagine there's probably a bunch of similar solutions out there - I just happened to notice Slumber in passing looking at something else :-)