コード例 #1
0
ファイル: apis.py プロジェクト: ChandanY1011/COVID
def verify_request_page(*args, **kwargs):
    uuid = request.form.get('uuid')
    r_df = request_data_by_uuid(uuid)
    if (r_df.shape[0] == 0):
        return json.dumps({
            'status': False,
            'string_response': 'Request ID does not exist.',
            'Response': {}
        })
    if (r_df.loc[0, 'status'] == 'received'):
        return json.dumps(
            {
                'Response': r_df.to_dict('records'),
                'status': True,
                'string_response': 'Request data extracted'
            },
            default=datetime_converter)
    else:
        return json.dumps({
            'Response': {},
            'status':
            False,
            'string_response':
            'Request already verified/rejected'
        })
コード例 #2
0
ファイル: partner_assignment.py プロジェクト: Pulkit07/COVID
def message_all_volunteers(uuid,radius,search_radius):
    v_list_q = """Select id as v_id,mob_number,name, latitude,longitude from volunteers where status=1"""
    v_list = pd.read_sql(v_list_q,connections('prod_db_read'))
    r_df = request_data_by_uuid(uuid)
    r_id = r_df.loc[0,'r_id']
    lat = r_df.loc[0,'latitude']
    lon = r_df.loc[0,'longitude']
    v_list['dist'] = get_haversine_distance(float(lat),float(lon),v_list['latitude'].astype(float).values,v_list['longitude'].astype(float).values)
    v_list = v_list.sort_values(by='dist',ascending=True)
    v_ids = pd.DataFrame()
    df = pd.DataFrame()
    df2 = pd.DataFrame()
    count=0
    orig_link = url_start+"accept/"+uuid
    link = url_shortener_fn(orig_link)
    print(link)
    save_request_sms_url(uuid, 'accept_link', link)
    for i in v_list.index:
        if(v_list.loc[i,'dist']<radius):
            count = count +1
            if(count>20):
                break
            sms_text = nearby_v_sms_text.format(v_name=v_list.loc[i,'name'],link=link)
            sms_to = int(v_list.loc[i,'mob_number'])
            df = df.append(v_list.loc[i,['v_id']])
            if((server_type=='prod')):
                send_sms(sms_text,sms_to,sms_type='transactional',send=True)
                print('SMS sent')
            else:
                print('Sending sms:',sms_text,' to ',str(sms_to))
        if((v_list.loc[i,'dist']>radius)&(v_list.loc[i,'dist']<search_radius)):
            count = count +1
            if(count>20):
                break
            sms_text = far_v_sms_text.format(address=r_df.loc[0,'geoaddress'][0:40],link=link)
            sms_to=int(v_list.loc[i,'mob_number'])
            df2 = df2.append(v_list.loc[i,['v_id']])
            if((server_type=='prod')):
                send_sms(sms_text,sms_to,sms_type='transactional',send=True)
                print('SMS sent')
            else:
                print('Sending sms:',sms_text,' to ',str(sms_to))
    df['r_id']=r_id
    df['status']='pending'
    print(v_list)
    print(df)
    print(df2)
    if((server_type=='prod')):
        engine = connections('prod_db_write')
        df.to_sql(name = 'nearby_volunteers', con = engine, schema='covidsos', if_exists='append', index = False,index_label=None)
    mod_sms_text = request_verified_m_sms1.format(r_id=str(r_df.loc[0,'r_id']),name=r_df.loc[0,'name'],geoaddress=r_df.loc[0,'geoaddress'][0:50],mob_number=str(r_df.loc[0,'mob_number']),v_count_1=str(df.shape[0]),v_count_2=str(df2.shape[0]))
    str_broadcast = "For request #"+str(r_df.loc[0,'r_id'])+ " "
    counter_broadcast = 0
    for i in v_list.index:
        counter_broadcast = counter_broadcast+1
        if((counter_broadcast>10) or (v_list.loc[i,'dist']>search_radius)):
            break
        str_broadcast = str_broadcast + v_list.loc[i,'name']+" m: wa.me/91"+str(v_list.loc[i,'mob_number'])+" "
    link = url_shortener_fn("https://wa.me/918618948661?text="+p.quote(str_broadcast))
    save_request_sms_url(uuid, 'broadcast_link', link)
    mod_sms_text_2 = request_verified_m_sms2.format(link=link)
    moderator_list = get_moderator_list()
    for i_number in moderator_list:
        if((server_type=='prod')):
            send_sms(mod_sms_text,sms_to=int(i_number),sms_type='transactional',send=True)
            send_sms(mod_sms_text_2,sms_to=int(i_number),sms_type='transactional',send=True)
            print('SMS sent')
        else:
            print('Sending sms:',mod_sms_text,' to ',str(i_number))
            print('Sending sms:',mod_sms_text_2,' to ',str(i_number))
    return None
コード例 #3
0
ファイル: apis.py プロジェクト: ChandanY1011/COVID
def verify_request(*args, **kwargs):
    uuid = request.form.get('uuid')
    what = request.form.get('what')
    why = request.form.get('why')
    financial_assistance = request.form.get('financial_assistance', 0)
    verification_status = request.form.get('verification_status')
    verified_by = kwargs.get('user_id', 0)
    r_id = request.form.get('r_id')
    name = request.form.get('name')
    where = request.form.get('geoaddress')
    mob_number = request.form.get('mob_number')
    urgent_status = request.form.get('urgent', 'no')
    source = request.form.get('source', 'covidsos')
    volunteers_reqd = request.form.get('volunteer_count', 1)
    current_time = dt.datetime.utcnow() + dt.timedelta(minutes=330)
    if (verification_status is None):
        return json.dumps({
            'Response': {},
            'status': False,
            'string_response': 'Please send verification status'
        })
    if ((r_id is None) or (uuid is None)):
        return json.dumps({
            'Response': {},
            'status': False,
            'string_response': 'Please send UUID/request ID'
        })
    r_df = request_data_by_uuid(uuid)
    if (r_df.shape[0] == 0):
        return json.dumps({
            'Response': {},
            'status': False,
            'string_response': 'Invalid UUID/request ID'
        })
    if (r_df.loc[0, 'source'] != source):
        response_0 = update_requests_db({'uuid': uuid}, {'source': source})
    if (r_df.loc[0, 'status'] == 'received'):
        r_v_dict = {
            'r_id': [r_id],
            'why': [why],
            'what': [what],
            'where': [where],
            'verification_status': [verification_status],
            'verified_by': [verified_by],
            'timestamp': [current_time],
            'financial_assistance': [financial_assistance],
            'urgent': [urgent_status]
        }
        df = pd.DataFrame(r_v_dict)
        expected_columns = [
            'timestamp', 'r_id', 'what', 'why', 'where', 'verification_status',
            'verified_by', 'financial_assistance', 'urgent'
        ]
        response_2 = update_requests_db({'uuid': uuid}, {
            'status': verification_status,
            'volunteers_reqd': volunteers_reqd
        })
        print('updated the status')
        past_id, past_status = check_past_verification(str(r_id))
        if (past_status == True):
            r_v_dict = {
                'r_id': r_id,
                'why': why,
                'what': what,
                'where': where,
                'verification_status': verification_status,
                'verified_by': verified_by,
                'timestamp': current_time,
                'financial_assistance': financial_assistance,
                'urgent': urgent_status
            }
            rv_dict = {x: r_v_dict[x] for x in r_v_dict}
            update_request_v_db({'id': (past_id)}, rv_dict)
        else:
            x, y = add_request_verification_db(df)
        if (verification_status == 'verified'):
            #Move to message_templates.py file
            requestor_text = '[COVIDSOS] Your request has been verified. We will look for volunteers in your neighbourhood.'
            send_sms(requestor_text,
                     sms_to=int(mob_number),
                     sms_type='transactional',
                     send=True)
            message_all_volunteers(uuid, neighbourhood_radius, search_radius)
        else:
            #Move to message_templates.py file
            requestor_text = '[COVIDSOS] Your request has been cancelled/rejected. If you still need help, please submit request again.'
            send_sms(requestor_text,
                     sms_to=int(mob_number),
                     sms_type='transactional',
                     send=True)
        return json.dumps({
            'Response': {},
            'status': response_2['status'],
            'string_response': response_2['string_response']
        })
    else:
        return json.dumps({
            'Response': {},
            'status':
            False,
            'string_response':
            'Request already verified/rejected'
        })
コード例 #4
0
ファイル: apis.py プロジェクト: ChandanY1011/COVID
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': {}
            })
コード例 #5
0
def message_all_volunteers(uuid, radius, search_radius):
    v_list_q = """Select id as v_id,mob_number,name, latitude,longitude from volunteers where status=1"""
    v_list = pd.read_sql(v_list_q, connections('prod_db_read'))
    r_df = request_data_by_uuid(uuid)
    r_id = r_df.loc[0, 'r_id']
    lat = r_df.loc[0, 'latitude']
    lon = r_df.loc[0, 'longitude']
    v_list['dist'] = get_haversine_distance(
        float(lat), float(lon), v_list['latitude'].astype(float).values,
        v_list['longitude'].astype(float).values)
    v_list = v_list.sort_values(by='dist', ascending=True)
    v_ids = pd.DataFrame()
    df = pd.DataFrame()
    df2 = pd.DataFrame()
    count = 0
    if (server_type == 'prod'):
        key_word = 'COVIDSOS'
        url_start = "https://covidsos.org/"
    else:
        key_word = 'TEST'
        url_start = "https://stg.covidsos.org/"
    for i in v_list.index:
        if (v_list.loc[i, 'dist'] < radius):
            orig_link = url_start + "accept/" + uuid
            link = url_shortener_fn(orig_link)
            sms_text = "[" + key_word + "]. Dear " + v_list.loc[
                i,
                'name'] + ", HELP NEEDED in your area. Click " + link + " to help."
            sms_to = int(v_list.loc[i, 'mob_number'])
            df = df.append(v_list.loc[i, ['v_id']])
            print(link)
            if ((server_type == 'prod')):
                send_sms(sms_text, sms_to, sms_type='transactional', send=True)
                print('SMS sent')
            else:
                print('Sending sms:', sms_text, ' to ', str(sms_to))
        if ((v_list.loc[i, 'dist'] > radius) &
            (v_list.loc[i, 'dist'] < search_radius)):
            count = count + 1
            if (count > 20):
                break
            orig_link = url_start + "accept/" + uuid
            link = url_shortener_fn(orig_link)
            print(link)
            sms_text = "[" + key_word + "] HELP NEEDED in " + r_df.loc[
                0, 'geoaddress'][
                    0:40] + ".. Click " + link + " to help or refer someone."
            sms_to = int(v_list.loc[i, 'mob_number'])
            df2 = df2.append(v_list.loc[i, ['v_id']])
            if ((server_type == 'prod')):
                send_sms(sms_text, sms_to, sms_type='transactional', send=True)
                print('SMS sent')
            else:
                print('Sending sms:', sms_text, ' to ', str(sms_to))
    df['r_id'] = r_id
    df['status'] = 'pending'
    print(v_list)
    print(df)
    print(df2)
    if ((server_type == 'prod')):
        engine = connections('prod_db_write')
        df.to_sql(name='nearby_volunteers',
                  con=engine,
                  schema='covidsos',
                  if_exists='append',
                  index=False,
                  index_label=None)
    mod_sms_text = key_word + " New request verified. Sent to " + str(
        df.shape[0]) + " nearby Volunteers and " + str(
            df2.shape[0]) + " volunteers further away"
    mod_sms_text_2 = key_word + " Request #" + str(
        r_df.loc[0, 'r_id']
    ) + " New Request Name: " + r_df.loc[0, 'name'] + " Address: " + r_df.loc[
        0, 'geoaddress'][0:50] + " Mob: " + str(
            r_df.loc[0, 'mob_number']) + " Req:" + r_df.loc[0, 'request']
    str_broadcast = "For request #" + str(r_df.loc[0, 'r_id']) + " "
    counter_broadcast = 0
    for i in v_list.index:
        counter_broadcast = counter_broadcast + 1
        if ((counter_broadcast > 10)
                or (v_list.loc[i, 'dist'] > search_radius)):
            break
        str_broadcast = str_broadcast + v_list.loc[
            i, 'name'] + " m: wa.me/91" + str(v_list.loc[i,
                                                         'mob_number']) + " "
    link = url_shortener_fn("https://wa.me/918618948661?text=" +
                            p.quote(str_broadcast))
    mod_sms_text_3 = "Broadcast to volunteers using " + link
    moderator_list = get_moderator_list()
    for i_number in moderator_list:
        if ((server_type == 'prod')):
            send_sms(mod_sms_text,
                     sms_to=int(i_number),
                     sms_type='transactional',
                     send=True)
            send_sms(mod_sms_text_2,
                     sms_to=int(i_number),
                     sms_type='transactional',
                     send=True)
            send_sms(mod_sms_text_3,
                     sms_to=int(i_number),
                     sms_type='transactional',
                     send=True)
            print('SMS sent')
        else:
            print('Sending sms:', mod_sms_text, ' to ', str(i_number))
            print('Sending sms:', mod_sms_text_2, ' to ', str(i_number))
            print('Sending sms:', mod_sms_text_3, ' to ', str(i_number))
    return None