Exemplo n.º 1
0
def preprocess_tweets(category, xls_file):
	sheet_name = "Stream"
	output_file = "processed_tweets.txt"
	dirty_words = [" #t**s", " #sexy ", " #boobs ", " sex ", " p**n ", " pussy ", 
					" b*****b", " cum ", " horny ", " sexual hunger "]
	
	num_dirty_tweets = 0
	copies = 0
	wb = rs.get_workbook(xls_file)
	ws = rs.get_sheet(wb ,sheet_name)

	tweets = rs.read_cells(category, ws)
	english_tweets = []
	output_file = open(output_file, "a")

	for tweet in tweets:
		content = tweet.content
		language = lr.detect_language(content)
		
		if language == "english":
			
			if processed_tweets.has_key(tweet.id):
				continue

			has_dirty_word = 0
			for word in dirty_words: 
				if word in tweet.content:
					num_dirty_tweets += 1
					has_dirty_word += 1
			if not has_dirty_word:
				processed_tweets[tweet.id] = 1
				out_str = tweet.toString()
				output_file.write(out_str.encode('ascii','backslashreplace'))

	output_file.close()
Exemplo n.º 2
0
def validate_phone(user_phone, user_given_otp):
    # correct_otp = get_otp(user_phone)

    # check if the user number exists in the list

    sheetname = "OTP_Record_Mumbai"
    status, sheet = get_sheet(sheetname)

    otp_records = (sheet.get_all_values())
    number_exists = False

    for otp_record in otp_records[1:]:
        # number match
        if user_phone == otp_record[number_index - 1]:
            user_otp = otp_record[otp_index - 1]
            otp_gen_time = int(otp_record[time_index - 1])
            # get the current time
            secnow = time.time()
            diff = (secnow - otp_gen_time) // 60
            print("Difference in time is ", diff)
            if diff >= 3:
                return False
            else:
                if user_otp != user_given_otp:
                    return False
                else:
                    return True
    return False
Exemplo n.º 3
0
def get_requests(sheetname, sheetType, need_status):
    '''
    insert into the google sheet in the order
    name, contact_num,lat, lon, address,
    rice_qty, wheat_qty, oil_qty, daal_qty,
    request_status
    '''

    # if need_status=="Completed":
    #     sheetname="Daily_Completed"
    # elif need_status=="Pending":
    #     sheetname="Details_People"

    status, sheet = get_sheet(sheetname)
    if status == False:
        return sheet
    list_of_requests = (sheet.get_all_values())
    print("number of rows ", len(sheet.get_all_values()))
    print("number of columns ", len(sheet.get_all_values()[0]))

    list_requests = []

    if sheetType == "ngo":
        for req in list_of_requests[1:]:
            list_requests.append(convert_ngoItem_to_dict(req))
        return list_requests

    # skip the first request since it is heading
    for the_request in list_of_requests[1:]:
        print("status is ", the_request[request_status_index - 1], need_status)

        if the_request[request_status_index - 1] == need_status:

            # dict_request={}
            # dict_request["request_id"]=the_request[0]

            # dict_request["name"]=the_request[1]
            # dict_request["contact_num"]=the_request[2]
            # # dict_request["lat"]=int(float(the_request[3]))
            # # dict_request["lon"]=int(float(the_request[4]))
            # dict_request["requestor_address"]=the_request[3]
            # dict_request["request_status"]=the_request[4]

            # dict_request["rice_qty"]=the_request[5]
            # dict_request["wheat_qty"]=the_request[6]
            # dict_request["oil_qty"]=the_request[7]
            # dict_request["daal_qty"]=the_request[8]
            # # a gap for beneficiary
            # dict_request["volunteer_name"]=the_request[10]
            # dict_request["vol_contact_num"]=the_request[11]

            dict_request = convert_list_to_dict(the_request)

            list_requests.append(dict_request)

    return list_requests
Exemplo n.º 4
0
def complete_payment():
    # list_ids_to_mark_complete=[]
    # print(request.form.keys)
    # for key,val in request.form.items():
    #     print(key)
    #     if key!="contact_num" and key!="otp_num" and key!="return_message":
    #         list_ids_to_mark_complete.append(int(float(val)))
    # print(list_ids_to_mark_complete)
    benificiary_contact = request.form['contact_num']
    otp_num = request.form['otp_num']
    amount_pledged = request.form['amount_pledged']
    contrib_name = request.form['contrib_name']

    # now to check if otp matches with the otp mentioned in the sheet
    # also check for expired otp

    is_valid = True
    is_valid = validate_phone(benificiary_contact, otp_num)

    print("checked the otp")

    if is_valid:
        # add amount to sheet

        status, sheet = get_sheet("Payment Local")
        if status == False:
            return sheet
        data_list = [contrib_name, benificiary_contact, amount_pledged]

        my_date = datetime.datetime.now(pytz.timezone('Asia/Calcutta'))
        data_list.append(str(my_date))
        index = len(sheet.get_all_values()) + 1
        sheet.insert_row(data_list, index)

        # status,sheet=get_sheet("Details_People")
        # if status==False:
        #     return sheet
        # list_of_requests=(sheet.get_all_values())

        # list_to_be_fulfilled=[]

        # row_count=2

        # we'll check if the request ids match
        # for the_request in list_of_requests[1:]:
        #     if int(float(the_request[0])) in list_ids_to_mark_complete:
        #         sheet.update_cell(row_count, request_status_index+1, "Completed")
        #         sheet.update_cell(row_count, beneficiary_contact_index+1,
        #          str(benificiary_contact))
        #     row_count+=1

        return redirect("https://imjo.in/U6X3pf")
    else:
        return "Some issue with your OTP, please go back and check out again"
Exemplo n.º 5
0
def complete_payment_mumbai():
    list_ids_to_mark_complete = []
    print(request.form.keys)
    for key, val in request.form.items():
        print("k is ", key)
        if key != "contact_num" and key != "otp_num" and key != "return_message" and key != "contrib_name" and key != "contrib_type":
            list_ids_to_mark_complete.append(int(float(val)))
    print(list_ids_to_mark_complete)
    benificiary_contact = request.form['contact_num']
    otp_num = request.form['otp_num']
    # amount_pledged=request.form['amount_pledged']
    contrib_name = request.form['contrib_name']
    contrib_type = request.form['contrib_type']

    # now to check if otp matches with the otp mentioned in the sheet
    # also check for expired otp

    is_valid = True
    is_valid = validate_phone(benificiary_contact, otp_num)

    print("checked the otp")

    if is_valid:

        status, sheet = get_sheet("Details_People_Mumbai")
        if status == False:
            return sheet
        list_of_requests = (sheet.get_all_values())

        list_to_be_fulfilled = []

        row_count = 2

        # we'll check if the request ids match
        for the_request in list_of_requests[1:]:
            if int(float(the_request[0])) in list_ids_to_mark_complete:
                sheet.update_cell(row_count, request_status_index, "Completed")
                sheet.update_cell(row_count, beneficiary_contact_index,
                                  str(benificiary_contact))
                sheet.update_cell(row_count, beneficiary_name_index,
                                  str(contrib_name))
                sheet.update_cell(row_count, beneficiary_type_index,
                                  str(contrib_type))

            row_count += 1

        return redirect(url_for("thank_you_mumbai"))
        # return render_template("thank-you-mumbai.html")
    else:
        return "Some issue with your OTP, please go back and check out again"
def insert_into_gsheet_mumbai(data_list):
    '''
    insert into the google sheet in the order
    name, contact_num,lat, lon, address,
    rice_qty, wheat_qty, oil_qty, daal_qty,
    request_status
    '''
    status, sheet = get_sheet("Details_People_Mumbai")
    if status == False:
        return sheet

    row = data_list
    index = len(sheet.get_all_values()) + 1
    print("last id ", sheet.get_all_values()[-1][0])
    if len(sheet.get_all_values()) >= 2:
        request_id = int(sheet.get_all_values()[-1][0]) + 1
    else:
        # first request
        request_id = 1
    row = [request_id] + row
    sheet.insert_row(row, index)
    return True
def send_otp_sms(user_phone):
    account_sid = environ.get('account_sid')
    auth_token = environ.get('auth_token')

    #first store it into sheet

    # get data from sheet
    sheetname = "OTP_Record"
    status, sheet = get_sheet(sheetname)

    otp_records = sheet.get_all_values()
    number_exists = False
    return_str = "OK"

    row_count = 2
    for otp_record in otp_records[1:]:
        # number match
        if user_phone == otp_record[number_index - 1]:
            return_str = "OTP has been already sent. Please wait 3 minutes before re generating"
            number_exists = True
            user_otp = otp_record[otp_index - 1]
            print("Otp already here, lets check the time")
            otp_gen_time = int(otp_record[time_index - 1])
            print("Otp was generated at ", otp_gen_time)
            # get the current time
            secnow = time.time()
            print("current time ", secnow)
            diff = (secnow - otp_gen_time) // 60
            print("Difference in time is ", diff)
            if diff >= 3:
                # more than 3 minutes, can generate new otp
                user_otp = generate_otp(user_phone)
                print("New otp is this ", user_otp)

                # update time stamp
                sheet.update_cell(row_count, time_index, secnow)
                # update with new otp
                sheet.update_cell(row_count, otp_index, user_otp)

                return_str = "OTP has been sent/recorded"
        row_count += 1

    if not number_exists:
        user_otp = generate_otp(user_phone)
        print("New user, otp is ", user_otp)
        # make a new entry in the sheet
        index = len(sheet.get_all_values()) + 1
        row = [time.time(), user_phone, user_otp]

        sheet.insert_row(row, index)
        return_str = "OTP has been sent/recorded"

    if return_str == "OTP has been sent/recorded":
        # send sms to user

        client = Client(account_sid, auth_token)

        if "+91" not in user_phone and len(user_phone) != 13:
            user_phone = "+91" + user_phone

        print("sending to ", user_phone)

        message = client.messages.create(
            body='Your OTP for Covid Help is :' + str(user_otp),
            from_=environ.get('reg_phone'),
            to=str(user_phone),
        )

        print(message.sid)

    # return to
    return return_str
Exemplo n.º 8
0
def checkoutmumbai():

    list_ids_to_mark_complete = []
    print(request.form.keys)
    for key, val in request.form.items():
        print(key)
        if key != "contact_num" and key != "contrib_name" and key != "contrib_type":
            list_ids_to_mark_complete.append(int(float(val)))
    print("to be completed", list_ids_to_mark_complete)

    benificiary_contact = request.form['contact_num']
    contrib_name = request.form['contrib_name']
    contrib_type = request.form['contrib_type']

    # some form validation here

    mobile_issue = False
    if benificiary_contact == "":
        mobile_issue = True

    if not benificiary_contact.isdecimal():
        mobile_issue = True

    if len(benificiary_contact) != 10:
        mobile_issue = True

    if mobile_issue:
        return "Please retry with proper mobile number"

    if len(list_ids_to_mark_complete) == 0:
        return "Please go back and click on the check boxes \
        to select the requirements you want to fulfill."

    status, sheet = get_sheet("Details_People_Mumbai")
    if status == False:
        return sheet
    list_of_requests = (sheet.get_all_values())

    list_to_be_fulfilled = []

    row_count = 2
    for the_request in list_of_requests[1:]:
        if int(float(the_request[0])) in list_ids_to_mark_complete:
            # first create a dict out of the row

            dict_request = convert_list_to_dict(the_request)

            list_to_be_fulfilled.append(dict_request)
            # sheet.update_cell(row_count, request_status_index+1, "Completed")
            # sheet.update_cell(row_count, beneficiary_contact_index+1, str(benificiary_contact))
        row_count += 1

    print(list_to_be_fulfilled)

    dict_order = {"contributor_number": str(benificiary_contact)}
    dict_order["order"] = list_to_be_fulfilled
    dict_order["contrib_name"] = contrib_name
    dict_order["contrib_type"] = contrib_type

    # now generate the otp
    return_str = send_otp_sms(str(benificiary_contact).strip())
    dict_order["return_message"] = return_str

    return render_template("otp_payment_mumbai.html", items=dict_order)