-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
50 lines (42 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import logging
import os.path
import time
from inspect import getsourcefile
from threading import Thread
from config import FITBIT_SYNC_ENABLED, LOG_LOCATION, DATETIME_FORMAT
from fitbit_sync import webserver, weight_sync
from wii_fit_bt_weight_tracker import tracker
def main():
# Setup logging
base_file = os.path.abspath(getsourcefile(lambda: 0))
base_file_location = base_file[:len(base_file)-7]
log_location = os.path.join(base_file_location, LOG_LOCATION)
logging.basicConfig(filename=log_location, filemode='a', format='%(asctime)s %(message)s', datefmt=DATETIME_FORMAT,
level=logging.INFO)
try:
# Start Bluetooth tracking thread
bt_thread = Thread(name="[WiiFitBoardBit] BT Tracking", target=tracker.main)
bt_thread.setDaemon(True)
bt_thread.start()
if FITBIT_SYNC_ENABLED:
# Start FitBit authentication Flask webserver thread
flask_thread = Thread(name="[WiiFitBoardBit] FitBit Authentication Web Server", target=webserver.main)
flask_thread.setDaemon(True)
flask_thread.start()
# Start FitBit weight synchronisation thread
sync_thread = Thread(name="[WiiFitBoardBit] FitBit OAuth2 Weight Synchronisation", target=weight_sync.main)
sync_thread.setDaemon(True)
sync_thread.start()
else:
logging.info("FitBit synchronisation is disabled. Authentication web server and weight synchronisation "
"threads were not started")
while True:
time.sleep(5)
except KeyboardInterrupt:
logging.info("Stopping due to Keyboard Interrupt event")
logging.shutdown()
print("Exiting")
exit(0)
if __name__ == "__main__":
main()