2005年09月28日 星期三 22:47
这个是用twisted的task来作, 随便把ipython放到里面, 这样还可以当ipython用. # -*- coding: utf-8 -*- from IPython.Shell import IPShellEmbed args = ['-pi1','In <\\#>:','-pi2',' <file://%23%3E:','-pi2','/>.\\D.:','-po','Out< \\#>:','-nosep' <file://%23%3E:','-nosep'/>] ipshell = IPShellEmbed(args) ipshell.set_exit_msg('Ctrl-C to exit program') ipshell.set_banner('Ctrl-D to exit interpreter and continue program') from twisted.internet import reactor, threads, task shell = threads.deferToThread(ipshell) #打开ipython player = task.LoopingCall(play_soundfile) #这里是你要打开的程序 player.start(60*30) #每1800秒播放一次 #可以用 player.stop() 来中止 reactor.run() On 9/27/05, Kai <kai0001 at 163.com> wrote: > > 为了避免连续长时间看电脑,能让可怜的眼睛休息一下,我凑合出这个python程序(完全新手啊,汗,大伙给改改。而且还缺少unix上的播放命令)。 > > 每次一开机,我就让它一直运行,每过60分钟,它就随机选一首曲子播放,提醒歇会,看个三级写真照片什么的。 > > #!/usr/bin/python > # -*- coding: gb2312 -*- > > import sys > import time > import random > import os > > directory = 'c:\\downloads\\music' # 歌曲文件夹 > > def play_soundfile(filename): # 启动播放器 > if sys.platform == 'win32': > import win32api > win32api.ShellExecute(0, "open", filename, None, "", 0) > else: > print "some *nix commands here to play a sound file" # 需要加上在unix 上播放的命令 > > fileList = [os.path.join(directory, os.path.normcase(f)) for f in > os.listdir(directory)] # get a list of all music files > > while 1: > print "--------------------------------------" > > fileName = random.choice(fileList) > print fileName > > play_soundfile(fileName) > > time.sleep(1800) > print '30 minutes have passed. ', time.strftime("%a, %d %b %Y %H:%M:%S > +0000", time.localtime()) > time.sleep(1800) > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050928/c2164e3f/attachment.htm
2005年09月29日 星期四 12:38
不错的东西。要能加上一点图形界面就更好了
Zeuux © 2025
京ICP备05028076号