{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "90790e0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "77970eb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "htmfiles = glob.glob(\"*\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1120bdff",
   "metadata": {},
   "outputs": [],
   "source": [
    "replaces = glob.glob(\"../_includes/gif/*\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6f5a2859",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'../_includes/gif/c_l-gif.html'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "replaces[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "058dd70f",
   "metadata": {},
   "outputs": [],
   "source": [
    "for htmlfile in htmfiles:\n",
    "    with open(htmlfile, \"r\") as fin:\n",
    "        text=fin.read()\n",
    "        for replacement in replaces:\n",
    "            with open(replacement, \"r\") as fin:\n",
    "                result=fin.read().strip(\"\\n\")\n",
    "            text=text.replace(\"{{%- include gif/{} -%}}\".format(replacement.split(\"/\")[-1]), result)\n",
    "        with open(\"../replaced/{}\".format(htmlfile.split(\"/\")[-1]), \"w+\") as fout:\n",
    "            fout.write(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "57ab8419",
   "metadata": {},
   "outputs": [],
   "source": [
    "for htmlfile in [htmfiles[0]]:\n",
    "    with open(htmlfile, \"r\") as fin:\n",
    "        currentfile=fin.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2ad3206b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'---\\nlayout: page\\ntitle: Примеры слов. Модели \"однополых\" имен — часть 5\\nprevurl: \"nemen4.htm\"\\nnexturl: \"nemen6.htm\"\\nnumlevel: 3\\nnumtitle: 4.1.5.5. Примеры слов. Модели \"однополых\" имен — часть 5\\n---\\n\\n\\n\\n<table cellspacing=0 class=b width=100%>\\n<tr>\\n<th><font size=2>Значение корня</th>\\n<th width=1%><font size=2>Корень<font size=2>Перевод</th>\\n<th width=1%><font size=2>Слово</th>\\n<th width=1%><font size=2>Модель</th>\\n</tr>\\n<tr>\\n<td valign=top rowspan=15><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/q-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/t-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/l-gif.html -%}</span><br><nobr><sup>{% include ref.html id="1.4.3.4" %}</sup></nobr></td>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/g-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/p9-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>гравюра</td>\\n<td><span class=\"hebsym\">{%- include gif/g-gif.html -%}-{%- include gif/l-gif.html -%}-{%- include gif/p-gif.html -%}</span></td></table></td>\\n<td>гравировать</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/d-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/p0-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/s-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>оттиск</td>\\n<td><span class=\"hebsym\">{%- include gif/d-gif.html -%}-{%- include gif/p-gif.html -%}-{%- include gif/s-gif.html -%}</span></td></table></td>\\n<td>печатать</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/x-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/b0-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/b-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>хобби</td>\\n<td><span class=\"hebsym\">{%- include gif/x-gif.html -%}-{%- include gif/b-gif.html -%}-{%- include gif/b-gif.html -%}</span></td></table></td>\\n<td>симпатия</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/x-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/b0-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/r-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>синтаксис</td>\\n<td><span class=\"hebsym\">{%- include gif/x-gif.html -%}-{%- include gif/b-gif.html -%}-{%- include gif/r-gif.html -%}</span></td></table></td>\\n<td>соединять</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/k-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/sh-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/r-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>препарат</td>\\n<td><span class=\"hebsym\">{%- include gif/k-gif.html -%}-{%- include gif/sh-gif.html -%}-{%- include gif/r-gif.html -%}</span></td></table></td>\\n<td>пригодный</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/k-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/f0-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/b-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>диктат</td>\\n<td><span class=\"hebsym\">{%- include gif/k-gif.html -%}-{%- include gif/f-gif.html -%}-{%- include gif/b-gif.html -%}</span></td></table></td>\\n<td>писать</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/d-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>ученик</td>\\n<td><span class=\"hebsym\">{%- include gif/l-gif.html -%}-{%- include gif/m-gif.html -%}-{%- include gif/d-gif.html -%}</span></td></table></td>\\n<td>учеба</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/m-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/r-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/c9-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>стимул</td>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}-{%- include gif/r-gif.html -%}-{%- include gif/c-gif.html -%}</span></td></table></td>\\n<td>энергия</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/s-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/r-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/t-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>сценарий</td>\\n<td><span class=\"hebsym\">{%- include gif/s-gif.html -%}-{%- include gif/r-gif.html -%}-{%- include gif/t-gif.html -%}</span></td></table></td>\\n<td>лента</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/p-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/q-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/d-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>должность; роль; функция</td>\\n<td><span class=\"hebsym\">{%- include gif/p-gif.html -%}-{%- include gif/q-gif.html -%}-{%- include gif/d-gif.html -%}</span></td></table></td>\\n<td>приказ</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/q-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/t-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>граммофонная пластинка</td>\\n<td><span class=\"hebsym\">{%- include gif/q-gif.html -%}-{%- include gif/l-gif.html -%}-{%- include gif/t-gif.html -%}</span></td></table></td>\\n<td>вбирать</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/q-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/c-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/b-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>бюджет</td>\\n<td><span class=\"hebsym\">{%- include gif/q-gif.html -%}-{%- include gif/c-gif.html -%}-{%- include gif/b-gif.html -%}</span></td></table></td>\\n<td>отрезать</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/r-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/x-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/c9-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>лосьон</td>\\n<td><span class=\"hebsym\">{%- include gif/r-gif.html -%}-{%- include gif/x-gif.html -%}-{%- include gif/c-gif.html -%}</span></td></table></td>\\n<td>мыть</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/r-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/k0-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/z-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>концентрат</td>\\n<td><span class=\"hebsym\">{%- include gif/r-gif.html -%}-{%- include gif/k-gif.html -%}-{%- include gif/z-gif.html -%}</span></td></table></td>\\n<td>сосредотачивать</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/r-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/sh-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/y-gif.html -%}{%- include gif/m9-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>эскиз</td>\\n<td><span class=\"hebsym\">{%- include gif/r-gif.html -%}-{%- include gif/sh-gif.html -%}-{%- include gif/m-gif.html -%}</span></td></table></td>\\n<td>записывать</td>\\n</tr>\\n<tr>\\n<td valign=top rowspan=5><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/q-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/t-gif.html -%}{%- include gif/v0-gif.html -%}{%- include gif/l-gif.html -%}</span><br><nobr><sup>{% include ref.html id="1.4.3.4" %}</sup></nobr></td>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/g-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/m-gif.html -%}{%- include gif/v0-gif.html -%}{%- include gif/l-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>компенсация</td>\\n<td><span class=\"hebsym\">{%- include gif/g-gif.html -%}-{%- include gif/m-gif.html -%}-{%- include gif/l-gif.html -%}</span></td></table></td>\\n<td>воздаяние, пенсия</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/m-gif.html -%}{%- include gif/v0-gif.html -%}{%- include gif/d-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>Талмуд</td>\\n<td><span class=\"hebsym\">{%- include gif/l-gif.html -%}-{%- include gif/m-gif.html -%}-{%- include gif/d-gif.html -%}</span></td></table></td>\\n<td>учеба</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/m-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/r-gif.html -%}{%- include gif/v0-gif.html -%}{%- include gif/q-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>косметика</td>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}-{%- include gif/r-gif.html -%}-{%- include gif/q-gif.html -%}</span></td></table></td>\\n<td>лоск</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/c-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/v0-gif.html -%}{%- include gif/m9-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>фотоснимок</td>\\n<td><span class=\"hebsym\">{%- include gif/c-gif.html -%}-{%- include gif/l-gif.html -%}-{%- include gif/m-gif.html -%}</span></td></table></td>\\n<td>фото</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/f0-gif.html -%}{%- include gif/a3-gif.html -%}{%- include gif/sh-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/v0-gif.html -%}{%- include gif/m9-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>выплата</td>\\n<td><span class=\"hebsym\">{%- include gif/sh-gif.html -%}-{%- include gif/l-gif.html -%}-{%- include gif/m-gif.html -%}</span></td></table></td>\\n<td>целый</td>\\n</tr>\\n<tr>\\n<td valign=top rowspan=5><span class=\"hebsym\">{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/q-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/t-gif.html -%}{%- include gif/o1-gif.html -%}{%- include gif/l-gif.html -%}</span><br><nobr><sup>{% include ref.html id="1.4.3.4" %}</sup></nobr></td>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/b-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/d0-gif.html -%}{%- include gif/o1-gif.html -%}{%- include gif/q-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>док</td>\\n<td><span class=\"hebsym\">{%- include gif/b-gif.html -%}-{%- include gif/d-gif.html -%}-{%- include gif/q-gif.html -%}</span></td></table></td>\\n<td>проверка</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/k-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/x-gif.html -%}{%- include gif/o1-gif.html -%}{%- include gif/l-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>кисточка</td>\\n<td><span class=\"hebsym\">{%- include gif/k-gif.html -%}-{%- include gif/x-gif.html -%}-{%- include gif/l-gif.html -%}</span></td></table></td>\\n<td>синий</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/k-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/l-gif.html -%}{%- include gif/o1-gif.html -%}{%- include gif/l-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>совокупность</td>\\n<td><span class=\"hebsym\">{%- include gif/k-gif.html -%}-{%- include gif/l-gif.html -%}-{%- include gif/l-gif.html -%}</span></td></table></td>\\n<td>всё</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/k-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/sh-gif.html -%}{%- include gif/o1-gif.html -%}{%- include gif/l-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>препятствие</td>\\n<td><span class=\"hebsym\">{%- include gif/k-gif.html -%}-{%- include gif/sh-gif.html -%}-{%- include gif/l-gif.html -%}</span></td></table></td>\\n<td>неудача</td>\\n</tr>\\n<tr>\\n<td><span class=\"hebsym\">{%- include gif/m-gif.html -%}{%- include gif/i3-gif.html -%}{%- include gif/s-gif.html -%}{%- include gif/w-gif.html -%}{%- include gif/f0-gif.html -%}{%- include gif/o1-gif.html -%}{%- include gif/r-gif.html -%}</span></td>\\n<td><table cellpadding=0 cellspacing=1 align=right>\\n<td>тайник</td>\\n<td><span class=\"hebsym\">{%- include gif/s-gif.html -%}-{%- include gif/f-gif.html -%}-{%- include gif/r-gif.html -%}</span></td></table></td>\\n<td>заслонять</td>\\n</tr></table>\\n'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "currentfile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "243193ce",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
