From 7957fd4ab5f33140bf3f088d68e5c79558ff71af Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Sun, 1 Aug 2021 18:25:40 +0200 Subject: [PATCH] Added speedtest skill --- .../skills/productivity/speedtest/__init__.py | 32 +++++++++++++++++++ .../dialog/fr-fr/result_speedtest.dialog | 3 ++ .../vocab/fr-fr/start_speedtest.intent | 1 + 3 files changed, 36 insertions(+) create mode 100644 jarvis/skills/productivity/speedtest/__init__.py create mode 100644 jarvis/skills/productivity/speedtest/dialog/fr-fr/result_speedtest.dialog create mode 100644 jarvis/skills/productivity/speedtest/vocab/fr-fr/start_speedtest.intent diff --git a/jarvis/skills/productivity/speedtest/__init__.py b/jarvis/skills/productivity/speedtest/__init__.py new file mode 100644 index 0000000..70b2fc9 --- /dev/null +++ b/jarvis/skills/productivity/speedtest/__init__.py @@ -0,0 +1,32 @@ +import speedtest + +from jarvis.skills import Skill, SkillRegistering +from jarvis.skills.decorators import intent_file_handler + + +class SpeedTestSkill(Skill, metaclass=SkillRegistering): + def __init__(self, data=dict): + super().__init__("SpeedTestSkill", data) + + @intent_file_handler("start_speedtest.intent", "StartSpeedTestIntent") + def handle_speedtest(self, data): + try: + self.speak_dialog('starting_speedtest') + + speed = speedtest.Speedtest() + # speed.get_servers([]) + speed.get_best_server() + speed.download() + speed.upload(pre_allocate=False) + # speed.results.share() + result = speed.results.dict() + down_speed = ('%.2f' % float((result["download"]) / 1000000)) + up_speed = ('%.2f' % float((result["upload"]) / 1000000)) + + self.speak_dialog('result', {'DOWN': down_speed, 'UP': up_speed}) + except: + self.speak_dialog("error") + + +def create_skill(data): + return SpeedTestSkill(data) diff --git a/jarvis/skills/productivity/speedtest/dialog/fr-fr/result_speedtest.dialog b/jarvis/skills/productivity/speedtest/dialog/fr-fr/result_speedtest.dialog new file mode 100644 index 0000000..ac0c9a8 --- /dev/null +++ b/jarvis/skills/productivity/speedtest/dialog/fr-fr/result_speedtest.dialog @@ -0,0 +1,3 @@ +Votre débit est de {{DOWN}} mégabits descendant et {{UP}} montant +Vous atteignez des vitesses de {{DOWN}} mégabits en téléchargement et environ {{UP}} en envoi +Votre connexion atteint les {{DOWN}} mégabits en téléchargement et près de {{UP}} mégabits en envoi \ No newline at end of file diff --git a/jarvis/skills/productivity/speedtest/vocab/fr-fr/start_speedtest.intent b/jarvis/skills/productivity/speedtest/vocab/fr-fr/start_speedtest.intent new file mode 100644 index 0000000..5ecc9df --- /dev/null +++ b/jarvis/skills/productivity/speedtest/vocab/fr-fr/start_speedtest.intent @@ -0,0 +1 @@ +(Lance|Fait|Test) (un|le) (test (de|du)|) (réseau|débit|speedtest) \ No newline at end of file