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    with open(config.caller_id_filename, "r") as caller_id_file:
19        caller_id = caller_id_file.read().strip()
20except:
21    caller_id = "anonymous"
22if config.language == "de":
23    message = "Anruf in Abwesenheit von %s am %s um %s\n" % (caller_id, current_date, current_time)
24else:
25    message = "Call in absence of %s in %s at %s\n" % (caller_id, current_date, current_time)
26try:
27    os.remove(config.caller_id_filename)
28except:
29    pass
30
31# log into file
32with open(config.call_log_file, "a") as log:
33    log.write(message)
34