LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-25-2004, 11:08 PM   #1
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Rep: Reputation: 45
Question python script


Hi all

I am interested in making a python script which would after the specified interval of time play a midi file.

It's like an alarm clock but the only catch is that I want it to keep repeating after say every 15 minute or so.

So, if I run the script, it plays that file(the alarm sound) after every 15 minutes.

Guide me ppl. May the forces be with you.

 
Old 03-26-2004, 02:57 AM   #2
rkef
Member
 
Registered: Mar 2004
Location: bursa
Posts: 110

Rep: Reputation: 15
$ man crontab

It is the standard tool for doing such things, and I think you'll like it once you get the hang of the syntax.

'at' is also excellent for one-time scheduling (which I realize you're not doing here, but it's still good to know):
Code:
$ at now + 30 min <enter>
at> _
Otherwise, if you insist on Python, you can do something like (note: I'm a Perlmonkey when it comes to scripting, so it's pseudo-code and I'm assuming Python has a sleep function; possibly as an add-on module(?)):
Code:
while (1) {
    midiplayer /path/to/music.midi;
    sleep 60*15;
}
I don't know what program is good for playing .midis, but I assume there are tens if not hundreds

HTH.

Last edited by rkef; 03-26-2004 at 03:14 AM.
 
Old 03-26-2004, 06:04 AM   #3
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
Hey, thanks rkef.

I'll still try it first in Python and then in Perl. So maybe I'll get back with my hiccups.

Cheers.
 
Old 03-27-2004, 01:23 AM   #4
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
It'd be a great help if someone out here can give me a step-by-step to doing this.
 
Old 03-27-2004, 01:47 AM   #5
rkef
Member
 
Registered: Mar 2004
Location: bursa
Posts: 110

Rep: Reputation: 15
What distro are you using? Check if you have a crond process running.
 
Old 03-29-2004, 04:43 AM   #6
yuray
Member
 
Registered: Apr 2003
Location: Russia, Khotkovo
Distribution: Debian
Posts: 146

Rep: Reputation: 15
Something like this
Code:
#!/usr/bin/python
import os
import time
 
while(1):
        time.sleep(15)
        os.system("pmidi my.mid")
 
Old 03-29-2004, 09:35 AM   #7
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
I'll see and then I'll get back.
 
Old 03-30-2004, 01:51 AM   #8
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
Hi.

I am using RH 9. Could this be possible if I wish to play an mp3 or a wav file instead of just midi.
 
Old 03-30-2004, 06:39 PM   #9
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
change the double quoted text in this line : os.system("pmidi my.mid")
to execute anything you want.
 
Old 04-05-2004, 02:12 AM   #10
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
Ok. So I have RH9 and still getting nowhere.

I have checked and crond services are running. Kindly guide me in making this script.
 
Old 04-05-2004, 06:07 PM   #11
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Code:
#!/usr/bin/python
import os
import time
 
while(1):
        time.sleep(15)
        os.system("mpeg123 my_mp3.mp3")
Now save the file as my_file.py and run it as so: python my_file.py

Enjoy!
 
Old 04-06-2004, 05:15 AM   #12
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
Please sort this out for me. When I type at the console
kmidi abc.mid
it says

Xlib: extension "GLX" missing on display ":0.0".
/dev/dsp doesn't support 4096-byte buffer fragments

But it starts playing.

But when I run the python script it says

Xlib: extension "GLX" missing on display ":0.0".
/dev/dsp doesn't support 4096-byte buffer fragments
Kmidi:Problem with PIPE_INT_WRITE due to:Broken pipe
Xlib: extension "GLX" missing on display ":0.0".
/dev/dsp doesn't support 4096-byte buffer fragments

It opens up kmidi but dies not play the file, WHY?
 
Old 04-06-2004, 05:17 AM   #13
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
I also realised that I could not specify the path to the midi file in the script so I moved the file to he directory where the script is.
 
Old 04-06-2004, 09:33 PM   #14
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
<bump>...
 
Old 04-07-2004, 06:19 AM   #15
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Original Poster
Rep: Reputation: 45
Hi all. I got it. Thanks for your time and support.

Thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
Help with small Python Script cmfarley19 Programming 8 05-02-2005 08:10 AM
how do I do this in Python? (simple sh script) johnMG Programming 6 12-22-2004 10:05 PM
can anyone help me pl with this eror i a python script safrout Programming 0 08-03-2004 02:38 AM
Anyone have a HelloWorld Python Qt script? SheldonPlankton Programming 1 07-22-2004 02:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration