from dateutil import parser as dp
from dateutil import tz
from flask import request, jsonify

import database
from models import Activities


def create_activity(token_info):

    data = request.get_json()

    start = dp.isoparse(data["activity_start"]).astimezone(tz.UTC)
    end = dp.isoparse(data["activity_end"]).astimezone(tz.UTC)

    new_activities = Activities(
        name=data["name"],
        user_id=token_info["public_id"],
        activity_start=start,
        activity_end=end,
        category_id=data["category_id"],
    )
    database.db_session.add(new_activities)
    database.db_session.commit()

    return jsonify({"message": "new activity record created"})


def get_user_activities(token_info):

    activities = Activities.query.filter_by(user_id=token_info["public_id"]).all()

    output = []
    for activity in activities:

        activity_data = {}
        activity_data["name"] = activity.name
        activity_data["activity_start"] = activity.activity_start
        activity_data["activity_end"] = activity.activity_end
        activity_data["category_id"] = activity.category_id
        output.append(activity_data)

    return jsonify({"activities": output})

c6524124937692bd6b6909aa0d258ea6f1fd028c
<mask token>

<mask token>


def get_user_activities(token_info):
    activities = Activities.query.filter_by(user_id=token_info['public_id']
        ).all()
    output = []
    for activity in activities:
        activity_data = {}
        activity_data['name'] = activity.name
        activity_data['activity_start'] = activity.activity_start
        activity_data['activity_end'] = activity.activity_end
        activity_data['category_id'] = activity.category_id
        output.append(activity_data)
    return jsonify({'activities': output})

<mask token>


def create_activity(token_info):
    data = request.get_json()
    start = dp.isoparse(data['activity_start']).astimezone(tz.UTC)
    end = dp.isoparse(data['activity_end']).astimezone(tz.UTC)
    new_activities = Activities(name=data['name'], user_id=token_info[
        'public_id'], activity_start=start, activity_end=end, category_id=
        data['category_id'])
    database.db_session.add(new_activities)
    database.db_session.commit()
    return jsonify({'message': 'new activity record created'})


def get_user_activities(token_info):
    activities = Activities.query.filter_by(user_id=token_info['public_id']
        ).all()
    output = []
    for activity in activities:
        activity_data = {}
        activity_data['name'] = activity.name
        activity_data['activity_start'] = activity.activity_start
        activity_data['activity_end'] = activity.activity_end
        activity_data['category_id'] = activity.category_id
        output.append(activity_data)
    return jsonify({'activities': output})

from dateutil import parser as dp
from dateutil import tz
from flask import request, jsonify
import database
from models import Activities


def create_activity(token_info):
    data = request.get_json()
    start = dp.isoparse(data['activity_start']).astimezone(tz.UTC)
    end = dp.isoparse(data['activity_end']).astimezone(tz.UTC)
    new_activities = Activities(name=data['name'], user_id=token_info[
        'public_id'], activity_start=start, activity_end=end, category_id=
        data['category_id'])
    database.db_session.add(new_activities)
    database.db_session.commit()
    return jsonify({'message': 'new activity record created'})


def get_user_activities(token_info):
    activities = Activities.query.filter_by(user_id=token_info['public_id']
        ).all()
    output = []
    for activity in activities:
        activity_data = {}
        activity_data['name'] = activity.name
        activity_data['activity_start'] = activity.activity_start
        activity_data['activity_end'] = activity.activity_end
        activity_data['category_id'] = activity.category_id
        output.append(activity_data)
    return jsonify({'activities': output})

from dateutil import parser as dp
from dateutil import tz
from flask import request, jsonify

import database
from models import Activities


def create_activity(token_info):

    data = request.get_json()

    start = dp.isoparse(data["activity_start"]).astimezone(tz.UTC)
    end = dp.isoparse(data["activity_end"]).astimezone(tz.UTC)

    new_activities = Activities(
        name=data["name"],
        user_id=token_info["public_id"],
        activity_start=start,
        activity_end=end,
        category_id=data["category_id"],
    )
    database.db_session.add(new_activities)
    database.db_session.commit()

    return jsonify({"message": "new activity record created"})


def get_user_activities(token_info):

    activities = Activities.query.filter_by(user_id=token_info["public_id"]).all()

    output = []
    for activity in activities:

        activity_data = {}
        activity_data["name"] = activity.name
        activity_data["activity_start"] = activity.activity_start
        activity_data["activity_end"] = activity.activity_end
        activity_data["category_id"] = activity.category_id
        output.append(activity_data)

    return jsonify({"activities": output})
