-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from arthur-schnitzler/main
code updates
- Loading branch information
Showing
11 changed files
with
271 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "535b021a-300f-4140-96b6-5a50b96336bc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# run against production 2024-10-16\n", | ||
"from tqdm import tqdm\n", | ||
"from dumper.utils import gsheet_to_df\n", | ||
"from apis_core.utils import get_object_from_pk_or_uri" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a914f665-cd8b-4698-8499-e4fb92c9f709", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = gsheet_to_df(\"1wgLHBHeJECkmgJUIpPdG-JS8F-0ht_LdVTxNmWwW8O0\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "08aefefc-762f-4400-9893-1043d69ca874", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"col, _ = Collection.objects.get_or_create(name=\"Schnitzler-Theater\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d6e188f0-371b-4527-8df1-3758d8eeee85", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# don't run twice!!!\n", | ||
"pmb_ids = []\n", | ||
"for i, row in tqdm(df.iterrows()):\n", | ||
" work = Work.objects.create(name=row[\"Title\"])\n", | ||
" pmb_ids.append(work.id)\n", | ||
" work.collection.add(col)\n", | ||
" uri, _ = Uri.objects.get_or_create(\n", | ||
" uri=f'https://{row[\"URI\"]}',\n", | ||
" domain=\"schnitzler-theater\",\n", | ||
" entity=work\n", | ||
" )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a845af15-a476-4e16-a8c1-ed33d1c7da86", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df[\"pmb_ids\"] = pmb_ids" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b682fa0f-4b92-4f90-b2c8-53d0f9f332a0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df.to_csv(\"theater-uris.csv\", index=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "63d06a2d-bc85-4ae4-8142-a287f471a2fa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Django Shell-Plus", | ||
"language": "python", | ||
"name": "django_extensions" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "abdba1e8-027e-4931-a35b-03aaf8aa9464", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from django.core.exceptions import ObjectDoesNotExist\n", | ||
"from tqdm import tqdm\n", | ||
"from dumper.utils import gsheet_to_df\n", | ||
"from apis_core.utils import get_object_from_pk_or_uri" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cdb36196-46aa-4b7b-9871-0a8a3dd279ea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = gsheet_to_df(\"1-_WXbdmpLzz_9vBiZ1y9v2tle_26m4tAhPTGzkkin5E\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "682d2d62-1e30-4db5-8323-c07a3f62222e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "342c4e3d-39c5-4f8b-b0b0-950cde457983", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"relation_type_lookup = {\n", | ||
" \"1049\": {\n", | ||
" \"relation_type\":PersonWork,\n", | ||
" \"relation\": PersonWorkRelation.objects.get(id=1049),\n", | ||
" \"target_class\": Work\n", | ||
" },\n", | ||
" \"1052\": {\n", | ||
" \"relation_type\": PersonWork,\n", | ||
" \"relation\": PersonWorkRelation.objects.get(id=1052),\n", | ||
" \"target_class\": Work\n", | ||
" },\n", | ||
" \"1053\": {\n", | ||
" \"relation_type\": PersonWork,\n", | ||
" \"relation\": PersonWorkRelation.objects.get(id=1053),\n", | ||
" \"target_class\": Work\n", | ||
" },\n", | ||
" \"1181\": {\n", | ||
" \"relation_type\": PersonPlace,\n", | ||
" \"relation\": PersonPlaceRelation.objects.get(id=1181),\n", | ||
" \"target_class\": Place\n", | ||
" },\n", | ||
" \"1217\": {\n", | ||
" \"relation_type\": PersonWork,\n", | ||
" \"relation\": PersonWorkRelation.objects.get(id=1217),\n", | ||
" \"target_class\": Work\n", | ||
" }\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6748b522-2617-4436-ab9b-0c46c1867e6a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"does_not_exist = set()\n", | ||
"for g, ndf in df.groupby(\"relation-id\"):\n", | ||
" relation = relation_type_lookup[str(g)][\"relation\"]\n", | ||
" relation_class = relation_type_lookup[str(g)][\"relation_type\"]\n", | ||
" target_class = relation_type_lookup[str(g)][\"target_class\"]\n", | ||
" print(relation, relation_class, target_class)\n", | ||
" if \"ork\" in relation_class.__name__:\n", | ||
" print(\"work\")\n", | ||
" else:\n", | ||
" print(\"place\")\n", | ||
" for i, row in tqdm(ndf.iterrows(), total=len(ndf)):\n", | ||
" try:\n", | ||
" source = Person.objects.get(pk=row[\"source_id\"])\n", | ||
" except ObjectDoesNotExist:\n", | ||
" does_not_exist.add(row[\"source_id\"])\n", | ||
" continue\n", | ||
" try:\n", | ||
" target = target_class.objects.get(pk=row[\"target_id\"])\n", | ||
" except ObjectDoesNotExist:\n", | ||
" does_not_exist.add(row[\"target_id\"])\n", | ||
" if isinstance(row[\"relation_start_date_written\"], str):\n", | ||
" start_date_written = row[\"relation_start_date_written\"]\n", | ||
" end_date_written = row[\"relation_end_date_written\"]\n", | ||
" else:\n", | ||
" start_date_written = None\n", | ||
" end_date_written = None\n", | ||
" if \"ork\" in relation_class.__name__:\n", | ||
" relation_class.objects.get_or_create(\n", | ||
" related_person=source,\n", | ||
" related_work=target,\n", | ||
" relation_type=relation,\n", | ||
" start_date_written=start_date_written,\n", | ||
" end_date_written=end_date_written\n", | ||
" )\n", | ||
" else:\n", | ||
" relation_class.objects.get_or_create(\n", | ||
" related_person=source,\n", | ||
" related_place=target,\n", | ||
" relation_type=relation,\n", | ||
" start_date_written=start_date_written,\n", | ||
" end_date_written=end_date_written\n", | ||
" )\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Django Shell-Plus", | ||
"language": "python", | ||
"name": "django_extensions" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters