"""This is the main executable of the provider job. Gets the data from the sources and upserts into the DCM. """ import logging import toggl, db, habitica from datetime import date, timedelta from time import sleep DATE_RANGE = 3 LOG_DIR = './logs/provider_' LOG_DATE = str(date.today().isoformat().replace('-', '')) LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' logging.basicConfig(filename=LOG_DIR + LOG_DATE + '.log', level=logging.DEBUG, format=LOG_FORMAT) logging.info("****************** Starting a new provider run ******************") for DateDelta in range(DATE_RANGE): date_to_sync = date.today()-timedelta(days=DateDelta) currently_in_toggl = toggl.get_data(date_to_sync) currently_in_dcm = db.get_toggl_dcm_datapoint(date_to_sync) if not currently_in_dcm: db.insert_toggl_dcm(date_to_sync, currently_in_toggl) elif currently_in_toggl != currently_in_dcm[0]: db.update_toggl_dcm(date_to_sync, currently_in_toggl) sleep(2) # horrible hack; as it turns out I can't just get the data grouped per day for a date range # and there is a limit of 1 API call per second in Toggl
import bm, toggl, db, habitica from datetime import date DEBUG = False # set to True not to insert or update anything in Beeminder LOG_DIR = "./logs/" LOG_DATE = str(date.today().isoformat().replace("-", "")) LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" logging.basicConfig(filename=LOG_DIR + LOG_DATE + ".log", level=logging.DEBUG, format=LOG_FORMAT) logging.info("****************** Starting a new run ******************") TODAY = date.today() TOGGL_DATA = toggl.get_data(TODAY) logging.debug("Today's data from toggl: " + str(TOGGL_DATA)) # add: is the toggl data different than last time? if TOGGL_DATA != 0: BM = bm.BeemAPI("togglproductivity2015") DATAPOINT_ID = db.load_dp_id(TODAY, "togglproductivity2015") # we don't have a datapoint id for the day, insert needed if DATAPOINT_ID is None: logging.debug("datapoint_id is None. Will insert into bm.") NEW_DATAPOINT_ID = BM.insert(data=TOGGL_DATA, debug=DEBUG) db.write_dp_id(NEW_DATAPOINT_ID, TODAY, "togglproductivity2015") # we have a datapoint id, update
from datetime import date DEBUG = False # set to True not to insert or update anything in Beeminder LOG_DIR = './logs/' LOG_DATE = str(date.today().isoformat().replace('-', '')) LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' logging.basicConfig(filename=LOG_DIR + LOG_DATE + '.log', level=logging.DEBUG, format=LOG_FORMAT) logging.info("****************** Starting a new run ******************") TODAY = date.today() TOGGL_DATA = toggl.get_data(TODAY) logging.debug("Today's data from toggl: " + str(TOGGL_DATA)) # add: is the toggl data different than last time? if TOGGL_DATA != 0: BM = bm.BeemAPI() DATAPOINT_ID = db.load_dp_id(TODAY) # not in the file? maybe there already is a datapoint in BM? # if DATAPOINT_ID is None: # logging.debug("No DP in the file, let's check in BM.") # BM_DATA = BM.get_data(TODAY) # if BM_DATA is not None: # logging.debug('BM returned id: ' + str(BM_DATA.id))