Skip to content

Instantly share code, notes, and snippets.

@mengzhuo
Last active December 17, 2015 07:39
Show Gist options
  • Save mengzhuo/5574722 to your computer and use it in GitHub Desktop.
Save mengzhuo/5574722 to your computer and use it in GitHub Desktop.
# -*- 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