1#!/usr/bin/env python 2 3import os, subprocess, time, datetime 4import config 5 6# current date and time 7datetime = datetime.datetime.now() 8current_date = "%.2d.%.2d.%.4d" % (datetime.day, datetime.month, datetime.year) 9current_time = "%.2d:%.2d:%.2d" % (datetime.hour, datetime.minute, datetime.second) 10 11# if music was stopped, resume again 12if os.path.exists(config.mpd_lockfile) == True: 13 os.remove(config.mpd_lockfile) 14 subprocess.call(["mpc", "-h", config.mpd_host, "-p", str(config.mpd_port), "play"]) 15 16# try to get the caller name / id from the previously created temp file 17try: 18 caller_id_file = open(config.caller_id_filename, "r") 19 caller_id = caller_id_file.read().strip() 20 caller_id_file.close() 21except: 22 caller_id = "anonymous" 23if config.language == "de": 24 message = "Anruf von %s am %s um %s\n" % (caller_id, current_date, current_time) 25else: 26 message = "Call of %s in %s at %s\n" % (caller_id, current_date, current_time) 27try: 28 os.remove(config.caller_id_filename) 29except: 30 pass 31 32# log into file 33log = open(config.call_log_file, "a") 34log.write(message) 35log.close() 36 37