mirror of
https://github.com/NohamR/Manuel.git
synced 2025-05-24 00:49:10 +00:00
2 lines
17 KiB
Plaintext
2 lines
17 KiB
Plaintext
{"cells":[{"cell_type":"code","execution_count":1,"metadata":{"cellView":"form","colab":{"base_uri":"https://localhost:8080/","height":375},"executionInfo":{"elapsed":7,"status":"error","timestamp":1680434191416,"user":{"displayName":"Ghjklm G","userId":"09208431433424498357"},"user_tz":-120},"id":"Q_VOKTuxaUwS","outputId":"41dcdd09-f7a8-469d-c660-422034f0a6ed"},"outputs":[{"ename":"MessageError","evalue":"ignored","output_type":"error","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mMessageError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-1-c44a46ee5c51>\u001b[0m in \u001b[0;36m<cell line: 15>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msystem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'sudo apt install /usr/bin/wkhtmltox_0.12.6-1.bionic_amd64.deb'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mgoogle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolab\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mdrive\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mdrive\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/content/gdrive'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msystem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'pip install git+https://github.com/Wyattjoh/pushover'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.9/dist-packages/google/colab/drive.py\u001b[0m in \u001b[0;36mmount\u001b[0;34m(mountpoint, force_remount, timeout_ms, readonly)\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmountpoint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mforce_remount\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_ms\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m120000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreadonly\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[0;34m\"\"\"Mount your Google Drive at the specified mountpoint path.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 103\u001b[0;31m return _mount(\n\u001b[0m\u001b[1;32m 104\u001b[0m \u001b[0mmountpoint\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0mforce_remount\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mforce_remount\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.9/dist-packages/google/colab/drive.py\u001b[0m in \u001b[0;36m_mount\u001b[0;34m(mountpoint, force_remount, timeout_ms, ephemeral, readonly)\u001b[0m\n\u001b[1;32m 130\u001b[0m )\n\u001b[1;32m 131\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mephemeral\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 132\u001b[0;31m _message.blocking_request(\n\u001b[0m\u001b[1;32m 133\u001b[0m \u001b[0;34m'request_auth'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrequest\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m'authType'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'dfs_ephemeral'\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_sec\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 134\u001b[0m )\n","\u001b[0;32m/usr/local/lib/python3.9/dist-packages/google/colab/_message.py\u001b[0m in \u001b[0;36mblocking_request\u001b[0;34m(request_type, request, timeout_sec, parent)\u001b[0m\n\u001b[1;32m 175\u001b[0m \u001b[0mrequest_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrequest\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparent\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparent\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpect_reply\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 176\u001b[0m )\n\u001b[0;32m--> 177\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mread_reply_from_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrequest_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_sec\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/usr/local/lib/python3.9/dist-packages/google/colab/_message.py\u001b[0m in \u001b[0;36mread_reply_from_input\u001b[0;34m(message_id, timeout_sec)\u001b[0m\n\u001b[1;32m 102\u001b[0m ):\n\u001b[1;32m 103\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'error'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mreply\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 104\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mMessageError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreply\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'error'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 105\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mreply\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'data'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 106\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mMessageError\u001b[0m: Error: credential propagation was unsuccessful"]}],"source":["#@title Initialisation\n","!pip install pdfkit\n","!pip install pypdf\n","!mkdir gen\n","!chmod 777 /root/content/Manuel/wkhtmltopdf.exe\n","!cat /etc/os-release\n","!pip install pdfkit\n","\n","!wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb\n","\n","!cp wkhtmltox_0.12.6-1.bionic_amd64.deb /usr/bin\n","\n","!sudo apt install /usr/bin/wkhtmltox_0.12.6-1.bionic_amd64.deb\n","from google.colab import drive\n","drive.mount('/content/gdrive')\n","!pip install git+https://github.com/Wyattjoh/pushover"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"QoAsZb7mcKOZ"},"outputs":[],"source":["!mkdir /root/\n","!mkdir /root/content/\n","!mkdir /root/content/Manuel/\n","!mkdir /root/content/Manuel/gen/\n","!ls /root/content/Manuel/gen/\n","#be sure it return true "]},{"cell_type":"code","execution_count":2,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":189},"executionInfo":{"elapsed":450,"status":"error","timestamp":1680434256652,"user":{"displayName":"Ghjklm G","userId":"09208431433424498357"},"user_tz":-120},"id":"0lBO9lBT8o7q","outputId":"033fe8e9-0ebf-47d1-828c-6fffb4baa585"},"outputs":[{"ename":"NameError","evalue":"ignored","output_type":"error","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-2-b89e895eb6fe>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpdfkit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_url\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"https://exobank.hachette-livre.fr/contents/final/9782017102106-fxl/OEBPS/Page_1.html?interface=postMessage\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"/root/content/Manuel/out.pdf\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mNameError\u001b[0m: name 'pdfkit' is not defined"]}],"source":["pdfkit.from_url(\"https://exobank.hachette-livre.fr/contents/final/9782017102106-fxl/OEBPS/Page_1.html?interface=postMessage\", \"/root/content/Manuel/out.pdf\")"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":132814,"status":"ok","timestamp":1680379287318,"user":{"displayName":"Ghjklm G","userId":"09208431433424498357"},"user_tz":-120},"id":"a1_iqy6WaIfD","outputId":"54588e2f-defc-4db5-d4ff-2b85d276bf6a"},"outputs":[{"name":"stdout","output_type":"stream","text":["eleve.pdf gdrive gen\tsample_data wkhtmltox_0.12.6-1.bionic_amd64.deb\n","Quel est l'id eleve ? 9782016291894\n","Quelle est l'édition ? \n","Quel est le nombre de pages ? 416\n","Quel est l'id professeur ? 9782016291900\n","Quel est le nom du manuel ? Histoire-Géographie-EMC 4e - Ed. 2021 Plaza\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_386.html\n","386/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_387.html\n","387/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_388.html\n","388/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_389.html\n","389/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_390.html\n","390/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_391.html\n","391/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_392.html\n","392/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_393.html\n","393/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_394.html\n","394/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_395.html\n","395/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_396.html\n","396/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_397.html\n","397/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_398.html\n","398/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_399.html\n","399/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_400.html\n","400/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_401.html\n","401/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_402.html\n","402/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_403.html\n","403/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_404.html\n","404/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_405.html\n","405/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_406.html\n","406/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_407.html\n","407/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_408.html\n","408/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_409.html\n","409/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_410.html\n","410/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_411.html\n","411/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_412.html\n","412/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_413.html\n","413/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_414.html\n","414/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_415.html\n","415/416\n","https://exobank.hachette-livre.fr/contents/final/9782016291900-fxl/OEBPS/Page_416.html\n","416/416\n","Gen pdfs en 116.2006 secondes\n","Gen pdf unique en 16.0256 secondes\n","Tout en 132.2262 secondes\n","DONE\n","\n","Histoire-Géographie-EMC 4e - Ed. 2021 Plaza\n"]},{"data":{"text/plain":["True"]},"execution_count":21,"metadata":{},"output_type":"execute_result"}],"source":["#@title Code\n","import pdfkit\n","import re\n","\n","from pushover import Pushover\n","from pdfkit.api import configuration\n","from pypdf import PdfMerger\n","import time\n","import os\n","import sys\n","import shutil\n","from tkinter import messagebox\n","\n","toc = time.perf_counter()\n","\n","options = {}\n","# clear(2)\n","!ls\n","\n","id = int(input(\"Quel est l'id eleve ? \"))\n","edition = input(\"Quelle est l'édition ? \")\n","nbpages = int(input(\"Quel est le nombre de pages ? \"))\n","id2 = int(input(\"Quel est l'id professeur ? \"))\n","nomdulivre = input(\"Quel est le nom du manuel ? \")\n","\n","if edition == 'hachette' or edition == '':\n"," debuturl = 'https://exobank.hachette-livre.fr/contents/final/'\n"," finurl = '-fxl/OEBPS/Page_{}.html'\n","elif (edition == 'hatier') or (edition == 'didier'):\n"," debuturl = 'https://exobank.hachette-livre.fr/contents/final/'\n"," finurl = '-fxl/OEBPS/page{}.xhtml?interface=postMessage'\n","else:\n"," print(\"L'édition entrée n'existe pas encore\")\n","\n","url = debuturl + str(id) + finurl\n","# url = \"https://exobank.hachette-livre.fr/contents/final/9782278093472-fxl/OEBPS/page{}.xhtml?interface=postMessage\"\n","output = '/root/content/Manuel/gen/eleve{}.pdf'\n","# for offset in range(1, nbpages + 1, 1):\n","# newurl = url.format(offset)\n","# print(newurl)\n","# newoutput = output.format(offset)\n","# print(str(offset) + \"/\" + str(nbpages))\n","\n","# pdfkit.from_url(newurl, newoutput)\n","\n","# pdfs = '/root/content/Manuel/gen/eleve{}.pdf'\n","# pdfsnewpdfs = []\n","\n","# for offset in range(1, nbpages + 1, 1):\n","# newpdfs = pdfs.format(offset)\n","# pdfsnewpdfs.append(str(newpdfs))\n","# # print(pdfsnewpdfs)\n","\n","# finpage = time.perf_counter()\n","\n","# debutmerge = time.perf_counter()\n","# merger = PdfMerger()\n","\n","# for pdf in pdfsnewpdfs:\n","# merger.append(pdf)\n","\n","# merger.write(\"eleve.pdf\")\n","# merger.close()\n","# finmerge = time.perf_counter()\n","\n","#version prof\n","\n","\n","if edition == 'hachette' or edition == '':\n"," debuturl = 'https://exobank.hachette-livre.fr/contents/final/'\n"," finurl = '-fxl/OEBPS/Page_{}.html'\n","elif (edition == 'hatier') or (edition == 'didier'):\n"," debuturl = 'https://exobank.hachette-livre.fr/contents/final/'\n"," finurl = '-fxl/OEBPS/page{}.xhtml?interface=postMessage'\n","else:\n"," print(\"L'édition entrée n'existe pas encore\")\n","\n","url = debuturl + str(id2) + finurl\n","# url = \"https://exobank.hachette-livre.fr/contents/final/9782278093472-fxl/OEBPS/page{}.xhtml?interface=postMessage\"\n","output = '/root/content/Manuel/gen/prof{}.pdf'\n","for offset in range(386, nbpages + 1, 1):\n"," newurl = url.format(offset)\n"," print(newurl)\n"," newoutput = output.format(offset)\n"," print(str(offset) + \"/\" + str(nbpages))\n","\n"," pdfkit.from_url(newurl, newoutput)\n","\n","pdfs = '/root/content/Manuel/gen/prof{}.pdf'\n","pdfsnewpdfs = []\n","\n","for offset in range(1, nbpages + 1, 1):\n"," newpdfs = pdfs.format(offset)\n"," pdfsnewpdfs.append(str(newpdfs))\n","# print(pdfsnewpdfs)\n","\n","finpage = time.perf_counter()\n","\n","debutmerge = time.perf_counter()\n","merger = PdfMerger()\n","\n","for pdf in pdfsnewpdfs:\n"," merger.append(pdf)\n","\n","merger.write(\"prof.pdf\")\n","merger.close()\n","finmerge = time.perf_counter()\n","\n","# clear(2)\n","print(f\"Gen pdfs en {finpage - toc:0.4f} secondes\")\n","print(f\"Gen pdf unique en {finmerge - debutmerge:0.4f} secondes\")\n","print(f\"Tout en {finmerge - toc:0.4f} secondes\")\n","print('DONE')\n","\n","print(edition)\n","print(nomdulivre)\n","\n","po = Pushover(\"a73uqu1px5w9aq84tnsbcgyf14c7zz\")\n","po.user(\"ub91t4nporrc2nv374ed9kk9nwnd2p\")\n","msg = po.msg(\"Les téléchargements sont terminés\")\n","msg.set(\"title\", \"Finis\")\n","po.send(msg)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":4468,"status":"ok","timestamp":1680379380281,"user":{"displayName":"Ghjklm G","userId":"09208431433424498357"},"user_tz":-120},"id":"xXQewjziafxv","outputId":"5d0f2649-5490-4961-c916-179068e66b53"},"outputs":[{"name":"stdout","output_type":"stream","text":["Quel est le nom du livre ?test\n"]}],"source":["nomdulivre = input(\"Quel est le nom du livre ?\")\n","! mkdir nomdulivre"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyM0RR0xQd14H7d+wWpbuv6z","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.9"}},"nbformat":4,"nbformat_minor":0}
|