Skip to content

Commit

Permalink
Notebook for setting gallery dates
Browse files Browse the repository at this point in the history
  • Loading branch information
MinasukiHikimuna committed Aug 30, 2024
1 parent 1506032 commit 827a3aa
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions pandas/gallery_dates.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import dotenv\n",
"import os\n",
"from libraries.client_stashapp import get_stashapp_client\n",
"from libraries.StashDbClient import StashDbClient\n",
"\n",
"dotenv.load_dotenv()\n",
"\n",
"stash = get_stashapp_client()\n",
"\n",
"stashbox_client = StashDbClient(\n",
" os.getenv(\"STASHDB_ENDPOINT\"),\n",
" os.getenv(\"STASHDB_API_KEY\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"galleries = stash.find_galleries()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_galleries = pd.DataFrame(galleries)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Filter galleries with a single file\n",
"df_single_file_galleries = df_galleries[df_galleries['files'].apply(lambda x: len(x) == 1)].copy()\n",
"\n",
"# Extract basename of the single file\n",
"df_single_file_galleries.loc[:, 'file_basename'] = df_single_file_galleries['files'].apply(lambda x: os.path.basename(x[0]['basename']))\n",
"\n",
"# Reset index for cleaner output\n",
"df_single_file_galleries = df_single_file_galleries.reset_index(drop=True)\n",
"\n",
"# Select only the specified columns\n",
"df_single_file_galleries = df_single_file_galleries[['id', 'date', 'title', 'file_basename']]\n",
"\n",
"# Parse date from file_basename and create a new column\n",
"df_single_file_galleries['parsed_date'] = df_single_file_galleries['file_basename'].str.extract(r'(\\d{4}-\\d{2}-\\d{2})')[0]\n",
"\n",
"df_single_file_galleries = df_single_file_galleries[(df_single_file_galleries['date'].isna()) & ((df_single_file_galleries['parsed_date'].notna()) & (df_single_file_galleries['parsed_date'] != \"0001-01-01\"))]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for index, row in df_single_file_galleries.iterrows():\n",
" stash.update_gallery({\n",
" \"id\": row[\"id\"],\n",
" \"date\": row[\"parsed_date\"]\n",
" })"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pandas",
"language": "python",
"name": "python3"
},
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 827a3aa

Please sign in to comment.