web service 动手玩儿

最近工作中需要用的web service的一些数据调用,本生是php调用.net的需求。顺便就查了下python怎样用。如下: 例子中的 1电话是网上随便搜索的一个标注为诈骗号码的电话。 2web service是网上随便搜索的一个源。 本例用的是suds的一个lib 安装很简单不赘述了。 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me from suds.client import Client def websevice(phone): url = ‘http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl’ c = Client(url) r = c.service.getMobileCodeInfo(phone) #print client可以直接查看有哪些方法可以调用 return r def main(): phone_number = ‘13802792784’ r = websevice(phone_number) print r if __name__ == “__main__”: main()

count.workdays.py

没事儿写个脚本工作日以及周末的统计 可输出相对应的日期号数. #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me #date:2013-12-15 import datetime from calendar import monthrange def get_year(): return str(datetime.date.today())[:4] def get_month(): return str(datetime.date.today())[5:7] def get_day(): return str(datetime.date.today())[-2:] def get_weekenddays_and_businessdays(year, month): i = 1 weekenddays = [] businessdays = [] already_work_days = [] count_days = monthrange(year, month) if (year, month) == (int(get_year()), int(get_month())): currentday = int(get_day()) else: currentday = […]

about the order of Class in python

#!/usr/bin/python2 class A(object): print ‘in A class…’ def __init__(self): print ‘-‘ * 20 print ‘init ‘, self.__class__.__name__,’ calss…’ print ‘Created Class:’, self.__class__.__name__ print ‘out ‘, self.__class__.__name__,’A calss…’ print ‘-‘ * 20 print ‘out A class…’ class B(A): print ‘in B class…’ class C(B): print ‘in B class…’ class D(B, A): print ‘in D class…’ a […]

scandir.py

#!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me import sys import os def scandir(p): try: items = os.listdir(p) except OSError: print ‘OSError, Could not Open dir: %s’ % p exit(1) for element in items: fullpath = p + ‘/’ + element if os.path.isdir(fullpath): scandir(fullpath) print fullpath def main(): if len(sys.argv) == 2: path = sys.argv[1] print ‘path is: %s’ % […]

track.package.py 0.2

update:修改了一下输出样式,增加地点的输出 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me #date: 2013-11-21 from bs4 import BeautifulSoup import urllib2 import sys def main(): if len(sys.argv) != 2: print “Need a track number” exit(1) track_number = sys.argv[1] track_date = [] track_location = [] headers = { ‘User-Agent’ : ‘Mozilla/5.0’ } url = “https://tools.usps.com/go/TrackConfirmAction!input.action?tRef=qt&tLc=1&tLabels=” + track_number req = urllib2.Request(url, None, headers) htmltext = urllib2.urlopen(req).read() […]

track.package.py 追踪USPS货运单

今天朋友告诉我说终于把手机给我寄了,但是用的是USPS的first class,我的个天,只有看自己人品好不好了。写了个抓取进度的脚本。很简单。 遇到一些问题刚开始两个list循环如下: for info,date in infos, dates: print “%s @ %s” % (info.text, ‘ ‘.join(date.text.split())) 会失败报错ValueError: too many values to unpack 想了下可以直接用index指定输出内容呀!(真傻还想了一会儿才想到)于是该了一下成这样 for i in range(len(track_date)): print “%s @ %s” % (track_info[i].text,track_date[i]) 这里重要的是track_info[i].text里的.text 才会提取内容,不然html的tag都一并输出了这就不友好了。 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me #date: 2013-11-21 from bs4 import BeautifulSoup import urllib2 import sys def main(): if len(sys.argv) != 2: print […]

python之timer0.3

想了想应该用参数的话更好些加入getopt包 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me #version 0.3 #date 2013-10-20 from time import sleep from progressbar import ETA,ProgressBar,Bar, Percentage import getopt import sys class timer: def __init__(self, sec): self.sec = sec def main(self, sec): widgets = [Bar(‘>’), Percentage(), ” “, ETA()] pbar = ProgressBar(widgets=widgets, maxval=(self.sec+1)*10).start() for i in range(1,(self.sec+1)*10): sleep(0.1) pbar.update(i+1) pbar.finish() def start(self): self.main(self) def USAGE(): […]

python之timer0.2

想了想能不能不换行再加上进度条呢,于是在google上搜了一阵还真有这个包 在这里 再封装一下 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me #version 0.2 #date 2013-10-20 from time import sleep from progressbar import ETA,ProgressBar,Bar, Percentage class timer: def __init__(self, sec=10): self.sec = sec def main(self, sec): widgets = [Bar(‘>’), Percentage(), ” “, ETA()] pbar = ProgressBar(widgets=widgets, maxval=(self.sec+1)*10).start() for i in range(1,self.sec*10): sleep(0.1) pbar.update(i+1) pbar.finish() def start(self): self.main(self) if __name__ == “__main__”: […]

python之timer

坐那感觉心跳厉害想测一下心率写了个定时很简单 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me #version 0.1 #date 2013-11-20 from time import sleep def main(): for i in range(1,60): print i sleep(1) if __name__ == “__main__”: main()

pyrename with getopt

这是第三个版本加入了参数选项 #!/usr/bin/python2 #auth:codewalker #mail:001@codewalker.me version = 0.3 from sys import argv, exit from os import rename, listdir, getcwd import re import getopt def usage(): print “USAGE:%s oldpart newpart” % argv[0] print ”’ -v|–verbose verbose -V|–version show version -h|–help show this ”’ def main(): try: opts, args = getopt.getopt(argv[1:], “hvV”, [“help”, “verbose”,”version”]) except getopt.GetoptError, e: print […]