from recover.models import *
from recover.patient_data import *
from datetime import date

def midnightRun():
    physicians = User.objects()
    for physician in physicians:
        patients = physician.patients
        for patient in patients:
            data = PatientData(patient)
            last_synced = patient.date_last_synced.isoformat()
            last_synced = last_synced[0:10]
            data.get_heart_rate_data_for_date_range(last_synced)
            data.get_activity_data_for_date_range(last_synced)

@@ -61,22 +61,8 @@
 t *%0A
-from datetime 
 impo
@@ -68,16 +68,21 @@
 ort date
+time%0A
 %0A%0Adef mi
@@ -485,28 +485,91 @@
 for_date_range(last_synced)%0A
+            patient.date_last_synced = datetime.datetime.now()%0A

Update 'date_last_synced' field on each patient after midnight fetching