forked from acdh-oeaw/pmb-service
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #100 from arthur-schnitzler/main
code update (reduced gunicorn workers to one)
- Loading branch information
Showing
5 changed files
with
541 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,3 +194,4 @@ brahms_pmb.csv | |
hanslick-werke-wikidata.csv | ||
Untitled1.ipynb | ||
event-types.csv | ||
events-pmb_ids.csv |
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,313 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "080d64de-e40b-4aa3-94a0-adcc59c2c508", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from tqdm import tqdm\n", | ||
"from dumper.utils import gsheet_to_df\n", | ||
"from apis_core.utils import get_object_from_pk_or_uri\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "aba2e0d2-933f-4ce2-9e05-5b7049e842b6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"col, _ = Collection.objects.get_or_create(name=\"Schnitzler-Theater\")\n", | ||
"temp_col, _ = Collection.objects.get_or_create(name=\"temp-issue-227\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "69207701-41c4-4151-b36a-037613baa634", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"200\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"df = gsheet_to_df(\"1NAyAetEWR1RzyGcdTWc0KGK2ip19PpSyIOBBCOnyRnA\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "cb370aa1-33f6-4d1b-97d9-0c09f3fd8bb3", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style scoped>\n", | ||
" .dataframe tbody tr th:only-of-type {\n", | ||
" vertical-align: middle;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>start-date</th>\n", | ||
" <th>end-date</th>\n", | ||
" <th>start-date-written</th>\n", | ||
" <th>end-date-written</th>\n", | ||
" <th>title</th>\n", | ||
" <th>eventType</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>1876-03-15</td>\n", | ||
" <td>1876-03-15</td>\n", | ||
" <td>1876-03-15</td>\n", | ||
" <td>1876-03-15</td>\n", | ||
" <td>Aufführung von Das heiß Eysen; Die ehrlich Bäc...</td>\n", | ||
" <td>1200</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>1876-04-02</td>\n", | ||
" <td>1876-04-02</td>\n", | ||
" <td>1876-04-02</td>\n", | ||
" <td>1876-04-02</td>\n", | ||
" <td>Gesellschaftskonzert, 2.4.1876</td>\n", | ||
" <td>4302</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>1876-04-27</td>\n", | ||
" <td>1876-04-27</td>\n", | ||
" <td>1876-04-27</td>\n", | ||
" <td>1876-04-27</td>\n", | ||
" <td>Aufführung von Götz von Berlichingen, 27.4.1876</td>\n", | ||
" <td>1200</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>1876-05-08</td>\n", | ||
" <td>1876-05-08</td>\n", | ||
" <td>1876-05-08</td>\n", | ||
" <td>1876-05-08</td>\n", | ||
" <td>Aufführung von Uriel Acosta. Trauerspiel in fü...</td>\n", | ||
" <td>1200</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>1876-06-29</td>\n", | ||
" <td>1876-06-29</td>\n", | ||
" <td>1876-06-29</td>\n", | ||
" <td>1876-06-29</td>\n", | ||
" <td>Aufführung von Die Hugenotten, 29.6.1876</td>\n", | ||
" <td>1200</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>...</th>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3905</th>\n", | ||
" <td>1931-10-09</td>\n", | ||
" <td>1931-10-09</td>\n", | ||
" <td>1931-10-09</td>\n", | ||
" <td>1931-10-09</td>\n", | ||
" <td>Filmvorführung von Razzia auf Liebe, 9.10.1931</td>\n", | ||
" <td>4234</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3906</th>\n", | ||
" <td>1931-10-11</td>\n", | ||
" <td>1931-10-11</td>\n", | ||
" <td>1931-10-11</td>\n", | ||
" <td>1931-10-11</td>\n", | ||
" <td>Filmvorführung von Eva, 11.10.1931</td>\n", | ||
" <td>4234</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3907</th>\n", | ||
" <td>1931-10-12</td>\n", | ||
" <td>1931-10-12</td>\n", | ||
" <td>1931-10-12</td>\n", | ||
" <td>1931-10-12</td>\n", | ||
" <td>Filmvorführung von Purpur und Waschblau, 12.10...</td>\n", | ||
" <td>4234</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3908</th>\n", | ||
" <td>1931-10-16</td>\n", | ||
" <td>1931-10-16</td>\n", | ||
" <td>1931-10-16</td>\n", | ||
" <td>1931-10-16</td>\n", | ||
" <td>Filmvorführung von Der König der Blitzer, 16.1...</td>\n", | ||
" <td>4234</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3909</th>\n", | ||
" <td>1931-10-19</td>\n", | ||
" <td>1931-10-19</td>\n", | ||
" <td>1931-10-19</td>\n", | ||
" <td>1931-10-19</td>\n", | ||
" <td>Filmvorführung von Café Paradies, 19.10.1931</td>\n", | ||
" <td>4234</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"<p>3910 rows × 6 columns</p>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" start-date end-date start-date-written end-date-written \\\n", | ||
"0 1876-03-15 1876-03-15 1876-03-15 1876-03-15 \n", | ||
"1 1876-04-02 1876-04-02 1876-04-02 1876-04-02 \n", | ||
"2 1876-04-27 1876-04-27 1876-04-27 1876-04-27 \n", | ||
"3 1876-05-08 1876-05-08 1876-05-08 1876-05-08 \n", | ||
"4 1876-06-29 1876-06-29 1876-06-29 1876-06-29 \n", | ||
"... ... ... ... ... \n", | ||
"3905 1931-10-09 1931-10-09 1931-10-09 1931-10-09 \n", | ||
"3906 1931-10-11 1931-10-11 1931-10-11 1931-10-11 \n", | ||
"3907 1931-10-12 1931-10-12 1931-10-12 1931-10-12 \n", | ||
"3908 1931-10-16 1931-10-16 1931-10-16 1931-10-16 \n", | ||
"3909 1931-10-19 1931-10-19 1931-10-19 1931-10-19 \n", | ||
"\n", | ||
" title eventType \n", | ||
"0 Aufführung von Das heiß Eysen; Die ehrlich Bäc... 1200 \n", | ||
"1 Gesellschaftskonzert, 2.4.1876 4302 \n", | ||
"2 Aufführung von Götz von Berlichingen, 27.4.1876 1200 \n", | ||
"3 Aufführung von Uriel Acosta. Trauerspiel in fü... 1200 \n", | ||
"4 Aufführung von Die Hugenotten, 29.6.1876 1200 \n", | ||
"... ... ... \n", | ||
"3905 Filmvorführung von Razzia auf Liebe, 9.10.1931 4234 \n", | ||
"3906 Filmvorführung von Eva, 11.10.1931 4234 \n", | ||
"3907 Filmvorführung von Purpur und Waschblau, 12.10... 4234 \n", | ||
"3908 Filmvorführung von Der König der Blitzer, 16.1... 4234 \n", | ||
"3909 Filmvorführung von Café Paradies, 19.10.1931 4234 \n", | ||
"\n", | ||
"[3910 rows x 6 columns]" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "96d77edf-cca9-4d27-ac33-6d101865a9d0", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"100%|███████████████████████████████████████████████████████████████████████| 3910/3910 [12:54<00:00, 5.05it/s]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"pmb_ids = []\n", | ||
"for i, row in tqdm(df.iterrows(), total=len(df)):\n", | ||
" event_type = EventType.objects.get(id=row[\"eventType\"].split(\" \")[0])\n", | ||
" item, _ = Event.objects.get_or_create(\n", | ||
" name=row[\"title\"],\n", | ||
" start_date_written=row[\"start-date\"],\n", | ||
" kind=event_type\n", | ||
" )\n", | ||
" item.collection.add(col)\n", | ||
" item.collection.add(temp_col)\n", | ||
" pmb_ids.append([i, f\"{item.start_date}\", item.name, item.id])\n", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "74861981-9b45-49af-a3e8-aeddd139b0b4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"new_df = pd.DataFrame(pmb_ids)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "f7329d46-ab6b-4ecc-a518-1872012576a4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df[\"pmb_ids\"] = new_df[3]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "c81f0485-e6fc-477d-9cad-e75068a8d28f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df.to_csv(\"events-pmb_ids.csv\", index=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ca6a59bb-c8a1-45ef-8797-ba1012c7bc9f", | ||
"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 | ||
} |
Oops, something went wrong.