博客统计信息

51cto推荐博客
用户名:阿汐
文章数:57
评论数:67
访问量:73088
无忧币:4163
博客积分:1524
博客等级:5
注册日期:2008-06-04

我最近发表的评论

一个准程序员的20.. 回复
程序员还是能找到女朋友的,别听人..
“.中国”域名获.. 回复
争面子,圈地盘,我们所谓的创新性在..
LGPL与闭源程序 回复
很有实际意义,好文章。
利用pysvn 获取SV.. 回复
wing免费版http://www.wingware.com..
JAVA之痛 回复
说得好,一辆性能优越的跑车却安装..
我的操作系统是win7 64bit,平时一直用的是python2.5.4的版本,因为今天需要用到python读取mysql数据库,不过网络上没有支持python2.5.4的64bit mysql包版本。所以换了python2.6,反正只是临时解决方案,写完程序之后还会换回来的。然后在使用过程中遇到一些问题。

先列一下软件下载的地址
python2.6 64bit下载:http://www.python.org/ftp/python/2.6/python-2.6.amd64.msi
MySQL-python-1.2.2.win-amd64-py2.6:http://www.codegood.com/download/3/


先后安装完毕之后,先打开IDEL准备测试一下
import MySQLdb

import MySQLdb

Traceback (most recent call last):
    File "<pyshell#0>", line 1, in <module>
        import MySQLdb
    File "C:\Python26\Lib\site-packages\MySQLdb\__init__.py", line 34, in <module>
        from sets import ImmutableSet
    File "C:\Python26\Lib\sets.py", line 85, in <module>
        stacklevel=2)
&..
类别:Python|阅读(547)|回复(0)|(0)阅读全文>>
CSRF(跨站请求伪造),django 1.2.1在projects的setting中默认配置了处理CSRF的中间件 'django.middleware.csrf.CsrfViewMiddleware',

因此,如果post提交表单的html代码如下,django会抛出一个异常.
CSRF token missing or incorrect.
类别:Python|阅读(1676)|回复(1)|(0)阅读全文>>
Advanced Directory Synchronization module
来源地址:http://snipperize.todayclose.com/snippet/py/Advanced-Directory-Synchronization-module--143151/
""" pyrobocopy.py -      Version: 1.0          Report the difference in content     of two directories, synchronize or     update a directory from another, taking     into account time-stamps of files etc.      By Anand B Pillai       (This program is inspired by the windows     'Robocopy' program.)      Mod  Nov 11 Rewrote to use the filecmp module. ..
类别:Python|阅读(397)|回复(0)|(0)阅读全文>>
python获取当前日期前后N天或N月的日期
来源地址:http://snipperize.todayclose.com/snippet/py/python%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%A5%E6%9C%9F%E5%89%8D%E5%90%8EN%E5%A4%A9%E6%88%96N%E6%9C%88%E7%9A%84%E6%97%A5%E6%9C%9F--97049/
#!/usr/bin/python ''''' Filename: "utildate.py" author:   "zhangsong" date  :   "2009-03-24" version:  "1.00" ''' from time import strftime, localtime from datetime import timedelta, date import calendar   year = strftime("%Y",localtime()) mon  = strftime("%m",localtime()) day  = strftime("%d",localtime()) hour = strftime("%H",localtime()) min  = strftime("%M",localtime()) sec  = strftime("%S",..
类别:Python|阅读(1422)|回复(0)|(0)阅读全文>>
判断某个字符是否为中文
来源地址:http://snipperize.todayclose.com/snippet/py/%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E4%B8%AD%E6%96%87%E5%AD%97%E7%AC%A6--4021/
""" 判断unicode码是否为中文字符. """ def is_cn_char(i):     return 0x4e00<=ord(i)<0x9fa6  def is_cn_or_en(i):     o = ord(i)     return o<128 or 0x4e00<=o<0x9fa6 
 
类别:Python|阅读(537)|回复(0)|(0)阅读全文>>
Console (text) progress indicator class
来源地址:http://snipperize.todayclose.com/snippet/py/Console-%28text%29-progress-indicator-class--14253/
class progressbarClass:      def __init__(self, finalcount, progresschar=None):         import sys         self.finalcount=finalcount         self.blockcount=0         #         # See if caller passed me a character to use on the         # progress bar (like "*").  If not use the block         # character that makes it look like ..
类别:Python|阅读(372)|回复(0)|(0)阅读全文>>
Django code highlight template filter
来源地址:http://snipperize.todayclose.com/snippet/py/Django-code-highlight-template-filter--24910/
from pygments import highlight from pygments.lexers import get_lexer_by_name, PhpLexer from pygments.formatters import HtmlFormatter from pygments.util import ClassNotFound   @register.filter def highlight_code(code, lang):   if code is not None:     try:       # startinline is for PhpLexer so that it doesn't       # require a <?php       lexer = get_lexer_by_name(lang, encoding='utf-8', stripall=True, startinline=True)     except ClassNotFound:   &nb..
类别:Python|阅读(134)|回复(0)|(0)阅读全文>>
Console Make Text Color and Bold
来源地址:http://snipperize.todayclose.com/snippet/py/Console-Make-Text-Color-and-Bold--596002/
def color(t, c):         return chr(0x1b)+"["+str(c)+"m"+t+chr(0x1b)+"[0m" def black(t):         return color(t, 30) def red(t):         return color(t, 31) def green(t):         return color(t, 32) def yellow(t):         return color(t, 33) def blue(t):         return color(t, 34) def mangenta(t):         return color(t, 35) def cyan(t):      &..
制作Shell下面的进度条
来源地址:http://snipperize.todayclose.com/snippet/py/%E5%88%B6%E4%BD%9CShell%E4%B8%8B%E9%9D%A2%E7%9A%84%E8%BF%9B%E5%BA%A6%E6%9D%A1--33351/
def _flushWid2info(self):         self._sql = "select count(*) as total from test"         total = self._mysql.findOne(self._sql)['total']   #找到总数                 self._mysql.freeResult()         self._sql = "select * from test"         self._mysql.query(self._sql)         _tmp = self._mysql.findNext()         i = 0.0    &n..
类别:Python|阅读(117)|回复(0)|(0)阅读全文>>
 
来源:http://snipperize.todayclose.com/snippet/py/Send-email-with-attachment--53762/
Send email with attachment
import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.Utils import COMMASPACE, formatdate from email import Encoders import os  def sendMail(to, subject, text, files=[],server="localhost"):     assert type(to)==list     assert type(files)==list     fro = "Expediteur <expediteur@mail.com>"      msg = MIMEMultipart()     msg['From'] = fro     msg['To'] = COMMASPACE.join(to)    &n..
类别:Python|阅读(547)|回复(0)|(0)阅读全文>>
2010-04-05 01:25:35
我现在的感觉是,写blog,首先是一种生活习惯,其次,时间上一定要宽裕。就像我加入的很多讨论组,QQ群,有10%的活跃用户就很了不起了。 剩下的人干嘛去了呢? 忙啊,实在是太忙,忙剩下的时间总想好好休息,或者快速的浏览一些新闻,资讯,就躺下睡觉了。
大概从去年7,8月份,我写blog的时间就越来越少了,之前是因为时间充裕,工作进度也安排的不够紧凑,学到很多新东西,都可以在闲暇之余写下来,然而等项目真正启动之后,也许我学到了更多的东西,也有更多的心得体会,但是,总是没有时间和精力去记录了。甚至在日常的电子邮件,即时聊天工具上,几乎永远的消失了我的踪迹。
这大半年的时间,在技术上,学到了不少新的东西,也在团队的带动下,养成了更多良好的工作习惯,每一次新的功能开发时,设计代码之初,总会考虑很久,迟迟不会动手,人确实是学得越多,看得越多才知道自己越渺小,越不值一提。
2009年本来有2,3个个人项目的开发计划。
一个cms,设计初衷是为了更好的融合行业客户的需求,简化操作流程。
一个心情记录的微博客,用图表分析,内容分析的方式来记录一个人,一周,一个月,一年,一段长久的日子里的心路历程,对自己走过的这段路有一个总结..
开发中遇到一个需求,随手做个记录.

需要用到pysvn的lib
下载地址:http://pysvn.tigris.org/project_downloads.html


#! /usr/bin/env python
#coding=utf-8
import pysvn
import datetime

client = pysvn.Client()
entry = client.info('本地代码库项目路径')

print u'SVN路径:',entry.url
print u'最新版本:',entry.commit_revision.number
print u'提交人员:',entry.commit_author
print u'更新日期:', datetime.datetime.fromtimestamp(entry.commit_time)

类别:Python|阅读(405)|回复(1)|(0)阅读全文>>
2009-08-30 02:41:15
在看文档的时候一直觉得django的表单设计是很酷的东西,今天花了点时间研究一下,掌握的还不多,不过已经能实现不少的东西,当然是在编写极少代码的情况下。不然研究它的表单就没有意义了。

我目前使用的Django版本是1.1 beta.所以是继承于forms来实现的表单系统
 from django import forms

第一步:首先在models.py中定义一个表单模型

class RemarkForm(forms.Form):
        subject = forms.CharField(max_length=100 ,label='留言标题')
        mail = forms.EmailField(label='电子邮件')
        topic = forms.ChoiceField(choices=TOPIC_CHOICES,label='选择评分')  
        message = forms.CharField(label='留言内容',widget=forms.Textarea)
        cc_myself = forms.BooleanField(required=False ,label='订阅该贴')
那个topic中的choices需要在models.py中定义一个数组.
TOPIC_CHOICES = (
        ('leve1', '差评'),
        ('leve2', '中评'),
类别:Python|阅读(1631)|回复(3)|(0)阅读全文>>
晚上无事看到了自己在51cto的blog个人信息,于是准备用python试试把它们抓取出来显示到程序里,顺便练练手。对正则式不是很熟,所以字符串解析基本是用python的字符串操作函数库来完成的。

其实原理也很简单,就是从互联网下载博客首页到内存里(保存为文件再读取也是一样),然后查找到<div class="side_sinfo"> 这个字符串,我分析HTML文件得来的,从这个地方开始,一步一步的解析,最后结果就出来了。

照例看看预览,直接在控制台完成的:




以下是代码. python2.5下编译通过
#coding=gbk
import urllib,re
from urllib import urlopen
if __name__=="__main__":
        blogUrl=raw_input('请输51cto的blog地址:')
        #下载网页到内存
        webdata = urlopen(blogUrl).read()
        #标签特征开始位置
        nPosStart = webdata.find('博客统计信息')
        #标签特征结束位置
        nPosEnd     = webdata.find('注册日期:')
        #分割内容,+24是为了补全部分html
        userInfoStr = webdata[nPosStart:nPosEnd+24]


        nPosStart2 = userInfoStr.find('用户名')
        userInfoStr = userInfoStr[nPosStart2:nPosEnd+24]
        #清除部分标签
        userInfoStr = userInfoStr.replace('<div class="side_sinfo">','')
        userInfoStr = userInfoStr.replace('<a href="http://51ctoblog.blog.51cto.com/26414/5591" target="_blank" style="text-decoration: underline;">','')
        userInfoStr = userInfoStr.replace('</a>','')
        #清除换行
        userInfoStr = userInfoStr.replace('\n','')
        #清除空格
        userInfoStr = userInfoStr.replace(' ','')
        #按<br>拆分信息
        userInfoStr = userInfoStr.split('<br>')
        print "博客个人信息查询:"
        print "================="
        #循环输出
        for userInfo in userInfoStr:
                print userInfo
修改了一下,支持在程序里反复查询

#coding=gbk
import urllib,re
from urllib import urlopen
def searchbloginfo(url):
        #下载网页到内存
        webdata = urlopen(blogUrl).read()
        #标签特征开始位置
        nPosStart = webdata.find('博客统计信息')
        #标签特征结束位置
        nPosEnd     = webdata.find('注册日期:')
        #分割内容,+24是为了补全部分html
        userInfoStr = webdata[nPosStart:nPosEnd+24]


        nPosStart2 = userInfoStr.find('用户名')
        userInfoStr = userInfoStr[nPosStart2:nPosEnd+24]
        #清除部分标签
        userInfoStr = userInfoStr.replace('<div class="side_sinfo">','')
        userInfoStr = userInfoStr.replace('<a href="http://51ctoblog.blog.51cto.com/26414/5591" target="_blank" style="text-decoration: underline;">','')
        userInfoStr = userInfoStr.replace('</a>','')
        #清除换行
        userInfoStr = userInfoStr.replace('\n','')
        #清除空格
        userInfoStr = userInfoStr.replace(' ','')
        #按<br>拆分信息
        userInfoStr = userInfoStr.split('<br>')
        print "博客个人信息查询:"
        print "================="
        #循环输出
        for userInfo in userInfoStr:
                print userInfo

if __name__=="__main__":
        running = True
        while running:
                blogUrl = raw_input('请输51cto的blog地址--输入0结束程序:')
                if cmp(blogUrl , '0') == 0:
                        running = False
                else:
                        searchbloginfo(blogUrl)
[/img]..
2009-08-15 01:45:58
wxImage::AddHandler(new wxBMPHandler);
                wxScreenDC DC;
                wxSize screenSize = wxGetDisplaySize();
 <<   1   2   3   4   >>   页数 ( 1/4 )