GithubHelp home page GithubHelp logo

lanjelin / cronometerpy Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 56 KB

Python Library for generating json for importing to Cronometer foods

License: GNU General Public License v3.0

Python 100.00%

cronometerpy's Introduction

CronometerPy

Code style: black

Python Library for generating json for importing to Cronometer foods.

Import the makeJsonDict()-function from crono_json.py, and give it at least a name for the food, and a list of dictionaries containing the nutriends. It will return a dictionary you can use directly with json.dump.

import json
from crono_json import makeJsonDict
from cronopy import CronoPy

name = "TINE Helmelk 3,5 % fett 1 liter"
nutrients = [
    {"id": 208, "amount": 63.0},
    {"id": 204, "amount": 3.5},
    {"id": 606, "amount": 2.3},
    {"id": 205, "amount": 4.5},
    {"id": 269, "amount": 4.5},
    {"id": 203, "amount": 3.4},
    {"id": 307, "amount": 40.0},
]
crono_json_dict = makeJsonDict(name, nutrients)

# Save as json
with open(f"fancy_name.json", "w") as outfile:
    json.dump(crono_json_dict, outfile)

# Directly save to cronometer custom foods
# so far it requires, and only supports 
# name, nutrients, barcodes(only first), notes and source
barcodes = ["07038010000065"]
notes = "Allergens: Milk"
source = "CronoPy"
crono_json_dict = makeJsonDict(
    name, nutrients, notes=notes, barcodes=barcodes, source=source
)
cron = CronoPy()
msg, error = cron.Login(username, password)
if error:
    raise SystemExit(msg)
else:
    print(msg)
msg, error = cron.importCustomFood(crono_json_dict)
if error:
   print(f"Error: {msg}")
else:
   print(msg)
msg, error = cron.Logout()
print(msg)

For a complete example with all the variables, take a look at example.py, it's output is available in example.json

The file example_minimal.json contains the minimal amount of information required by Cronometer to accept the json-file.

crono_dict.py contains all the variables I've been able to pull, and is required by crono_json.py.

Go make something fancy!

cronometerpy's People

Contributors

lanjelin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.