From 7beded130ade21a70c58c45deed5ecaf77e657d7 Mon Sep 17 00:00:00 2001
From: Rick <rick@gnous.eu>
Date: Sat, 31 Oct 2020 21:45:11 +0100
Subject: [PATCH] ajout fichiers de base
---
extract.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
help.py | 31 +++++++++++++++++++++++++
2 files changed, 97 insertions(+)
create mode 100755 extract.sh
create mode 100644 help.py
diff --git a/extract.sh b/extract.sh
new file mode 100755
index 0000000..1bce8ae
--- /dev/null
+++ b/extract.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+#***************************#
+# extract.sh #
+# #
+# author : rick@gnous.eu #
+# licence: GPL3 or later #
+# #
+#***************************#
+
+
+################################################################################
+# Télécharge le fichier .b se trouvant à l’url en paramètre et le dézip dans
+# /tmp/file-tmp.
+# Globals:
+# [TODO:var-name]
+# Arguments:
+# $1: le curl (sans de --output) à faire pour récupérer le fichier
+################################################################################
+function recupDezip {
+ command="$@ --output /tmp/file-tmp.b"
+ eval $command
+
+ if [ -f "/tmp/file-tmp" ]
+ then
+ rm /tmp/file-tmp
+ fi
+
+ brotli -d -S .b /tmp/file-tmp.b
+}
+
+read -p "Entrez commande curl sans --compressed : " commandCurl
+
+recupDezip $commandCurl
+
+# on récupère le nombre de résultat pour avoir le nombre de page
+nbResult=$(python3 help.py -g)
+nbPage=$((nbResult / 25))
+url=$(echo $commandCurl | cut -d\ -f2)
+args=$(echo $commandCurl | cut -d\ -f3-)
+url="${url::-1}&offset=${url: -1}"
+
+if [ $((nbResult % 25)) -gt 0 ]
+then
+ nbPage=$((nbPage + 1))
+fi
+
+read -p "Attention ! $nbPage pages seront traités !"
+
+if [ -f result.json ]
+then
+ rm result.json
+fi
+cp /tmp/file-tmp result.json
+
+j=25
+for i in $(seq 1 $nbPage)
+do
+ newUrl="${url::-1}$j${url: -1}"
+ newCommand="curl $newUrl $args"
+ recupDezip $newCommand
+ python3 help.py -u
+ j=$((j + 25))
+done
+
+echo $nbPage
diff --git a/help.py b/help.py
new file mode 100644
index 0000000..069c4fd
--- /dev/null
+++ b/help.py
@@ -0,0 +1,31 @@
+import argparse
+import json
+
+######################
+# INITIALISATION DES #
+# VARIABLES #
+######################
+__author__ = "rick@gnous.eu"
+__licence__ = "GLP3 or later"
+
+parser = argparse.ArgumentParser(
+ description="Permet d’entrer des phrases ou des mots qui seront traduient en morse grace à la classe traducteurMorse. Cette traduction sera ensuite convertie en flash lumineux."
+ )
+parser.add_argument('-g', '--getelem', action="store_true", help="Retourne le nombre d’éléments du fichier json")
+parser.add_argument('-u', '--updatejson', action="store_true", help="Met à jour le fichier json avec les nouvelles infos")
+args = parser.parse_args()
+
+if args.getelem:
+ with open("/tmp/file-tmp", 'r') as file:
+ data = json.load(file)
+ print(data["total_results"])
+ exit(0)
+elif args.updatejson:
+ with open("/tmp/file-tmp", 'r') as file:
+ data = json.load(file)
+ with open("result.json", 'r+') as file:
+ oldData = json.load(file)
+ for messages in data["messages"]:
+ oldData["messages"].append(messages)
+ file.seek(0)
+ json.dump(oldData, file, indent=4)