Differences between revisions 1 and 2
Revision 1 as of 2005-09-28 01:41:36
Size: 1501
Editor: ZoomQuiet
Comment:
Revision 2 as of 2005-09-28 16:00:42
Size: 1675
Editor: Kev
Comment:
Deletions are marked like this. Additions are marked like this.
Line 45: Line 45:

"""
goopler said: To be able to import win32api, one needs to "要安装win32all包。这里有:
http://starship.python.net/crew/mhammond/win32/Downloads.html"
"""

2005-09-28 "土制闹钟"

{{{发件人: Kai <[email protected]> 回复: [email protected] 收件人: "[email protected]" <[email protected]> 日期: 2005-9-27 下午11:48 主题: [python-chinese] 我的土制闹钟 }}} 为了避免连续长时间看电脑,能让可怜的眼睛休息一下,我凑合出这个python程序(完全新手啊,汗,大伙给改改。而且还缺少unix上的播放命令)。

每次一开机,我就让它一直运行,每过60分钟,它就随机选一首曲子播放,提醒歇会,看个三级写真照片什么的。

   1 #!/usr/bin/python
   2 # -*- coding: gb2312 -*-
   3 
   4 import sys
   5 import time
   6 import random
   7 import os
   8 
   9 directory = 'c:\\downloads\\music'  # 歌曲文件夹
  10 
  11 def play_soundfile(filename):  # 启动播放器
  12    if sys.platform == 'win32':
  13        import win32api
  14        win32api.ShellExecute(0, "open", filename, None, "", 0)
  15    else:
  16        print "some *nix commands here to play a sound file" # 需要加上在unix 上播放的命令
  17 
  18 fileList =  [os.path.join(directory, os.path.normcase(f)) for f in os.listdir(directory)]  # get a list of all music files
  19 
  20 while 1:
  21    print "--------------------------------------"
  22 
  23    fileName = random.choice(fileList)
  24    print fileName
  25 
  26    play_soundfile(fileName)
  27 
  28    time.sleep(1800)
  29    print '30 minutes have passed. ', time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())
  30    time.sleep(1800)

""" goopler said: To be able to import win32api, one needs to "要安装win32all包。这里有: http://starship.python.net/crew/mhammond/win32/Downloads.html" """

MicroProj/2005-09-28 (last edited 2009-12-25 07:19:15 by localhost)