Last active
December 17, 2015 07:39
-
-
Save mengzhuo/5574722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*-s | |
''' | |
File: bigben.py | |
Author: Meng Zhuo <[email protected]> | |
Description: 大笨钟 | |
''' | |
import time | |
import logging | |
import threading | |
from datetime import datetime | |
#initial | |
logging.basicConfig(level=logging.DEBUG, | |
format="%(asctime)-15s[%(levelname)-8s]%(message)s") | |
logger = logging.getLogger('BigBen') | |
HOUR_SECONDS = 3600 | |
def big_ben(): | |
logger.info("Dang " * int(datetime.now().strftime("%I"))) | |
residuals = time.time() % HOUR_SECONDS | |
threading.Timer(HOUR_SECONDS-residuals, big_ben).start() | |
def main(): | |
logger.debug('Big Ben is runing...') | |
time.sleep(HOUR_SECONDS - time.time() % HOUR_SECONDS) | |
big_ben() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment