def update_volunteer_info(*args, **kwargs): v_id = request.form.get('volunteer_id') name = request.form.get('name') mob_number = request.form.get('mob_number') email_id = request.form.get('email_id') address = request.form.get('address') geoaddress = request.form.get('geoaddress', address) latitude = request.form.get('latitude') longitude = request.form.get('longitude') source = request.form.get('source') status = request.form.get('status') country = request.form.get('country') req_dict = { 'name': name, 'mob_number': mob_number, 'email_id': email_id, 'country': country, 'address': address, 'geoaddress': geoaddress, 'latitude': latitude, 'longitude': longitude, 'source': source, 'status': status } v_df = volunteer_data_by_id(v_id) if (v_df.shape[0] == 0): return json.dumps({ 'status': False, 'string_response': 'Volunteer does not exist', 'Response': {} }) if (v_id is None): return { 'Response': {}, 'status': False, 'string_response': 'Volunteer ID mandatory' } v_dict = {x: req_dict[x] for x in req_dict if req_dict[x] is not None} response = json.dumps(update_volunteers_db({'id': v_id}, v_dict)) return response
def auto_assign_volunteer(): v_id = request.form.get('volunteer_id') uuid = request.form.get('uuid') matching_by = 'autoassigned' task_action = request.form.get('task_action') r_df = request_data_by_uuid(uuid) v_df = volunteer_data_by_id(v_id) if (r_df.shape[0] == 0): return json.dumps({ 'status': False, 'string_response': 'Request ID does not exist.', 'Response': {} }) if (v_df.shape[0] == 0): return json.dumps({ 'status': False, 'string_response': 'Volunteer does not exist', 'Response': {} }) else: r_id = r_df.loc[0, 'r_id'] if (((r_df.loc[0, 'status'] == 'received') or (r_df.loc[0, 'status'] == 'verified') or (r_df.loc[0, 'status'] == 'pending')) & (task_action == 'accepted')): current_time = dt.datetime.utcnow() + dt.timedelta(minutes=330) req_dict = { 'volunteer_id': [v_id], 'request_id': [r_id], 'matching_by': [matching_by], 'timestamp': [current_time] } df = pd.DataFrame(req_dict) response = request_matching(df) response_2 = update_requests_db({'id': r_id}, {'status': 'matched'}) response_3 = update_nearby_volunteers_db({'r_id': r_id}, {'status': 'expired'}) #Move to message_templates.py file #Send to Volunteer v_sms_text = '[COVID SOS] Thank you agreeing to help. Name:' + r_df.loc[ 0, 'name'] + ' Mob:' + str( r_df.loc[0, 'mob_number']) + ' Request:' + r_df.loc[ 0, 'request'] + ' Address:' + r_df.loc[0, 'geoaddress'] send_sms(v_sms_text, int(v_df.loc[0, 'mob_number']), sms_type='transactional', send=True) #Send to Requestor v_sms_text = '[COVID SOS] Volunteer ' + v_df.loc[ 0, 'name'] + ' will help you. Mob: ' + str( v_df.loc[0, 'mob_number']) send_sms(v_sms_text, int(r_df.loc[0, 'mob_number']), sms_type='transactional', send=True) return json.dumps(response) elif ((r_df.loc[0, 'status'] == 'received') or (r_df.loc[0, 'status'] == 'verified') or (r_df.loc[0, 'status'] == 'pending')): response_3 = update_nearby_volunteers_db( { 'r_id': r_id, 'v_id': v_id }, {'status': 'expired'}) return json.dumps({ 'status': True, 'string_response': 'Request rejected', 'Response': {} }) else: return json.dumps({ 'status': False, 'string_response': 'Request already assigned', 'Response': {} })
def assign_request_to_volunteer(volunteer_id, request_id, matched_by): r_df = request_data_by_id(request_id) v_df = volunteer_data_by_id(volunteer_id) if (r_df.shape[0] == 0): return { 'status': False, 'string_response': 'Request ID does not exist.', 'Response': {} } if (v_df.shape[0] == 0): return { 'status': False, 'string_response': 'Volunteer does not exist', 'Response': {} } else: if (r_df.loc[0, 'status'] in ['received', 'verified', 'pending']): current_time = dt.datetime.utcnow() + dt.timedelta(minutes=330) req_dict = { 'volunteer_id': [volunteer_id], 'request_id': [r_df.loc[0, 'r_id']], 'matching_by': [matched_by], 'timestamp': [current_time] } df = pd.DataFrame(req_dict) #Add entry in request_matching table response = request_matching(df) #Update request status as matched if response['status'] == True: volunteers_assigned = get_volunteers_assigned_to_request( request_id) if r_df.loc[0, 'volunteers_reqd'] == volunteers_assigned: response_2 = update_requests_db({'id': request_id}, {'status': 'matched'}) response_3 = update_nearby_volunteers_db( {'r_id': request_id}, {'status': 'expired'}) #Move to message_templates.py file #Send to Volunteer v_sms_text = '[COVID SOS] Thank you agreeing to help. Name:' + r_df.loc[ 0, 'name'] + ' Mob:' + str( r_df.loc[0, 'mob_number']) + ' Request:' + r_df.loc[ 0, 'request'] + ' Address:' + r_df.loc[0, 'geoaddress'] send_sms(v_sms_text, int(v_df.loc[0, 'mob_number']), sms_type='transactional', send=True) #Send to Requestor r_sms_text = '[COVID SOS] Volunteer ' + v_df.loc[ 0, 'name'] + ' will help you. Mob: ' + str( v_df.loc[0, 'mob_number']) send_sms(r_sms_text, int(r_df.loc[0, 'mob_number']), sms_type='transactional', send=True) #Send to Moderator m_sms_text = '[COVID SOS] Volunteer ' + v_df.loc[ 0, 'name'] + ' Mob: ' + str( v_df.loc[0, 'mob_number']) + ' assigned to ' + r_df.loc[ 0, 'name'] + ' Mob:' + str(r_df.loc[0, 'mob_number']) moderator_list = get_moderator_list() for i_number in moderator_list: send_sms(m_sms_text, int(i_number), sms_type='transactional', send=True) else: return { 'status': False, 'string_response': 'Request already assigned/closed/completed', 'Response': {} } return response