Using Python to implement the command line alarm script instance _python

Source: Internet
Author: User
Tags numeric value

Objective:

This article describes how to create a simple alarm with Python, it can run at the command line terminal, it takes minutes as command-line arguments, the "wake-up" message is printed this minute, and the bell alarms, you can test it in 0 minutes, it will execute immediately, Use the Speaker Control Panel to adjust the sound.

Here's the script:

# alarm_clock.py # description:a Simple Python, the computer Act # like a alarm clock. Start it running from "command line" # with a command line argument specifying the duration in minutes # after which T o Sound the alarm. It'll sleep for this long, # and then beep a few times.
 
Use a duration of 0 to test the # alarm immediiately, e.g. for checking this volume is okay. # author:vasudev ram-http://www.dancingbison.com Import sys import string from time import sleep sa = sys.argv LSA = Len (SYS.ARGV) if LSA!= 2:print "Usage: [Python] alarm_clock.py duration_in_minutes" print "Example: [Python] A
  larm_clock.py "Print" use a value of 0 minutes for testing the alarm immediately.
  Print "Beeps a few times after the duration are over."
  Print "Press Ctrl-c to terminate the alarm clock early." Sys.exit (1) try:minutes = Int (sa[1]) except Valueerror:print "Invalid numeric value (%s) for minutes"% sa[1] pr int "Should is an intEger >= 0 "sys.exit (1) If minutes < 0:print" Invalid value for minutes, should is >= 0 "sys.exit (1) SE 
    Conds = minutes * if minutes = = 1:unit_word = "Minute" Else:unit_word = "minutes" Try:if minutes > 0: print ' Sleeping for ' + str (minutes) + Unit_word sleep (seconds) print ' Wake up ' for I in Range (5): Print Chr (7), sleep (1) except Keyboardinterrupt:print "interrupted by user" Sys.exit (1) # EOF

Summarize:

This script I work already in use, very practical, of course, to avoid affecting other colleagues work, you'd better bring headphones, if the request is not high, in fact, printed from the terminal "wake-up" message is enough to remind. The above is the entire content of this article, I hope that the study and work can bring some help, if you have questions you can message exchange. Thank you for your support to the cloud-dwelling community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.