首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python兑现iteye博客归档的条形图

2012-08-29 
python实现iteye博客归档的条形图iteye博客中的归档只是简单的日期数量统计,查看自己写博客情况不是很直观

python实现iteye博客归档的条形图

iteye博客中的归档只是简单的日期数量统计,查看自己写博客情况不是很直观,一直都想他们都有一个这样的功能,结果一直都没有,加上自己最近学了一点python就自己实现了(python刚入门好多东西不懂),不过如果iteye也能实现自己添加插件的功能,这样我这个功能也能是一个插件(自己yy)。

先看效果:


python兑现iteye博客归档的条形图


python兑现iteye博客归档的条形图
?下面贴代码:

?

?

import urllibimport urllib2import reimport reportlaburl = 'http://xiaoshenge.iteye.com/blog/monthblog_more'user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'headers = { 'User-Agent' : user_agent }request = urllib2.Request(url, '', headers)response = urllib2.urlopen(request)html = response.read()p = re.compile('<li><a href="/blog/monthblog/(.*?)">.*</a> \((.*?)\)</li>')datas = []for date,total in p.findall(html):    data = (date,int(total))    datas.append(data)import sysimport cairoimport pycha.linesurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 800, 600)dataSet = (    ('lines', [(i, l[1]) for i, l in enumerate(datas)]),)options = {    'axis': {        'x': {            'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(datas)],        },        'y': {            'tickCount': len(datas),        },        'background': {            'name': 'gradient',            'args': {'initialColor': 'blue',},        },        'legend': {'hide': True,},        'padding': {'left': 55,'bottom': 40,}    }}chart = pycha.line.LineChart(surface,options)chart.addDataset(dataSet)chart.render()surface.write_to_png('test.png')

热点排行