LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python script (https://www.linuxquestions.org/questions/programming-9/python-script-162483/)

LinuxLala 03-25-2004 11:08 PM

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.

:D

rkef 03-26-2004 02:57 AM

$ 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.

LinuxLala 03-26-2004 06:04 AM

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.

LinuxLala 03-27-2004 01:23 AM

It'd be a great help if someone out here can give me a step-by-step to doing this.

rkef 03-27-2004 01:47 AM

What distro are you using? Check if you have a crond process running.

yuray 03-29-2004 04:43 AM

Something like this
Code:

#!/usr/bin/python
import os
import time
 
while(1):
        time.sleep(15)
        os.system("pmidi my.mid")


LinuxLala 03-29-2004 09:35 AM

I'll see and then I'll get back.

LinuxLala 03-30-2004 01:51 AM

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.

kooch 03-30-2004 06:39 PM

change the double quoted text in this line : os.system("pmidi my.mid")
to execute anything you want.

LinuxLala 04-05-2004 02:12 AM

Ok. So I have RH9 and still getting nowhere.

I have checked and crond services are running. Kindly guide me in making this script.

The_Nerd 04-05-2004 06:07 PM

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!

LinuxLala 04-06-2004 05:15 AM

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?

LinuxLala 04-06-2004 05:17 AM

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.

LinuxLala 04-06-2004 09:33 PM

<bump>...

LinuxLala 04-07-2004 06:19 AM

Hi all. I got it. Thanks for your time and support.

Thank you.


All times are GMT -5. The time now is 03:47 PM.