Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note field was causing an error on data collection from diabetes-m #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions getdata.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from secret import USERNAME, PASSWORD, NS_URL, NS_SECRET
import requests, json, arrow, hashlib, urllib, datetime
import cloudscraper
import cloudscraper, sys, os


DBM_HOST = 'https://analytics.diabetes-m.com'

# this is the enteredBy field saved to Nightscout
NS_AUTHOR = "Diabetes-M (dm2nsc)"

# Disable
def blockPrint():
sys.stdout = open(os.devnull, 'w')

# Restore
def enablePrint():
sys.stdout = sys.__stdout__


def get_login():
sess = cloudscraper.create_scraper(
Expand Down Expand Up @@ -51,11 +59,17 @@ def to_mgdl(mmol):

def convert_nightscout(entries, start_time=None):
out = []
# next line silences the output of the gathered records to the screen
blockPrint()
for entry in entries:
print(' '.join(map(str, entries)))
bolus = entry["carb_bolus"] + entry["correction_bolus"]
time = arrow.get(int(entry["entry_time"])/1000).to(entry["timezone"])
notes = entry["notes"]

# next if block added to compensate for errors related to empty notes
if dict["notes"]:
notes = 'DBM-Source'
else:
notes = entry["notes"]
if start_time and start_time >= time:
continue

Expand Down Expand Up @@ -96,7 +110,8 @@ def convert_nightscout(entries, start_time=None):
dat.update(bgEvent)

out.append(dat)

# next line renables console output
enablePrint()
return out

def upload_nightscout(ns_format):
Expand Down
11 changes: 6 additions & 5 deletions secret.py-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rename this file to `secret.py`
USERNAME = '<diabetes-m username>'
PASSWORD = '<diabetes-m password>'
NS_URL = 'http://your-nightscout-host-with-trailing-slash/'
NS_SECRET = 'nightscout-secret-key'
# rename this file to `secret.py`
USERNAME = '<diabetes-m username>'
PASSWORD = '<diabetes-m password>'
NS_URL = 'http://your-nightscout-host-with-trailing-slash/'
NS_SECRET = 'nightscout-secret-key'