Exemplo n.º 1
0
def initial_load():
    """
    Loads the past 61 days of data into the user's database document. If a day already exists then it will be overwritten.
    This should only be ran on creation of the user's database object (their initial login).
    :return: None
    """

    db_user = db.find_one({'username': session['username']
                           })  # pulls session user from the database
    print(db_user)

    mfp_client = Client(username=session['username'],
                        password=db_user['password']
                        )  # creates a MFP client from the database credentials
    nutrition_user = Nutrition.User(
        mfp_client)  # creates a Nutrition User with the MFP client

    today = date.today()
    end = date.today() - timedelta(
        days=61)  # remember to change this to 61 after testing

    while today >= end:
        db.update_one(
            {'username': session.get('username')},
            {'$set': {
                ('data.' + str(end)): nutrition_user.get_day(end)
            }})
        print('Added ' + str(end) + ' to ' + db_user['username'] +
              ' meal database.')
        end += timedelta(days=1)
Exemplo n.º 2
0
def smart_load():
    """
    Loops through the past 61 days in the user's database, and if a day is missing then it will get added, otherwise no
    action will be taken. This should be run on every login to ensure the most recent data is loaded.
    :return: None
    """

    today = date.today()
    end = date.today() - timedelta(
        days=1)  # remember to change this to 61 after development
    db_user = db.find_one({'username': session['username']
                           })  # links to the current user's database
    mfp_client = Client(username=session['username'],
                        password=db_user['password']
                        )  # creates a MFP client from the database credentials
    nutrition_user = Nutrition.User(
        mfp_client)  # creates a Nutrition User with the MFP client

    while today >= end:

        try:  # see if a day exists in the database
            day = db_user['data'][str(end)]
            print(str(end) + ' is loaded.')

        except KeyError:  # if the day has not been loaded
            print(str(end) + ' is missing - updating now...')
            db.update_one(
                {'username': session.get('username')},
                {'$set': {
                    ('data.' + str(end)): nutrition_user.get_day(end)
                }})

        end += timedelta(days=1)  # increment the day
Exemplo n.º 3
0
 def setUp(self):
     self.arbitrary_username = '******'
     self.arbitrary_password = '******'
     self.arbitrary_date = datetime.date(2013, 3, 2)
     self.client = Client(self.arbitrary_username,
                          self.arbitrary_password,
                          login=False)
     super(TestClient, self).setUp()
Exemplo n.º 4
0
 def setUp(self):
     self.arbitrary_username = "******"
     self.arbitrary_password = "******"
     self.arbitrary_date1 = datetime.date(2015, 4, 20)
     self.arbitrary_date2 = datetime.date(2015, 4, 28)
     self.client = Client(self.arbitrary_username,
                          self.arbitrary_password,
                          login=False)
     super().setUp()
Exemplo n.º 5
0
def handler(event, context):
    client = Client('*****@*****.**', 'MFP4180')
    print(event)
    _id = client.get_food_search_results(
        event['queryStringParameters']['query'])[0].mfp_id
    item = client.get_food_item_details(_id)
    x = vars(item)
    x.popitem()
    return {'statusCode': 200, 'body': json.dumps(x)}
Exemplo n.º 6
0
    def setUpClass(cls):
        try:
            username = os.environ["MFP_INTEGRATION_TESTING_USERNAME"]
            password = os.environ["MFP_INTEGRATION_TESTING_PASSWORD"]
        except KeyError:
            pytest.skip("Integration testing account not set in this environment.")
            return

        cls.client = Client(username, password,)

        day_with_known_entries = datetime.date(2020, 7, 4)

        cls.day = cls.client.get_date(day_with_known_entries)
Exemplo n.º 7
0
def login():
    """
    Route for the login page. Will validate credentials on POST, and redirect to / on GET. If credentials are valid
    user will get redirected to /app and if invalid redirected to /.
    :return: A redirect to / or app
    """

    if request.method == 'GET':  # if they navigate to /login they get redirected to /
        return redirect('/')
    else:
        print(request.form)
        inputted_username = request.form['username']
        inputted_password = request.form['password']

        try:  # validate login - look for a better way to test if login is valid
            mfp_client = Client(username=inputted_username,
                                password=inputted_password)

        except ValueError:  # invalid login
            print('invalid login')
            return redirect('/')

        print('valid login')
        existing_user = db.find_one({'username': inputted_username})

        if existing_user is None:  # initializes user - full user initialization will take place in this block
            db.insert({
                "username": inputted_username,
                'password': inputted_password,
                'valid_value': 1000
            })
            print('Created the user: '******'username': inputted_username}))
        else:
            print(inputted_username + ' already exists in the database.')

            if existing_user[
                    'password'] != inputted_password:  # updating their password if it's changed
                db.update_one({'username': inputted_username},
                              {'$set': {
                                  'password': inputted_password
                              }})

        session[
            'username'] = inputted_username  #adding their username to the session
        print(session)
        return redirect('/app')
Exemplo n.º 8
0
from myfitnesspal import Client
import json

client = Client('*****@*****.**', 'MFP4180')
_id = client.get_food_search_results("thin mints girl scout")[0].mfp_id
item = client.get_food_item_details(_id)
x = vars(item)
x.popitem()
print(x)
print(json.dumps(x))