コード例 #1
0
ファイル: arthur.py プロジェクト: williampiat3/cocoon
    def refresh_tokens(self):
        endpoint = 'https://auth.arthuronline.co.uk/oauth/token'

        headers = {
            'Cache-Control': 'no-cache',
            'content-type': 'application/x-www-form-urlencoded'
        }

        data = {
            'refresh_token': self.creds['refresh_token'],
            'client_id': self.creds['client_id'],
            'client_secret': self.creds['client_secret'],
            'grant_type': 'refresh_token'
        }

        response = requests.post(endpoint, data=data, headers=headers).json()
        print(response)
        toolbox.update_targeted(
            {
                'access_token': response['access_token'],
                'refresh_token': response['refresh_token']
            }, 'api_tokens', {'service': 'arthur'}, self.conn)
        return {
            'access_token': response['access_token'],
            'refresh_token': response['refresh_token']
        }
コード例 #2
0
ファイル: arthur.py プロジェクト: williampiat3/cocoon
	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
コード例 #3
0
ファイル: arthur.py プロジェクト: williampiat3/cocoon
 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)
コード例 #4
0
ファイル: flatmates.py プロジェクト: williampiat3/cocoon
 if i == 0:
     couple = True
 else:
     couple = False
 profiles = get_last_profiles(s, path)
 candidates = check_interest_profile(s, profiles, couple=couple)
 exclusion_list, not_interesting = get_exclusion_list(conn)
 to_exclude = []
 for candidate in candidates:
     to_exclude.append(candidate["link"])
     if candidate["link"] in exclusion_list:
         continue
     if candidate["link"] in not_interesting:
         send_message(s, candidate, path)
         toolbox.update_targeted({"message_sent": 1},
                                 "prospections",
                                 {"link": candidate["link"]}, conn)
         wait_random_time(12, 20)
         continue
     to_upload_to_db = [candidate]
     send_message(s, candidate, path)
     wait_random_time(15, 22)
     upload_to_db(conn, to_upload_to_db, 1)
 to_upload_to_db = []
 for profile in profiles:
     if profile['link'] not in to_exclude and profile[
             'link'] not in exclusion_list and profile[
                 'link'] not in not_interesting:
         to_upload_to_db.append(profile)
 upload_to_db(conn, to_upload_to_db, 0)
 i += 1
コード例 #5
0
ファイル: arthur.py プロジェクト: williampiat3/cocoon
 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