def getMetricData(self): apiAuthorizationHeaders = {'Authorization' : 'Bearer ' + self.userAuthorizationToken.encode('ascii', 'ignore') } userJawboneData = requests.get('https://jawbone.com/nudge/api/v.1.1/users/@me/moves', headers = apiAuthorizationHeaders) userJawboneDay = json.loads(userJawboneData.text)['data']['items'][0] userJawboneSteps = 0 currentDate = getFormattedTime("%Y%m%d") if (str(userJawboneDay['date']) == currentDate): userJawboneSteps = userJawboneSteps + userJawboneDay['details']['steps'] return userJawboneSteps
def writeData(givenUser, userDataBase): userMetricsList = givenUser['metrics'] givenUserName = givenUser['username'] for metric in userMetricsList: dbInsertObject = { "date" : eval(getFormattedTime("%Y%m%d")), "username" : givenUserName, "metric" : metric} dbMetricCollection = userDataBase[metric] dbMetricCollection.remove(dbInsertObject) if userMetricsList[metric]['source'] == 'file': filePath = userMetricsList[metric]['path'][0] + givenUserName + '/' + userMetricsList[metric]['path'][1] fileData = "" if userMetricsList[metric]['format'][0] == 'percentage': fileDataObject = standard.singleNumberLib(filePath) fileData = fileDataObject.getFileData() elif userMetricsList[metric]['format'][0] == 'graph': fileDataObject = standard.multipleNumberLib(filePath) fileData = fileDataObject.getFileData() elif userMetricsList[metric]['format'][0] == 'raw': fileDataObject = standard.rawFileLib(filePath) fileData = fileDataObject.getFileData() elif userMetricsList[metric]['format'][0] == 'picture': fileDataObject = standard.pictureFileLib(filePath) fileData = fileDataObject.getFileData() if fileData == None: fileData = "" dbInsertObject['value'] = fileData elif userMetricsList[metric]['source'] == 'custom': customData = "" if userMetricsList[metric]['type'] == 'jawbone': customDataObject = custom.jawboneLib(userMetricsList[metric]['auth']) customData = customDataObject.getMetricData() elif userMetricsList[metric]['type'] == 'weather': customDataObject = custom.weatherLib(userMetricsList[metric]['location']) customData = customDataObject.getMetricData() if customDataObject == None: customData = "" dbInsertObject['value'] = customData dbMetricCollection.insert(dbInsertObject) print "Data inserted."
def writeAllUserData(databaseUserCollection, userDataBase): autoWriteDataLogHandler = open("auto.log", "a") for currentUser in databaseUserCollection.find(): autoWriteDataLogHandler.write("Logging data for " + currentUser['username'] + " on " + getFormattedTime("%Y%m%d") + " at " + getFormattedTime("%H:%M:%S") + ".\n") writeData(currentUser, userDataBase) autoWriteDataLogHandler.close()