<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas_datareader.data as web\n",
    "from pymatgen import Structure\n",
    "from mpcontribs.client import load_client"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use your API key to set up the client."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "project = 'my_project'\n",
    "client = load_client('your-api-key-here')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *dir* command lists available resources and operations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(dir(client))\n",
    "print(dir(client.projects))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the *projects* resource to retrieve or update project information. The *_fields* argument controls which fields are included in the response."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client.projects.get_entry(pk=project, _fields=['title', 'authors', 'description', 'urls']).result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *update_entry* operation returns a dictionary of updated fields."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "client.projects.update_entry(pk=project, project={\n",
    "     'title': 'New Title', # 'urls': {'PRC': 'https://google.fr'}, 'urls': {'PRC': None}\n",
    "}).result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the *contributions* resource to create, retrieve, and update contributions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "identifier = 'mp-1002'\n",
    "cid = client.contributions.create_entry(contribution={\n",
    "    'project': project, 'identifier': identifier,\n",
    "    'data': {'E': '3.33 eV', 'E|V': {'a': 1, 'b': '3 cm'}}\n",
    "}).result()['id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client.contributions.get_entry(pk=cid, _fields=['id', 'identifier', 'data']).result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],<commit_msg>fix get_started nb<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas_datareader.data as web\n",
    "from pymatgen import Structure\n",
    "from mpcontribs.client import load_client"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use your API key to set up the client."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "project = 'my_project'\n",
    "client = load_client('your-api-key-here')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *dir* command lists available resources and operations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(dir(client))\n",
    "print(dir(client.projects))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the *projects* resource to retrieve or update project information. The *_fields* argument controls which fields are included in the response."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client.projects.get_entry(pk=project, _fields=['title', 'authors', 'description', 'urls']).result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *update_entry* operation returns a dictionary of updated fields."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "client.projects.update_entry(pk=project, project={\n",
    "     'title': 'New Title', # 'urls': {'PRC': 'https://google.fr'}, 'urls': {'PRC': None}\n",
    "}).result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the *contributions* resource to create, retrieve, and update contributions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "identifier = 'mp-1002'\n",
    "cid = client.contributions.create_entries(contributions=[{\n",
    "    'project': project, 'identifier': identifier,\n",
    "    'data': {'E': '3.33 eV', 'E|V': {'a': 1, 'b': '3 cm'}}\n",
    "}]).result()['data'][0]['id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client.contributions.get_entry(pk=cid, _fields=['id', 'identifier', 'data']).result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
{'fraction_non_alphanumeric': 0.21925431274346133, 'fraction_numerical': 0.003524392506028566, 'mean_word_length': 3.0389513108614232, 'pattern_counts': {'":': 112, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7250184', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1902, 'n_words': 390}