Exemple #1
0
def get_exclusion_list(conn):
    former = toolbox.select_db(
        "SELECT * FROM prospections WHERE message_sent=1", conn)
    exclusion_list = list(map(lambda x: x["link"], former))
    former = toolbox.select_db(
        "SELECT * FROM prospections WHERE message_sent=0", conn)
    not_interesting = list(map(lambda x: x["link"], former))
    return exclusion_list, not_interesting
Exemple #2
0
	def __init__(self,conn):
		self.creds=toolbox.select_db("SELECT * FROM ops.api_tokens WHERE service='arthur'",conn)[0]
		self.conn=conn
		try:
			self.get_current_properties()
		except KeyError:
			self.refresh_tokens()
			self.creds=toolbox.select_db("SELECT * FROM ops.api_tokens WHERE service='arthur'",conn)[0]
Exemple #3
0
def db_display():
    #head=request.headers['Authorization']
    #if check_authentication(head):
    conn = toolbox.get_connection()
    front = front_tb.Front(conn)
    intel = request.get_json()
    id_sub = intel["UniqueID"]
    email = intel["Email"]
    #hard coded shit I know
    form = formstack.Formstack(conn)
    initial_data = form.get_submission(id_sub)
    dict_initial = dict(
        map(lambda x: (x['field'], x['value']), initial_data['data']))
    link = "https://cocoon.formstack.com/forms/tenant_information?id_sub={0}".format(
        str(id_sub))
    data_email_propective_tenant = {
        "link": link,
        "last_name": dict_initial["64515438"],
        "first_name": dict_initial["64515437"],
        "address": dict_initial["64515442"],
        "bond": str(2 * int(dict_initial["64515461"])),
        "rent": str(int(dict_initial["64515461"])),
        "incoming_date": dict_initial["64515462"],
    }
    try:
        query = []
        house_info = toolbox.select_db(
            "SELECT * FROM ops.houses WHERE address='" +
            dict_initial["64515442"] + "'", conn)[0]
        query.append(
            "SELECT t.first_name, t.nationality,  TIMESTAMPDIFF(year,t.birthdate, now() ) AS age,t.sex,t.occupation,t.phone,t.email"
        )
        query.append(
            "FROM ops.tenants AS t INNER JOIN ops.tenants_history AS th ON t.id=th.tenant_id"
        )
        query.append("WHERE th.house_id='" + house_info["id"] + "' AND '" +
                     dict_initial["64515462"] +
                     "' BETWEEN incoming_date AND outgoing_date ")
        roommates = toolbox.select_db(' '.join(query), conn)
        emails = []
        extension = []
        for roommate in roommates:
            emails.append(roommate["email"])
            string = "<td>" + roommate["first_name"] + "</td>"
            string += "<td>" + roommate["nationality"] + "</td>"
            string += "<td>" + str(roommate["age"]) + "</td>"
            string += "<td>" + roommate["sex"] + "</td>"
            string += "<td>" + roommate["occupation"] + "</td>"
            string += "<td>" + str(roommate["phone"]) + "</td>"
            string += "<td>" + roommate["email"] + "</td>"
            extension.append("<tr>" + string + "</tr>")
        with open("templates/deposit_email.html", "r") as file:
            template = file.read()

        template = template.format(**data_email_propective_tenant)
        template = template.replace("<h3></h3>", ' '.join(extension))
    except Exception, e:
        front.send_email(["*****@*****.**"], "issue", str(e))
Exemple #4
0
def check_authentication(Authorization):
    conn = toolbox.get_connection()
    data = toolbox.select_db("SELECT access_token FROM ops.webhooks_tokens;",
                             conn)
    conn.close()
    list_bearer = list(map(lambda x: "Bearer " + x["access_token"], data))
    print(list_bearer)
    if Authorization in list_bearer:
        return True
    else:
        raise InvalidUsage('Authentication failed', status_code=410)
Exemple #5
0
	def update_tenancies_status(self):
		pending_units=toolbox.select_db("SELECT * FROM ops.tenants_history WHERE arthur_id IS NOT NULL AND state='OK' AND NOW()<outgoing_date",self.conn)
		print(pending_units)
		for unit in pending_units:
			tenancy=self.get_tenancy(unit["arthur_id"])
			new_status=tenancy["data"]["status"]
			if  new_status.lower() == "rejected" :
				print("tenant rejected")
				toolbox.update_targeted({'state':new_status.lower()},"ops.tenants_history",{"arthur_id":unit["arthur_id"]},self.conn)
				continue
			if unit["signature"]!=None and new_status.lower() == "prospective":
				#update status on arthur
				self.update_tenancy(unit["arthur_id"],{"status":"approved","renters":"test"})
				print("status update on arthur")
				continue
			if unit["signature"]!=None and new_status.lower() != "prospective":
				print("update intel")
				toolbox.update_targeted({'incoming_date':tenancy["data"]["move_in_date"],'outgoing_date':tenancy["data"]["move_out_date"]},"ops.tenants_history",{"arthur_id":unit["arthur_id"]},self.conn)
				continue
		return True
Exemple #6
0
 def update_tenant_information(self):
     renters = self.get_renters()
     match = dict(
         map(
             lambda x: (x["tenancy_id"], {
                 "first_name": x["first_name"],
                 "last_name": x["last_name"],
                 "email": x["email"],
                 "phone": x["mobile"]
             }), renters))
     for renter in match:
         tenancies = toolbox.select_db(
             "SELECT * FROM ops.tenants_history WHERE arthur_id='{}'".
             format(renter), self.conn)
         id_tenant = None
         for tenancy in tenancies:
             id_tenant = tenancy["tenant_id"]
             break
         if id_tenant != None:
             toolbox.update_targeted(match[renter], "ops.tenants",
                                     {"id": id_tenant}, self.conn)
Exemple #7
0
 def __init__(self, conn):
     self.conn = conn
     self.creds = toolbox.select_db(
         "SELECT * FROM ops.api_tokens WHERE service='formstack'", conn)[0]
Exemple #8
0
                dict_tenant["64707116"].encode('ascii', 'ignore'))
        except KeyError:
            pass
        try:
            data_tenant["description"] = MySQLdb.escape_string(''.join([
                i if ord(i) < 128 else ' '
                for i in dict_tenant["64707081"].replace("'", " ").replace(
                    u'\xc1', "a").replace(u'\xe3', "a").replace(
                        u'\U0001f601', "").replace(u'\u202d', " ")
            ]).encode('ascii', 'ignore'))
        except KeyError:
            pass

        logging.debug(data_tenant)
        house_info = toolbox.select_db(
            "SELECT * FROM ops.houses WHERE address='" +
            dict_initial["64515442"] + "'", conn)[0]

        data_ao = {
            'status': 'prospective',
            'status_alias': 'undefined',
            'tenancy_start': dict_initial["64515462"],
            'tenancy_end': dict_initial["64515463"],
            'duration': 'undefined',
            'break_clause': dict_initial["64515463"],
            'move_in_date': dict_initial["64515462"],
            'move_out_date': dict_initial["64515463"],
            'registered_deposit': str(int(dict_initial["64515461"]) * 2),
            'registered_deposit_date': dict_initial["64515462"],
            'rent_amount': str(dict_initial["64515461"]),
            'rent_frequency_id': '5',
Exemple #9
0
def match_blurb(subject,array_match):
	for match in array_match:
		if re.search(match, subject):
			return True
	return False

if __name__=="__main__":

	
	array_inboxes={'FACEBOOK':["sent a message to the conversation"],
	'Easyroommate_AU':["ve just received a message from"],
	'Flatmates Notifications':["You have received a new message from"]
	}
	conn=toolbox.get_connection()
	msg_already_stored=toolbox.select_db("SELECT msg_id FROM front_emails",conn)
	exclusion_list=list(map(lambda x: x["msg_id"],msg_already_stored))
	endpoint = "https://api2.frontapp.com/inboxes"
	token=toolbox.select_db("SELECT access_token FROM api_tokens WHERE service='front'",conn)[0]["access_token"]
	headers_get = {"Authorization":"Bearer "+token,
				"Host":"api2.frontapp.com"}
	results=requests.get(endpoint,headers=headers_get).json()["_results"]
	
	ids={}
	output=[]
	
	for result in results:
		if result["name"] in array_inboxes.keys():
			ids[result["id"]]=result["name"]
	for id_inbox in ids:
		endpoint_conv="https://api2.frontapp.com/inboxes/"+id_inbox+"/conversations"
Exemple #10
0
 def update_tenancies_status(self):
     current_units = toolbox.select_db(
         "SELECT * FROM ops.tenants_history WHERE arthur_id IS NOT NULL AND state='OK' AND NOW()<outgoing_date",
         self.conn)
     for unit in current_units:
         tenancy = self.get_tenancy(unit["arthur_id"])
         room = tenancy["data"]["unit_address_name"].split(" ")[1]
         unit_id = tenancy["data"]["Unit"]["id"]
         unit_arthur = self.get_unit(unit_id)
         current_id_house = toolbox.select_specific(
             "ops.houses",
             {"arthur_id": str(unit_arthur["data"]["property"]["id"])},
             self.conn)["id"]
         new_status = tenancy["data"]["status"]
         rent_tenant = int(tenancy["data"]["rent_amount"].split(".")[0])
         if new_status.lower() == "rejected":
             print("tenant rejected")
             toolbox.update_targeted({'state': new_status.lower()},
                                     "ops.tenants_history",
                                     {"arthur_id": unit["arthur_id"]},
                                     self.conn)
             continue
         if new_status.lower(
         ) == "approved" and unit["incoming_date"] < datetime.datetime.now(
         ).date() and unit["outgoing_date"] > datetime.datetime.now().date(
         ):
             self.update_tenancy(unit["arthur_id"], {"status": "current"})
         if new_status.lower() in [
                 "approved", "current", "periodic", "ending", "past"
         ]:
             print("update intel")
             try:
                 data_update = {
                     'tenant_nr': "Tenant " + str(room),
                     'incoming_date': tenancy["data"]["move_in_date"],
                     #'outgoing_date':tenancy["data"]["move_out_date"]
                     'rent': rent_tenant,
                     "house_id": str(current_id_house)
                 }
                 if tenancy["data"]["move_out_date"] != None:
                     data_update["outgoing_date"] = tenancy["data"][
                         "move_out_date"]
                 toolbox.update_targeted(data_update, "ops.tenants_history",
                                         {"arthur_id": unit["arthur_id"]},
                                         self.conn)
             except:
                 pass
             continue
     pending_units = toolbox.select_db(
         "SELECT * FROM ops.tenants_history WHERE arthur_id IS NOT NULL AND state='pending'",
         self.conn)
     for unit in pending_units:
         tenancy = self.get_tenancy(unit["arthur_id"])
         new_status = tenancy["data"]["status"]
         print(new_status)
         if new_status.lower() == "rejected":
             print("tenant rejected")
             toolbox.update_targeted({'state': new_status.lower()},
                                     "ops.tenants_history",
                                     {"arthur_id": unit["arthur_id"]},
                                     self.conn)
             continue
         if new_status.lower() == "approved":
             toolbox.update_targeted({'state': 'OK'}, "ops.tenants_history",
                                     {"arthur_id": unit["arthur_id"]},
                                     self.conn)
             print((unit["incoming_date"] -
                    datetime.datetime.now().date()).days)
             if (unit["incoming_date"] -
                     datetime.datetime.now().date()).days < 7.:
                 #create task for checking contracts now
                 print(
                     self.create_task(
                         'Cocoon',
                         "URGENT TODAY: check signature and prepare incoming report with the tenant ",
                         date_due=datetime.datetime.now().strftime(
                             '%Y-%m-%d'),
                         tenancy_id=unit["arthur_id"]))
             else:
                 #create task for checking the contracts
                 moving_in_date = datetime.datetime.strptime(
                     tenancy["data"]["move_in_date"], "%Y-%m-%d")
                 event_date = (
                     moving_in_date -
                     datetime.timedelta(days=7)).strftime('%d-%m-%Y')
                 print(
                     self.create_task(
                         'Cocoon',
                         "Please check signature and organise  incoming procedure for "
                         + event_date,
                         date_due=event_date,
                         tenancy_id=unit["arthur_id"]))
     return True
Exemple #11
0
	def __init__(self,conn):
		self.creds=toolbox.select_db("SELECT * FROM api_tokens WHERE service='front'",conn)[0]