Version initiale testée avec Mission Cybersécurité

This commit is contained in:
François Pelletier 2023-06-17 00:41:32 -04:00
parent 7da7c29d99
commit eca7b20373
6 changed files with 496 additions and 86 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/parametres.py
/venv/
/.idea/
/html/

View file

@ -1,92 +1,12 @@
# Backup Thrivecart Learn
# Sauvegarde d'une formation ThriveCart Learn
Depuis un navigateur, va dans les outils de développeur (touche F12), puis connecte toi à ta formation avec un compte apprenant (inscris-toi à ta formation avec un code rabais de 100%, le compte "John Smith" ne fonctionne pas).
Tu devrais voir dans la section Réseau (Network en anglais) une page avec le nom de ta formation en haut de la liste. Clique dessus, et tu devrais voir les informations de la capture ci-dessous
## Getting started
![](informations.png)
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Ensuite, complète les premières section du notebook, puis tu devrais pouvoir l'exécuter d'un seul coup
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
La sauvegarde va être dans le dossier html
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://git.jevalide.ca/gitlab/partage/backup-thrivecart-learn.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.jevalide.ca/gitlab/partage/backup-thrivecart-learn/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

BIN
informations.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 KiB

88
requirements.txt Normal file
View file

@ -0,0 +1,88 @@
anyio==3.7.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens==2.2.1
attrs==23.1.0
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
comm==0.1.3
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
executing==1.2.0
fastjsonschema==2.17.1
fqdn==1.5.1
idna==3.4
ipykernel==6.23.2
ipython==8.14.0
ipython-genutils==0.2.0
ipywidgets==8.0.6
isoduration==20.11.0
jedi==0.18.2
Jinja2==3.1.2
jsonpointer==2.4
jsonschema==4.17.3
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.6.3
jupyter_client==8.2.0
jupyter_core==5.3.1
jupyter_server==2.6.0
jupyter_server_terminals==0.4.4
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.7
MarkupSafe==2.1.3
matplotlib-inline==0.1.6
mistune==2.0.5
nbclassic==1.0.0
nbclient==0.8.0
nbconvert==7.5.0
nbformat==5.9.0
nest-asyncio==1.5.6
notebook==6.5.4
notebook_shim==0.2.3
overrides==7.3.1
packaging==23.1
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
platformdirs==3.5.3
prometheus-client==0.17.0
prompt-toolkit==3.0.38
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.15.1
pyrsistent==0.19.3
python-dateutil==2.8.2
python-json-logger==2.0.7
PyYAML==6.0
pyzmq==25.1.0
qtconsole==5.4.3
QtPy==2.3.1
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
Send2Trash==1.8.2
six==1.16.0
sniffio==1.3.0
soupsieve==2.4.1
stack-data==0.6.2
terminado==0.17.1
tinycss2==1.2.1
tornado==6.3.2
traitlets==5.9.0
uri-template==1.2.0
urllib3==2.0.3
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.3
widgetsnbextension==4.0.7

391
thrivecart-backup.ipynb Normal file
View file

@ -0,0 +1,391 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"## Chargement des informations"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import requests\n",
"from bs4 import BeautifulSoup\n",
"import os"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"from thrivecart_utils import extract_image_filename_thrivecart"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Mettre l'URL de ta formation ici tel qu'accédé par les apprenants. Doit inclure le / à la fin de l'URL.\n",
"\n",
"url = ''"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Mettre ici le User-Agent\n",
"headers = {\n",
" 'User-Agent': ''\n",
"}"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Mettre tous les cookies ici dans un dictionnaire, changer les noms au besoin.\n",
"cookies = {\n",
" 'thrivecart_v2': '',\n",
" '__stripe_mid': '',\n",
" 'tc_account': '',\n",
" 'tcc_v1_23439': ''\n",
"}"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"## Page d'accueil\n",
"\n",
"Dans cette section, on va sauvegarder la page d'accueil de la formation, visible une fois connecté à ThriveCart."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"### Téléchargement de la page"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Send a GET request to the URL with the user agent and cookies\n",
"response_home = requests.get(url, headers=headers, cookies=cookies)\n",
"html_content_home = response_home.text"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"### Enregistrement de la page"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"current_dir = 'html'\n",
"os.makedirs(current_dir, exist_ok=True)\n",
"with open(os.path.join(current_dir,'index.html'), 'w') as f:\n",
" f.write(html_content_home)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"### Soupe de la page"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Create a BeautifulSoup object with the HTML content\n",
"home_soup = BeautifulSoup(html_content_home, 'html.parser')"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"### Téléchargement des images de la page"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Extract all URLs from the page that start with the desired prefix\n",
"home_images_dir = os.path.join(current_dir, 'images')\n",
"os.makedirs(os.path.join(current_dir,'images'), exist_ok=True)\n",
"home_images = []\n",
"for image in home_soup.find_all('img'):\n",
" href = image.get('src')\n",
" home_images.append(href)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Send a GET request to the URL with the user agent and cookies\n",
"for home_image in home_images:\n",
" response_lesson_image = requests.get(home_image, headers=headers, cookies=cookies)\n",
" image_filename = extract_image_filename_thrivecart(home_image)\n",
" if response_lesson_image.status_code == 200:\n",
" # Save the image to a file\n",
" with open(os.path.join(home_images_dir,image_filename), 'wb') as file:\n",
" file.write(response_lesson_image.content)\n",
" print(f\"Image downloaded and saved as {image_filename}\")\n",
" else:\n",
" print(\"Failed to download the image\")"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"## Modules\n",
"\n",
"Dans cette section, on va sauvegarder les modules de la formation, accessible via des liens sur la page d'accueil de la formation."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"### Extraction des URLs des modules depuis la page d'accueil"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Extract all URLs from the page that start with the desired prefix\n",
"module_urls = []\n",
"for link in home_soup.find_all('a'):\n",
" href = link.get('href')\n",
" if href and href.startswith(url) and not href.endswith(url):\n",
" module_urls.append(href)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Process the extracted URLs as per your requirement\n",
"lessons_urls = []\n",
"for module_url in module_urls:\n",
" print(module_url)\n",
"\n",
" # Send a GET request to the URL with the user agent and cookies\n",
" response_module = requests.get(module_url, headers=headers, cookies=cookies)\n",
" html_content_module = response_module.text\n",
"\n",
" # Enregistrement de la page\n",
" current_dir = 'html/modules/'\n",
" current_module = module_url.split('/')[-2]\n",
" os.makedirs(os.path.join(current_dir,\n",
" current_module), exist_ok=True)\n",
" with open(os.path.join(current_dir,current_module,'index.html'), 'w') as f:\n",
" f.write(html_content_module)\n",
"\n",
" # Create a BeautifulSoup object with the HTML content\n",
" module_soup = BeautifulSoup(html_content_module, 'html.parser')\n",
"\n",
" # Extract all images from the page\n",
" module_images = []\n",
" for image in module_soup.find_all('img'):\n",
" href = image.get('src')\n",
" if href.startswith(\"https://spark.thrivecart.com/\"):\n",
" module_images.append(href)\n",
"\n",
" # Send a GET request to the URL with the user agent and cookies\n",
" os.makedirs(os.path.join(current_dir,\n",
" current_module,'images'), exist_ok=True)\n",
" for module_image in module_images:\n",
" response_module_image = requests.get(module_image, headers=headers, cookies=cookies)\n",
" image_filename = extract_image_filename_thrivecart(module_image)\n",
" if response_module_image.status_code == 200:\n",
" # Save the image to a file\n",
" with open(os.path.join(current_dir,current_module,'images',image_filename), 'wb') as file:\n",
" file.write(response_module_image.content)\n",
"\n",
" # Extract all URLs from the page that start with the desired prefix\n",
" for link in module_soup.find_all('a'):\n",
" lesson_url = link.get('href')\n",
" if lesson_url and lesson_url.startswith(url) and not lesson_url.endswith(url) and lesson_url not in module_urls:\n",
" lessons_urls.append((current_module,lesson_url))"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"## Leçons\n",
"\n",
"Dans cette section, on va sauvegarder les leçons de la formation, accessible via des liens dans chaque module de la formation."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"### Extraction des URLs des leçons depuis la page d'accueil"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Process the extracted URLs as per your requirement\n",
"for lesson_urlpair in lessons_urls:\n",
" current_module = lesson_urlpair[0]\n",
" lesson_url = lesson_urlpair[1]\n",
"\n",
" # Send a GET request to the URL with the user agent and cookies\n",
" response_lesson = requests.get(lesson_url, headers=headers, cookies=cookies)\n",
" html_content_lesson = response_lesson.text\n",
"\n",
" # Enregistrement de la page\n",
" current_dir = os.path.join('html/modules/',current_module)\n",
" current_lesson = lesson_url.split('/')[-2]\n",
" os.makedirs(os.path.join(current_dir,\n",
" current_lesson), exist_ok=True)\n",
" with open(os.path.join(current_dir,current_lesson,'index.html'), 'w') as f:\n",
" f.write(html_content_lesson)\n",
" print(f'Fichier enregistré: {current_lesson}/index.html')\n",
" # Create a BeautifulSoup object with the HTML content\n",
" lesson_soup = BeautifulSoup(html_content_lesson, 'html.parser')\n",
"\n",
" # Extract all images from the page\n",
" lesson_images = []\n",
" for image in lesson_soup.find_all('img'):\n",
" href = image.get('src')\n",
" if href.startswith(\"https://spark.thrivecart.com/\"):\n",
" lesson_images.append(href)\n",
"\n",
" # Send a GET request to the URL with the user agent and cookies\n",
" os.makedirs(os.path.join(current_dir,\n",
" current_lesson,'images'), exist_ok=True)\n",
" for lesson_image in lesson_images:\n",
" response_lesson_image = requests.get(lesson_image, headers=headers, cookies=cookies)\n",
" image_filename = extract_image_filename_thrivecart(lesson_image)\n",
" # Save the image to a file\n",
" with open(os.path.join(current_dir,current_lesson,'images',image_filename), 'wb') as file:\n",
" file.write(response_lesson_image.content)\n",
" print(f'Fichier enregistré: {image_filename}')"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

7
thrivecart_utils.py Normal file
View file

@ -0,0 +1,7 @@
from urllib import parse
def extract_image_filename_thrivecart(url):
parsed_url = parse.urlparse(url)
filename = parse.unquote(parsed_url.path.split('/')[-1]).split('/')[-1]
return filename