import requests
import json


def search(conf, title):
    """search target page in database

    Args:
        conf (dict): Config
        title (str): Target page title

    Returns:
        dict: Search result
    """
    header = {"Authorization": f"Bearer {conf['token']}",
              "Notion-Version": "2021-05-13",
              "Content-Type": "application/json"
              }
    url_search = f"https://api.notion.com/v1/databases/{conf['databaseId']}/query"
    payload_search = {
        "filter": {
            "property": conf["property"],
            "text": {
                "equals": title
            }
        }
    }
    req_search = requests.post(
        url_search, data=json.dumps(payload_search), headers=header)
    search_json = req_search.json()
    print(search_json)
    return search_json