diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e5e69a --- /dev/null +++ b/.gitignore @@ -0,0 +1,140 @@ +# Editors +.vscode/ +.idea/ + +# Vagrant +.vagrant/ + +# Mac/OSX +.DS_Store + +# Windows +Thumbs.db + +# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +dist_chrome/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# node +node_modules/ + +# latex files +*.aux +*.out +*.log +*.toc + +exercices/ +ficall (1).pdf +ficall.tex +fic00097.pdf +/exemples diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c97ef3 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +TEX=pdflatex +SRC=essaie.tex +OUTDIR=output +OUTPDF=$(OUTDIR)/essaie.pdf + +all: + @mkdir -p $(OUTDIR) + $(TEX) -output-directory=$(OUTDIR) $(SRC) + +clean: + rm -rf $(OUTDIR)/*.aux $(OUTDIR)/*.log $(OUTDIR)/*.pdf + +.PHONY: all clean \ No newline at end of file diff --git a/assets/Icone_etoile.png b/assets/Icone_etoile.png new file mode 100644 index 0000000..a060d90 Binary files /dev/null and b/assets/Icone_etoile.png differ diff --git a/essaie.tex b/essaie.tex index e31c457..c6cc0dd 100644 --- a/essaie.tex +++ b/essaie.tex @@ -1,7 +1,7 @@ \documentclass[11pt,a4paper]{article} \usepackage{amsfonts,amsmath,amssymb,amsthm} \usepackage[utf8]{inputenc} -\usepackage{fontenc} +\usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{mathptmx} \usepackage{fancybox} @@ -10,11 +10,11 @@ \usepackage{tikz} \usepackage{hyperref} \hypersetup{ - colorlinks=true, - linkcolor=blue, - urlcolor=blue, - pdftitle={Exo7 - Exercices de mathématiques}, - pdfauthor={Exo7} + colorlinks=true, + linkcolor=blue, + urlcolor=blue, + pdftitle={Exercices de mathématiques}, + pdfauthor={Noham Rivoirard} } \usepackage{geometry} \geometry{top=2cm, bottom=2cm, left=2cm, right=2cm} @@ -42,16 +42,16 @@ % Modified to include variable number of stars and optional title \newcommand{\enonce}[2]{% \refstepcounter{exo}% -\edef\currentexonum{\theexo}% +\expandafter\edef\csname exoNum@\exoref\endcsname{\theexo}% \hypertarget{exo7:\exoref}{}\label{exo7:\exoref}% {\bf Exercice \arabic{exo}}~\printStars{\exostars}\ \ \ifthenelse{\equal{\exotitle}{}}{#2}{\textbf{\exotitle} -- #2}\vspace{1mm}\hrule\vspace{1mm}% -} +} % Command to print stars using TikZ foreach \newcommand{\printStars}[1]{% \foreach \i in {1,...,#1} {% - \includegraphics[height=1em]{Icone_etoile.png}% + \includegraphics[height=1em]{assets/Icone_etoile.png}% }% } @@ -61,15 +61,47 @@ \ifthenelse{\equal{\ref{cor7:#1}}{\ref{bidon}}}{}{\hyperlink{cor7:#1}{\texttt{Correction} $\blacktriangledown$}}}}% \hfill{\scriptsize\texttt{[#1]}}\vspace{1mm}\hrule\vspace*{7mm}% } -\newcommand{\indication}[1]{\hypertarget{ind7:#1}{}\label{ind7:#1}{\bf Indication pour \hyperlink{exo7:#1}{l'exercice \currentexonum $\blacktriangle$}}\vspace{1mm}\hrule\vspace{1mm}} +\newcommand{\indication}[1]{% +\hypertarget{ind7:#1}{}\label{ind7:#1}% +{\bf Indication pour \hyperlink{exo7:#1}{l'exercice \csname exoNum@#1\endcsname\ $\blacktriangle$}}\vspace{1mm}\hrule\vspace{1mm}} +\newcommand{\correction}[1]{% +\hypertarget{cor7:#1}{}\label{cor7:#1}% +{\bf Correction de \hyperlink{exo7:#1}{l'exercice \csname exoNum@#1\endcsname\ $\blacktriangle$}}\vspace{1mm}\hrule\vspace{1mm}} \newcommand{\finindication}{\vspace{1mm}\hrule\vspace*{7mm}} -\newcommand{\correction}[1]{\hypertarget{cor7:#1}{}\label{cor7:#1}{\bf Correction de \hyperlink{exo7:#1}{l'exercice \currentexonum $\blacktriangle$}}\vspace{1mm}\hrule\vspace{1mm}} \newcommand{\fincorrection}{\vspace{1mm}\hrule\vspace*{7mm}} \newcommand{\finenonces}{\newpage} \newcommand{\finindications}{\newpage} \newcommand{\fiche}[1]{} \newcommand{\finfiche}{} \newcommand{\addcommand}[1]{} +% Bibmath commands +\newcommand{\mcm}{\mathcal{M}} +\newcommand{\mcc}{\mathcal{C}} +\newcommand{\mcmn}{\mathcal{M}} +\newcommand{\mcmnr}{\mathcal{M}_n(\mtr)} +\newcommand{\mcmnk}{\mathcal{M}_n(\mtk)} +\newcommand{\mcsn}{\mathcal{S}_n} +\newcommand{\mcs}{\mathcal{S}} +\newcommand{\mcd}{\mathcal{D}} +\newcommand{\mcsns}{\mathcal{S}_n^{++}} +\newcommand{\glnk}{GL_n(\mtk)} +\newcommand{\mnr}{\mathcal{M}_n(\mtr)}\DeclareMathOperator{\ch}{ch} +\DeclareMathOperator{\sh}{sh} +\DeclareMathOperator{\vect}{vect}\DeclareMathOperator{\card}{card} +\DeclareMathOperator{\comat}{comat}\DeclareMathOperator{\imv}{Im} +\DeclareMathOperator{\rang}{rg} +\DeclareMathOperator{\Fr}{Fr} +\DeclareMathOperator{\diam}{diam} +\DeclareMathOperator{\supp}{supp} +\newcommand{\veps}{\varepsilon} +\newcommand{\mcu}{\mathcal{U}} +\newcommand{\mcun}{\mcu_n} +\newcommand{\dis}{\displaystyle} +\newcommand{\croouv}{[\![} +\newcommand{\crofer}{]\!]} +\newcommand{\rab}{\mathcal{R}(a,b)} +\newcommand{\pss}[2]{\langle #1,#2\rangle} + % End of preamble \usepackage{graphics} \usepackage[all]{xy} @@ -84,17 +116,31 @@ Enoncé de l'exercice.. \finenonce{000001} \finexercice +\exercice{000002, bodin, 1998/09/01, 2, Titre de l'exercice} +\enonce{000002}{} +Enoncé de l'exercice.. +\finenonce{000002} +\finexercice + \newpage \indication{000001} Indication de l'exercice.. \finindication +\indication{000002} +Indication de l'exercice.. +\finindication + \newpage \correction{000001} Correction de l'exercice.. \fincorrection +\correction{000002} +Correction de l'exercice.. +\fincorrection + \end{document} \ No newline at end of file diff --git a/grab.py b/grab.py new file mode 100644 index 0000000..1c80273 --- /dev/null +++ b/grab.py @@ -0,0 +1,81 @@ +from bs4 import BeautifulSoup +import requests +import urllib.parse as urlparse + +headers = { + 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8', + 'accept-language': 'fr-FR,fr;q=0.7', + 'cache-control': 'no-cache', + 'pragma': 'no-cache', + 'priority': 'u=0, i', + 'sec-ch-ua': '"Brave";v="131", "Chromium";v="131", "Not_A Brand";v="24"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"macOS"', + 'sec-fetch-dest': 'document', + 'sec-fetch-mode': 'navigate', + 'sec-fetch-site': 'same-origin', + 'sec-fetch-user': '?1', + 'sec-gpc': '1', + 'upgrade-insecure-requests': '1', + 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', +} + +params = { + 'action': 'affiche', + 'quoi': 'mpsi/feuillesexo/matrices', + 'type': 'fexo', +} + +response = requests.get('https://bibmath.net/ressources/index.php', headers=headers, params=params) + +if response.status_code == 200: + soup = BeautifulSoup(response.text, 'html.parser') + article = soup.find('article', id='contenugauche') + if article: + title = article.find('h1').get_text(strip=True) + print(f"Title: {title}") + + # Find all part titles + part_titles = article.find_all('div', class_='titrepartie') + for part in part_titles: + part_text = part.get_text(strip=True) + print(f"Part of the File: {part_text}") + + exercises = article.find_all('div', class_='exo') + for exo in exercises: + exo_title_div = exo.find('div', class_='titreexo') + + exercise_number = exo_title_div.find_all('span')[1].text.strip() + title_start = exo_title_div.text.find(' - ') + 3 + title_end = exo_title_div.text.find('[Signaler une erreur]') + exercise_title = exo_title_div.text[title_start:title_end].strip() + + error_link = exo_title_div.find('a', href=lambda href: href and 'signalerreur.php' in href)['href'] + parsed_url = urlparse.urlparse(error_link) + exercise_id = urlparse.parse_qs(parsed_url.query)['numero'][0] + + stars_count = len(exo_title_div.find_all('img')) + + enonce = exo.find('div', class_='enonce').find('div', class_='inner').get_text(strip=True) + indication_div = exo.find('div', class_='indication') + indication = ( + indication_div.find('div', class_='inner').get_text(strip=True) + if indication_div else "No indication" + ) + + answer_div = exo.find('div', class_='corrige') + answer = ( + answer_div.find('div', class_='inner').get_text(strip=True) + if answer_div else "No answer" + ) + # print(f"Exercise Number: {exercise_number}") + # print(f"Exercise Title: {exercise_title}") + # print(f"Exercise ID: {exercise_id}") + # print(f"Stars: {stars_count} stars") + # print(f"Enonce: {enonce}") + # print(f"Indication: {indication}") + # print(f"Answer: {answer}") + else: + print("Article with id 'contenugauche' not found.") +else: + print(f"Request failed with status code: {response.status_code}") \ No newline at end of file diff --git a/output/essaie.pdf b/output/essaie.pdf new file mode 100644 index 0000000..2334d4f Binary files /dev/null and b/output/essaie.pdf differ diff --git a/parts/footer.tex b/parts/footer.tex new file mode 100644 index 0000000..815ab68 --- /dev/null +++ b/parts/footer.tex @@ -0,0 +1 @@ +\end{document} \ No newline at end of file diff --git a/parts/header.tex b/parts/header.tex new file mode 100644 index 0000000..5bb4d42 --- /dev/null +++ b/parts/header.tex @@ -0,0 +1,110 @@ +\documentclass[11pt,a4paper]{article} +\usepackage{amsfonts,amsmath,amssymb,amsthm} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage[french]{babel} +\usepackage{mathptmx} +\usepackage{fancybox} +\usepackage{graphicx} +\usepackage{ifthen} +\usepackage{tikz} +\usepackage{hyperref} +\hypersetup{ + colorlinks=true, + linkcolor=blue, + urlcolor=blue, + pdftitle={Exercices de mathématiques}, + pdfauthor={Noham Rivoirard} +} +\usepackage{geometry} +\geometry{top=2cm, bottom=2cm, left=2cm, right=2cm} + +% Modified to extract number of stars and title +\newcommand{\exercice}[1]{% + \def\exoargs{#1}% + \expandafter\parseexoargs\exoargs,,,,,\@nil% +} + +\def\parseexoargs#1,#2,#3,#4,#5,#6\@nil{% + \def\exoref{#1}% + \def\exoauthor{#2}% + \def\exodate{#3}% + \def\exostars{#4}% + \def\exotitle{#5}% +} + +\newcommand{\finexercice}{} +\newcommand{\noindication}{} +\newcommand{\nocorrection}{} +\newcounter{exo} +\newcommand{\currentexonum}{} % mémoire temporaire + +% Modified to include variable number of stars and optional title +\newcommand{\enonce}[2]{% +\refstepcounter{exo}% +\expandafter\edef\csname exoNum@\exoref\endcsname{\theexo}% +\hypertarget{exo7:\exoref}{}\label{exo7:\exoref}% + {\bf Exercice \arabic{exo}}~\printStars{\exostars}\ \ + \ifthenelse{\equal{\exotitle}{}}{#2}{\textbf{\exotitle} -- #2}\vspace{1mm}\hrule\vspace{1mm}% +} + +% Command to print stars using TikZ foreach +\newcommand{\printStars}[1]{% + \foreach \i in {1,...,#1} {% + \includegraphics[height=1em]{assets/Icone_etoile.png}% + }% +} + +\newcommand{\finenonce}[1]{% +\ifthenelse{\equal{\ref{ind7:#1}}{\ref{bidon}}\and\equal{\ref{cor7:#1}}{\ref{bidon}}}{}{\par{\footnotesize +\ifthenelse{\equal{\ref{ind7:#1}}{\ref{bidon}}}{}{\hyperlink{ind7:#1}{\texttt{Indication} $\blacktriangledown$}\qquad} +\ifthenelse{\equal{\ref{cor7:#1}}{\ref{bidon}}}{}{\hyperlink{cor7:#1}{\texttt{Correction} $\blacktriangledown$}}}}% +\hfill{\scriptsize\texttt{[#1]}}\vspace{1mm}\hrule\vspace*{7mm}% +} +\newcommand{\indication}[1]{% +\hypertarget{ind7:#1}{}\label{ind7:#1}% +{\bf Indication pour \hyperlink{exo7:#1}{l'exercice \csname exoNum@#1\endcsname\ $\blacktriangle$}}\vspace{1mm}\hrule\vspace{1mm}} +\newcommand{\correction}[1]{% +\hypertarget{cor7:#1}{}\label{cor7:#1}% +{\bf Correction de \hyperlink{exo7:#1}{l'exercice \csname exoNum@#1\endcsname\ $\blacktriangle$}}\vspace{1mm}\hrule\vspace{1mm}} +\newcommand{\finindication}{\vspace{1mm}\hrule\vspace*{7mm}} +\newcommand{\fincorrection}{\vspace{1mm}\hrule\vspace*{7mm}} +\newcommand{\finenonces}{\newpage} +\newcommand{\finindications}{\newpage} +\newcommand{\fiche}[1]{} \newcommand{\finfiche}{} +\newcommand{\addcommand}[1]{} + +% Bibmath commands +\newcommand{\mcm}{\mathcal{M}} +\newcommand{\mcc}{\mathcal{C}} +\newcommand{\mcmn}{\mathcal{M}} +\newcommand{\mcmnr}{\mathcal{M}_n(\mtr)} +\newcommand{\mcmnk}{\mathcal{M}_n(\mtk)} +\newcommand{\mcsn}{\mathcal{S}_n} +\newcommand{\mcs}{\mathcal{S}} +\newcommand{\mcd}{\mathcal{D}} +\newcommand{\mcsns}{\mathcal{S}_n^{++}} +\newcommand{\glnk}{GL_n(\mtk)} +\newcommand{\mnr}{\mathcal{M}_n(\mtr)}\DeclareMathOperator{\ch}{ch} +\DeclareMathOperator{\sh}{sh} +\DeclareMathOperator{\vect}{vect}\DeclareMathOperator{\card}{card} +\DeclareMathOperator{\comat}{comat}\DeclareMathOperator{\imv}{Im} +\DeclareMathOperator{\rang}{rg} +\DeclareMathOperator{\Fr}{Fr} +\DeclareMathOperator{\diam}{diam} +\DeclareMathOperator{\supp}{supp} +\newcommand{\veps}{\varepsilon} +\newcommand{\mcu}{\mathcal{U}} +\newcommand{\mcun}{\mcu_n} +\newcommand{\dis}{\displaystyle} +\newcommand{\croouv}{[\![} +\newcommand{\crofer}{]\!]} +\newcommand{\rab}{\mathcal{R}(a,b)} +\newcommand{\pss}[2]{\langle #1,#2\rangle} + +% End of preamble +\usepackage{graphics} +\usepackage[all]{xy} + + +\begin{document} \ No newline at end of file