Ejemplo n.º 1
0
def make_html_data(tag_count,
                   file_name,
                   font_max_size=120,
                   html_size=(900, 600)):
    tag_list = make_tags(tag_count, maxsize=font_max_size)
    data = create_html_data(tag_list,
                            size=html_size,
                            layout=LAYOUT_HORIZONTAL,
                            fontname='Korean')
    template_file = open(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     'web/template.html'), 'r')
    html_template = Template(template_file.read())

    context = {}

    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s"\
            style="top: %(top)dpx;left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)\
            dpx;">%(tag)s</a></li>'

    context['tags'] = ''.join([tags_template % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
            a.%(cname)s:hover{color:%(hover)s;}" % {
        'cname': k,
        'normal': v[0],
        'hover': v[1]
    } for k, v in data['css'].items())

    html_text = html_template.substitute(context)

    html_file = open(os.path.join('../dist', file_name), 'w')
    html_file.write(html_text)
    html_file.close()
    def generate_html(self, word_freq_tup_list, search_term):
        """
        this function generates html file depicting word cloud word_freq_tup is passed by the caller
        :param word_freq_tup_list:
        :return: generated word cloud html text
        """
        tags = make_tags(word_freq_tup_list)
        # print tags

        cloud_html = create_html_data(tags[:100], (500, 500),
                                      layout=LAYOUT_HORIZONTAL,
                                      fontname='PT Sans Regular')
        temp_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', '..',
                         'templates', 'template.html'))
        template_file = codecs.open(temp_path, mode='r', encoding='utf-8')
        html_template = Template(template_file.read())
        context = {}

        # TODO: change href attribute in a tag to give link to data display
        tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;">' \
                        '<a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
            left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

        context['tags'] = ''.join(
            [tags_template % link for link in cloud_html['links']])
        context['width'] = cloud_html['size'][0]
        context['height'] = cloud_html['size'][1]
        context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
            a.%(cname)s:hover{color:%(hover)s;}" % {
            'cname': k,
            'normal': v[0],
            'hover': v[1]
        } for k, v in cloud_html['css'].items())
        context['mycss'] = "\
            #word_f { \
            height: 300px; \
            -webkit-column-count: 5; \
            -moz-column-count: 5; \
            column-count: 5; \
            } \
            #word_f li { \
            display: block; \
            }\
            #word_f li a { \
            color: rgb(0, 162, 232); \
            }"

        context['word_freq'] = "".join("<li> %(key)s => %(val)s </li>" % {
            'key': t[0],
            'val': str(t[1])
        } for t in word_freq_tup_list)

        context[
            'page_title'] = 'Search Term : %s - Frequency Based Word Cloud - Top 100 words from search \
            results (length(word) >= 3)' % search_term
        context[
            'list_title'] = '300 features extracted and their corresponding frequencies'
        html_text = html_template.substitute(context)
        return html_text
Ejemplo n.º 3
0
 def test_create_html_data(self):
     """
     HTML code sample
     """
     tags = make_tags(get_tag_counts(self.hound.read())[:100], maxsize=120, colors=COLOR_SCHEMES['audacity'])
     data = create_html_data(tags, (440,600), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')
     
     template_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'web/template.html'), 'r')    
     html_template = Template(template_file.read())
     
     context = {}
     
     tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
     left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'
     
     context['tags'] = ''.join([tags_template % link for link in data['links']])
     context['width'] = data['size'][0]
     context['height'] = data['size'][1]
     context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
     a.%(cname)s:hover{color:%(hover)s;}" % 
                               {'cname':k,
                                'normal': v[0],
                                'hover': v[1]} 
                              for k,v in data['css'].items())
     
     html_text = html_template.substitute(context)
     
     html_file = open(os.path.join(self.test_output, 'cloud.html'), 'w')
     html_file.write(html_text)
     html_file.close()       
Ejemplo n.º 4
0
    def make_cloud(self, output_html):
        keywords = KeywordManager().all()
        text = ' '.join([kw.keyword for kw in keywords])

        if output_html:
            max_tags = 30
            max_size = 42
        else:
            max_tags = 100
            max_size = self.maxsize

        tags = make_tags(get_tag_counts(text)[:max_tags], minsize=self.minsize,
                         maxsize=max_size)

        if output_html:
            size = (900, 300)
            result = create_html_data(tags, size=size,
                                      layout=LAYOUT_HORIZONTAL)
        else:
            #now = datetime.utcnow()
            #filename = 'jcuwords/static/clouds/keyword-cloud-%s.png' % now.isoformat()
            cloud = self.resolver.resolve('jcuwords:keyword-cloud.png')
            filename = cloud.abspath()
            size = (1024, 500)
            create_tag_image(tags, filename, size=size,
                             fontname='IM Fell DW Pica',
                             layout=LAYOUT_MIX)
            image_url = self.request.resource_url(None, 'keyword-cloud.png')
            result = {'image': image_url}

        return result
Ejemplo n.º 5
0
def get_tag_cloud(request, region_code):
    # Get all tweets in the region
    data_zone = DataZone.objects.get(code=region_code)
    tweet_locations = TweetLocation.objects.filter(zone=data_zone)

    body_text = ''

    for x in tweet_locations:
        body_text += x.tweet.body + ' '

    tc = TagCloud()
    body_text = tc.filter_body(body_text)

    if body_text.strip() == '':
        body_text = "Region Empty"

    tags = make_tags(get_tag_counts(body_text)[:50], maxsize=50, colors=COLOR_SCHEMES['audacity'])
    data = create_html_data(tags, (560,450), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')

    context = {}
        
    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
    left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'
    
    context['tags'] = ''.join([tags_template % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = "".join("a.%(cname)s{color:%(normal)s;}a.%(cname)s:hover{color:%(hover)s;}" % {'cname':k, 'normal': v[0], 'hover': v[1]} for k,v in data['css'].items())

    return render_to_response('tag_cloud.html', {'tags': context['tags'], 'css': context['css']})
Ejemplo n.º 6
0
def generate_tag_cloud(tags,outputfile):
    data = create_html_data(tags, size=(900, 600), fontname='Crimson Text', layout=3)

    template_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/template.html'), 'r')
    html_template = Template(template_file.read())

    context = {}

    tags_template = '''
        <li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;">
            <a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx; left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a>
        </li>
    '''

    context['tags'] = ''.join([tags_template.rstrip() % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = '\n'.join("a.%(cname)s{color:%(normal)s;}\
    a.%(cname)s:hover{color:%(hover)s;}" %
                              {'cname':k,
                               'normal': v[0],
                               'hover': v[1]}
                             for k,v in data['css'].items())


    html_text = html_template.substitute(context)

    with codecs.open(outputfile, 'w', encoding='utf-8') as html_file:
        html_file.write(html_text)
def interactive_wordcloud(all_texts):
    '''

    :param all_texts:
    :return:
    '''
    flat_text = []
    for text in all_texts:
        for word in text:
            flat_text.append(word)
    print(flat_text)

    counts = Counter(flat_text).items()
    print(counts)

    sorted_wordscount = sorted(counts, key=lambda tup: tup[
        1])[:200]  # sort and select the top 200 words counts
    print(sorted_wordscount)
    # Running get_tag_counts result in error UnicodeDecodeError: 'charmap' codec can't decode byte 0xaa in position 90: character maps to <undefined>
    # This is because in file stopwords.py, that is called by counter.py (contains code for get_tag_counts), the stopwords are not read in utf-8
    tags = make_tags(sorted_wordscount, maxsize=100)
    print('tags', tags)
    data = create_html_data(tags,
                            size=(1600, 800),
                            layout=LAYOUT_MIX,
                            fontname='Philosopher',
                            rectangular=True)
    print('data', data)

    # ======================================================================================================================
    # Write wordcloud on HTML file
    # ======================================================================================================================

    template_file = open(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     'out/template.html'), 'r')
    html_template = Template(template_file.read())

    context = {}

    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
            left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

    context['tags'] = ''.join([tags_template % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
            a.%(cname)s:hover{color:%(hover)s;}" % {
        'cname': k,
        'normal': v[0],
        'hover': v[1]
    } for k, v in data['css'].items())

    html_text = html_template.substitute(context)

    test_output = os.path.join(os.getcwd(), 'out')
    html_file = open(os.path.join(test_output, 'cloud.html'), 'w')
    html_file.write(html_text)
    html_file.close()
    '''
Ejemplo n.º 8
0
    def test_create_html_data(self):
        """
        HTML code sample
        """
        data = create_html_data(self.tags, size=(600, 400), fontname='fonts/Arial.ttf', fontzoom=3)
        print '\nCSS\n'
        for style in data['css']:
            print style

        print '\nHTML\n'
        for link in data['links']:
            print '<a class="tag %(cls)s" href="#" style="top: %(top)dpx; left: %(left)dpx; font-size: %(size)dpx;">%(tag)s</a>' % link
    def generate_html(self, word_freq_tup_list, search_term):
        """
        this function generates html file depicting word cloud word_freq_tup is passed by the caller
        :param word_freq_tup_list:
        :return: generated word cloud html text
        """
        tags = make_tags(word_freq_tup_list)
        # print tags

        cloud_html = create_html_data(tags[:100], (500, 500), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')
        temp_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', '..', 'templates', 'template.html'))
        template_file = codecs.open(temp_path, mode='r', encoding='utf-8')
        html_template = Template(template_file.read())
        context = {}

        # TODO: change href attribute in a tag to give link to data display
        tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;">' \
                        '<a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
            left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

        context['tags'] = ''.join([tags_template % link for link in cloud_html['links']])
        context['width'] = cloud_html['size'][0]
        context['height'] = cloud_html['size'][1]
        context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
            a.%(cname)s:hover{color:%(hover)s;}" %
                                 {'cname': k,
                                  'normal': v[0],
                                  'hover': v[1]}
                                 for k, v in cloud_html['css'].items())
        context['mycss'] = "\
            #word_f { \
            height: 300px; \
            -webkit-column-count: 5; \
            -moz-column-count: 5; \
            column-count: 5; \
            } \
            #word_f li { \
            display: block; \
            }\
            #word_f li a { \
            color: rgb(0, 162, 232); \
            }"

        context['word_freq'] = "".join(
            "<li> %(key)s => %(val)s </li>" % {'key': t[0], 'val': str(t[1])} for t in word_freq_tup_list)

        context['page_title'] = 'Search Term : %s - Frequency Based Word Cloud - Top 100 words from search \
            results (length(word) >= 3)' % search_term
        context['list_title'] = '300 features extracted and their corresponding frequencies'
        html_text = html_template.substitute(context)
        return html_text
Ejemplo n.º 10
0
def createHtmlData(wors):
	
	auxwords = removeWords(wors)
	
		
	tags = make_tags(get_tag_counts(auxwords)[:20], maxsize=80, colors=COLOR_SCHEMES['oldschool'])

	
	data = create_html_data(tags, (800,600), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')

	tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
	    left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

	return ''.join([tags_template % link for link in data['links']])
Ejemplo n.º 11
0
def createHtmlData(wors):

    auxwords = removeWords(wors)

    tags = make_tags(get_tag_counts(auxwords)[:20],
                     maxsize=80,
                     colors=COLOR_SCHEMES['oldschool'])

    data = create_html_data(tags, (800, 600),
                            layout=LAYOUT_HORIZONTAL,
                            fontname='PT Sans Regular')

    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
	    left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

    return ''.join([tags_template % link for link in data['links']])
Ejemplo n.º 12
0
def create_cloud(sql):
    #p=translate(News2)
    #P=p.News2
    #query = (P.select(P.newsid).where(P.newsdate)==P.select(fn.MAX(P.newsdate)))
    cursor = connection.cursor()
    cursor.execute(sql)
    allterm=cursor.fetchall()
    alltermlist=list(allterm)
    alltermdic={}
    checklist=[]
    while not len(alltermlist) == 0:
        popone=alltermlist.pop()
        key=popone[0]
        value=popone[1]
        checklist.append(key)
        if key in [a[0] for a in checklist]:
            alltermdic[key]+=value
        else:
            alltermdic[key]=value
    swd = sorted(alltermdic.iteritems(), key=itemgetter(1), reverse=True)
    swd = [w for w in swd[1:50]]
    tags = make_tags(swd, maxsize=120)
    data = create_html_data(tags,
                            size=(600, 400),
                            layout=3,
                            fontname="Simhei",
                            rectangular=False)
    from string import Template
    context = {}
    with open('/Users/jojotenya/Documents/Django/News/newsCloud/template.html') as f:
        html_template = Template(f.read())
    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; \
        height: %(height)dpx;"><a class="tag \
        %(cls)s" href="/to_sec/%(tag)s" style="top: %(top)dpx;\
            left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; \
        line-height:%(lh)dpx;">%(tag)s</a></li>'
    context['tags'] = ''.join([tags_template % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
                             a.%(cname)s:hover{color:%(hover)s;}" %
                             {'cname': k,
                              'normal': v[0],
                              'hover': v[1]}
                             for k, v in data['css'].items())
    html_text = html_template.substitute(context)
    return html_text
Ejemplo n.º 13
0
    def _test_create_html_data(self):
        """
        HTML code sample
        """
        tags = make_tags(get_tag_counts(self.hound.read())[:100], maxsize=120, colors=COLOR_SCHEMES['audacity'])
        data, html_text = create_html_data(tags, size=(1280, 900), fontname='Lobster', fontzoom=1)
        
        html_file = open(os.path.join(self.test_output, 'cloud.html'), 'w')
        html_file.write(html_text)
        html_file.close
        
        print '\nCSS\n'
        for style in data['css']:
            print style

        print '\nHTML\n'
        for link in data['links']:
            print '<a class="tag %(cls)s" href="#" style="top: %(top)dpx; left: %(left)dpx; font-size: %(size)dpx;">%(tag)s</a>' % link
Ejemplo n.º 14
0
    def create_html_data(self):
        """
        HTML code sample
        """
        tags = make_tags(get_tag_counts(self.content),
                         maxsize=120,
                         colors=COLOR_SCHEMES['audacity'])
        # FIXME 存在segmentfault bug
        data = create_html_data(tags, (840, 1000),
                                layout=LAYOUT_HORIZONTAL,
                                fontname='PT Sans Regular')

        template_file = open(os.path.join('templates/', 'web/template.html'),
                             'r')
        html_template = Template(template_file.read())
        template_file.close()

        context = {}

        tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
        left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

        context['tags'] = ''.join(
            [tags_template % link for link in data['links']])
        context['width'] = data['size'][0]
        context['height'] = data['size'][1]
        context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
        a.%(cname)s:hover{color:%(hover)s;}" % {
            'cname': k,
            'normal': v[0],
            'hover': v[1]
        } for k, v in data['css'].items())

        html_text = html_template.substitute(context)

        html_file = open('templates/cloud.html', 'w')
        html_file.write(html_text.encode('utf-8'))
        html_file.close()
Ejemplo n.º 15
0
    def _test_create_html_data(self):
        """
        HTML code sample
        """
        tags = make_tags(get_tag_counts(self.hound.read())[:100],
                         maxsize=120,
                         colors=COLOR_SCHEMES['audacity'])
        data, html_text = create_html_data(tags,
                                           size=(1280, 900),
                                           fontname='Lobster',
                                           fontzoom=1)

        html_file = open(os.path.join(self.test_output, 'cloud.html'), 'w')
        html_file.write(html_text)
        html_file.close

        print '\nCSS\n'
        for style in data['css']:
            print style

        print '\nHTML\n'
        for link in data['links']:
            print '<a class="tag %(cls)s" href="#" style="top: %(top)dpx; left: %(left)dpx; font-size: %(size)dpx;">%(tag)s</a>' % link
Ejemplo n.º 16
0
    def test_create_html_data(self):
        """
        HTML code sample
        """
        tags = make_tags(get_tag_counts(self.hound.read())[:100],
                         maxsize=36,
                         colors=COLOR_SCHEMES['goldfish'])
        data = create_html_data(tags, (220, 300),
                                layout=LAYOUT_HORIZONTAL,
                                fontname='PT Sans Regular')

        template_file = open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'web/template.html'), 'r')
        html_template = Template(template_file.read())

        context = {}

        tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="/tag/%(tag)s" style="top: %(top)dpx;\
        left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'

        context['tags'] = ''.join(
            [tags_template % link for link in data['links']])
        context['width'] = data['size'][0]
        context['height'] = data['size'][1]
        context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
        a.%(cname)s:hover{color:%(hover)s;}" % {
            'cname': k,
            'normal': v[0],
            'hover': v[1]
        } for k, v in data['css'].items())

        html_text = html_template.substitute(context)

        html_file = open(os.path.join(self.test_output, 'cloud.html'), 'w')
        html_file.write(html_text)
        html_file.close()
def wordcloud(direc):
    
    text = ""

    with open(direc) as f:
        lines = f.readlines()
        text = "".join(lines)

    words = word_tokenize(text)

    tags = make_tags(get_tag_counts(text), maxsize=90)
    data = create_html_data(tags, (1600,1200), layout = LAYOUT_MIX, fontname='Philiosopher', rectangular=True)

    template_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../corpus/'), 'r')    
    html_template = Template(template_file.read())
     
    context = {}
     
    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
    left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'
     
    context['tags'] = ''.join([tags_template % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
    a.%(cname)s:hover{color:%(hover)s;}" %
                              {'cname':k,
                               'normal': v[0],
                               'hover': v[1]} 
                             for k,v in data['css'].items())
     
    html_text = html_template.substitute(context)
     
    html_file = open(os.path.join(self.test_output, 'cloud.html'), 'w')
    html_file.write(html_text)
    html_file.close() 
Ejemplo n.º 18
0
upon those not infrequent occasions when he was up all night, was seated
at the breakfast table. I stood upon the hearth-rug and picked up the
stick which our visitor had left behind him the night before. It was a
fine, thick piece of wood, bulbous-headed, of the sort which is known as
a "Penang lawyer." Just under the head was a broad silver band nearly
an inch across. "To James Mortimer, M.R.C.S., from his friends of the
C.C.H.," was engraved upon it, with the date "1884." It was just such a
stick as the old-fashioned family practitioner used to carry--dignified,
solid, and reassuring.
'''

tags = make_tags(
    get_tag_counts(text, maxsize=120, colors=COLOR_SCHEMES['audacity']))

data = create_html_data(tags, (440, 600),
                        layout=LAYOUT_HORIZONTAL,
                        fontname='PT Sans Regular')

template_file = open(
    os.path.join(os.path.dirname(os.path.abspath(__file__)),
                 'web/template.html'), 'r')
html_template = Template('''
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; utf-8">
<title>PyTagCloud</title>
<style type="text/css">
body{
background-color: black;
}
Ejemplo n.º 19
0
Mr. Sherlock Holmes, who was usually very late in the mornings, save
upon those not infrequent occasions when he was up all night, was seated
at the breakfast table. I stood upon the hearth-rug and picked up the
stick which our visitor had left behind him the night before. It was a
fine, thick piece of wood, bulbous-headed, of the sort which is known as
a "Penang lawyer." Just under the head was a broad silver band nearly
an inch across. "To James Mortimer, M.R.C.S., from his friends of the
C.C.H.," was engraved upon it, with the date "1884." It was just such a
stick as the old-fashioned family practitioner used to carry--dignified,
solid, and reassuring.
'''


tags = make_tags(get_tag_counts(text, maxsize=120, colors=COLOR_SCHEMES['audacity']))
                 
data = create_html_data(tags, (440,600), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')
        
template_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'web/template.html'), 'r')
html_template = Template('''
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; utf-8">
<title>PyTagCloud</title>
<style type="text/css">
body{
background-color: black;
}

@font-face {
font-family: 'PTSans';
src: url('../webfonts/ptsans/pt_sans-web-regular-webfont-2.eot');
def print_user_htmltagclouds(list_usernames,path):

    file_ = open('data/personomies_extended')
    tag_t_cloud = []
    tag_fr_cloud = []
    tag_cloud_tags = []
    tag_d_cloud = []
    tag_sum = 0.0
    tas_sum = 0.0
    old_usernameprint = ''
    sum_clouds = 0
    sum_clouds_not = 0
    for line in file_:
        row = line.strip('\n').split(' ')
        freq = float(row[0])
        new_username = row[1]
        tag = row[2]
        if not(row[3] == 'None'): tag_fu = float(row[3])
        else: tag_fu = None
        if not(row[4] == 'None'): tag_fr = float(row[4])
        else: tag_fr = None
        if not(row[5] == 'None'): tag_d = float(row[5])
        else: tag_d = None
        if not(row[6] == 'None'): tag_eu = float(row[6])
        else: tag_eu = None
        if not(row[7] == 'None'): tag_t = float(row[7])
        else:
            tag_t = None
        if new_username in list_usernames:
            if (new_username == old_username) or (old_username == ''):
                tas_sum += freq
                tag_sum += 1.0
                #if not(tag_fr == None): tag_fr_cloud.append((tag,tag_fr*freq))
                #if not(tag_d == None): tag_d_cloud.append((tag,tag_d*freq))
                #if not(tag_eu == None): tag_eu_sum.append(tag_eu*freq)
                if not(tag_t == None): tag_t_cloud.append((tag,tag_t*freq))
                tag_cloud_tags.append((tag,freq))
                old_usernameprint = old_username
            else:
                if not(tag_cloud_tags == []) and (len(tag_cloud_tags)>1) and tag_sum < PRINT_TAG_THRESHOLD:
                    sum_clouds += 1
                    if sum_clouds > PRINT_CLOUDS: break
                    tags_adjusted = []
                    sum_ = 0.0
                    for pair in tag_cloud_tags:
                        print pair
                        tags_adjusted.append((pair[0].replace('%20',' '),pair[1]))
                        sum_ += pair[1]
                    if not(sum_ == len(tags_adjusted)):
                        tags = make_tags(tags_adjusted)
                        for layout in LAYOUTS:
                            data, html_text = create_html_data(tags, size=(600, 500), fontname='Lobster', fontzoom=1)
                            html_file = open(path+'tagcloud_'+str(old_usernameprint)+'_'+'10'+'.html', 'w')
                            html_file.write(html_text)
                            html_file.close()
                else: sum_clouds_not += 1
                tag_sum = 1.0
                #tag_t_cloud = [(tag,tag_t*freq)]
                #tag_fr_cloud = [(tag,tag_fr*freq)]
                #tag_d_cloud = [(tag,tag_d*freq)]
                if not(tag_t == None): tag_cloud_tags = [(tag,freq)]
                else: tag_cloud_tags = []
                old_usernameprint = new_username
        old_username = new_username

    print 'Number of clouds printed:',sum_clouds,' and number of users dropped:',sum_clouds_not