想作一个python模块库,自己时时调用。
文件层级结构
~/bin:
---pylib pybin
~bin/pylib:
---notify __init__.py
~bin//pybin:
---ct_weather.py
~/bin/pylib/notify
---ct_notifyGTK.py __init__.py
~bin/pylib/__init__.py
import notify
__all__ = ['notify']~/bin/pylib/notify/__init__.py
import ct_notifyGTK
__all__ = ['ct_notifyGTK']
ct_notifyGTK.py
import gtk
import pynotify
notification = 0
def callback(icon):
notification.show()
def ct_notify(title, body, timeout = pynotify.EXPIRES_NEVER, type = 'notype'):
pynotify.init(title)
global notification
notification = pynotify.Notification(title, body, type)
notification.set_urgency(pynotify.URGENCY_NORMAL)
notification.set_timeout(timeout)
icon = gtk.status_icon_new_from_stock(gtk.STOCK_ABOUT)
icon.connect('activate', callback)
notification.attach_to_status_icon(icon)
gtk.main()
if __name__ == '__main__':
ct_notify('weather', 'rain/n3oC')
#import sys
#sys.path.append('/home/ct/bin/pylib')
from notify import ct_notifyGTK
from urllib import urlopen
import re
p = re.compile('<[^>]+>')
def ct_getweather(url = /
"http://www.weather.com.cn/wap/weather/101010100.shtml"):
'''
ct_getweather: return the encoded in utf8 texts represents weather
condition.
No description.
'''
sock = urlopen(url)
htmlsource = sock.read()
sock.close()
content = p.sub("", htmlsource)
content = '/n'.join(content.split()[1:12])
return content.decode('utf8')
#------end of ct_getweather() --------------------------------------------------
if __name__ == '__main__':
weather = ct_getweather()
ct_notifyGTK.ct_notify('Weather In Beijing', weather)
#!/bin/bash
echo "export PYTHONPATH=~/bin/pylib" >> ~/.bashrc