@app.route('/api/v1/acts', methods=['POST'])
def upload_act():
    global count_requests
    count_requests += 1
    if (request.method == 'POST'):
        if (not os.path.exists(DB)):
            os.makedirs(DB, exist_ok=True)
        request_data = json.loads(request.data.decode('utf-8'))
        if (not (GLOBAL_LIST in os.listdir())):
            data = pd.DataFrame(columns=['act_id', 'category'])
            data.to_csv(GLOBAL_LIST, index=False)
        if (not (LOGIN_FILE_NAME in os.listdir())):
            data = pd.DataFrame(columns=['username', 'password'])
            data.to_csv(LOGIN_FILE_NAME, index=False)
        data_acts = pd.read_csv(GLOBAL_LIST)
        header = {'origin': INSTANCE_IP}
        resp = r.get((('http://' + IP) + '/api/v1/users'), '{}', headers=header)
        print('=============')
        print(resp.text)
        print('=============')
        data_users = eval(resp.text)
        if ((request_data['username'] not in data_users) or (request_data['actId'] in data_acts['act_id'].tolist())):
            return Response('{}', status=400, mimetype='application/json')
        if ('upvotes' in request_data.keys()):
            return Response('{}', status=400, mimetype='application/json')
        request_data['upvotes'] = 0
        if (request_data['categoryName'] not in os.listdir(DB)):
            return Response('{}', status=400, mimetype='application/json')
        if (not validate(request_data['timestamp'])):
            return Response('{}', status=400, mimetype='application/json')
        try:
            base64.b64decode(request_data['imgB64'])
        except binascii.Error:
            return Response('{}', status=400, mimetype='application/json')
        data_acts = data_acts.append({'act_id': int(request_data['actId']), 'category': request_data['categoryName']}, ignore_index=True)
        data_acts.to_csv(GLOBAL_LIST, index=False)
        with open((((((DB + '/') + request_data['categoryName']) + '/') + str(request_data['actId'])) + '.png'), 'wb') as fp:
            fp.write(base64.decodebytes(request_data['imgB64'].encode()))
        temp_path = ((((DB + '/') + request_data['categoryName']) + '/') + GLOBAL_LIST)
        if (not (GLOBAL_LIST in os.listdir(((DB + '/') + request_data['categoryName'])))):
            data = pd.DataFrame(columns=list(request_data.keys()))
            data.to_csv(temp_path, index=False)
        data = pd.read_csv(temp_path)
        data = data.append(request_data, ignore_index=True)
        data.to_csv(temp_path, index=False)
        return Response('{}', status=201, mimetype='application/json')
    else:
        return Response('{}', status=405, mimetype='application/json')
@app.route('/api/v1/acts', methods=['POST'])
def upload_act():
    global count_requests
    count_requests += 1
    if (request.method == 'POST'):
        if (not os.path.exists(DB)):
            os.makedirs(DB, exist_ok=True)
        request_data = json.loads(request.data.decode('utf-8'))
        if (not (GLOBAL_LIST in os.listdir())):
            data = pd.DataFrame(columns=['act_id', 'category'])
            data.to_csv(GLOBAL_LIST, index=False)
        if (not (LOGIN_FILE_NAME in os.listdir())):
            data = pd.DataFrame(columns=['username', 'password'])
            data.to_csv(LOGIN_FILE_NAME, index=False)
        data_acts = pd.read_csv(GLOBAL_LIST)
        header = {'origin': INSTANCE_IP}
        resp = r.get((('http://' + IP) + '/api/v1/users'), '{}', headers=header)
        print('=============')
        print(resp.text)
        print('=============')
        data_users = eval(resp.text)
        if ((request_data['username'] not in data_users) or (request_data['actId'] in data_acts['act_id'].tolist())):
            return Response('{}', status=400, mimetype='application/json')
        if ('upvotes' in request_data.keys()):
            return Response('{}', status=400, mimetype='application/json')
        request_data['upvotes'] = 0
        if (request_data['categoryName'] not in os.listdir(DB)):
            return Response('{}', status=400, mimetype='application/json')
        if (not validate(request_data['timestamp'])):
            return Response('{}', status=400, mimetype='application/json')
        try:
            base64.b64decode(request_data['imgB64'])
        except binascii.Error:
            return Response('{}', status=400, mimetype='application/json')
        data_acts = data_acts.append({'act_id': int(request_data['actId']), 'category': request_data['categoryName']}, ignore_index=True)
        data_acts.to_csv(GLOBAL_LIST, index=False)
        with open((((((DB + '/') + request_data['categoryName']) + '/') + str(request_data['actId'])) + '.png'), 'wb') as fp:
            fp.write(base64.decodebytes(request_data['imgB64'].encode()))
        temp_path = ((((DB + '/') + request_data['categoryName']) + '/') + GLOBAL_LIST)
        if (not (GLOBAL_LIST in os.listdir(((DB + '/') + request_data['categoryName'])))):
            data = pd.DataFrame(columns=list(request_data.keys()))
            data.to_csv(temp_path, index=False)
        data = pd.read_csv(temp_path)
        data = data.append(request_data, ignore_index=True)
        data.to_csv(temp_path, index=False)
        return Response('{}', status=201, mimetype='application/json')
    else:
        return Response('{}', status=405, mimetype='application/json')