Browse Source

Init Commit

Patrick Baumgartner 3 năm trước cách đây
mục cha
commit
f631f43a4b

+ 6 - 9
Jessi/ContentFile.py

@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 import json
-from Texts import Contents
+from Jessi import Contents
 import Stats
 import random
 
@@ -20,12 +20,10 @@ class ContentFile(object):
         pass
 
     def __load(self):
-        print("ContentFile::__load()")
         self.entries.clear()
         self.entries = list()
         stats = Stats.Stats.getInstance()
-        print("ContentFile::__load()- Load File: text\\"+self._file)
-        with open('text\\'+self._file) as f:
+        with open('ressources/texts/'+self._file) as f:
             data = json.load(f)
 
         for i in data:
@@ -35,18 +33,17 @@ class ContentFile(object):
                             "freezy","funny","happyness","hot","humanity","hungry","intelligent","irritated","lonely","naiv",
                             "playful","sad","shy","sleepy","soziality","temperate","toLoud","toQuiet","usefull","useless"]
                 for sk in statKeys:
-                    if sk+"_max" in i["mood_required"] and i["mood_required"][sk+"_max"] <= getattr(stats.deviceStats,sk):
+                    if sk+"_max" in i["mood_required"] and i["mood_required"][sk+"_max"] <= getattr(stats.DeviceStats,sk):
                         add = False
                         break
-                    if sk+"_min" in i["mood_required"] and i["mood_required"][sk+"_min"] >= getattr(stats.deviceStats,sk):
+                    if sk+"_min" in i["mood_required"] and i["mood_required"][sk+"_min"] >= getattr(stats.DeviceStats,sk):
                         add = False
                         break
             if add == True and "text" in i:
                 self.entries.append(Contents.Contents(i))
-        print("Loading done")
 
 
-    def getText(self, tags):
+    def getText(self, tags) -> Contents:
         tagList = self.__argumentToTagList(tags)
         res = dict()
         maxNum = 1
@@ -79,7 +76,7 @@ class ContentFile(object):
             return rndText
         return ""
 
-    def Update():
+    def Update(self):
         self.__load()
 
 

+ 0 - 3
Jessi/Contents.py

@@ -14,7 +14,6 @@ class Contents(object):
         self.addStats = dict()
         self.actions = list()
         self.text = list()
-        print(item)
         if item!=None:
             if "tags" in item:
                 self.tags = self.__argumentToTagList(item["tags"])
@@ -54,7 +53,6 @@ class Contents(object):
                         found=True
                         break
                 if found==False:
-                    print("JSON-Tag not found: "+e)
                     return 0
         # check required Tags
         for t in tagList:
@@ -66,7 +64,6 @@ class Contents(object):
                         found = True
                         break
                 if found==False:
-                    print("Script-Tag not found: "+t+" ... " + t[1:] + " | " + "!"+t[1:])
                     return 0
             elif t[0:1]=="-":
                 found=False

+ 1 - 1
Jessi/__init__.py

@@ -1,3 +1,3 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
-from Texts.main import Text
+from Jessi.main import Text

+ 14 - 12
Jessi/main.py

@@ -1,9 +1,11 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
+from importlib.resources import contents
 from Stats import Stats
 import configparser
-from Network import Network
-from Texts import ContentFile
+from lib.Network import Network
+from Jessi import ContentFile
+from Jessi import Contents
 import datetime
 import math
 import json
@@ -30,9 +32,9 @@ class Text:
         return Text.instance
 
     def __init__(self):
-        self.stats = Stats.getInstance()
+        self.stats:Stats = Stats.getInstance()
         self.config = configparser.ConfigParser()
-        self.config.read("config.ini")
+        self.config.read("config/config.ini")
         self.replacer = list()
         # TODO: Replacer.js laden, und alle 60-180 Sekunden eine List-Variable mit möglichen Antworten füllen / aktualisieren
         #       z.B. aus der Replacer.js "badwords" mit allen möglichen Antworten, abhängig der Requirements, in die Variable "replacer["badwords"][]" füllen
@@ -40,17 +42,17 @@ class Text:
         self.readReplacer()
         
 
-    def getText(self, intent, tags):
+    def getText(self, intent:str, tags) -> Contents:
         if intent not in self.content:
-            if os.path.isfile("text/"+intent+".json") == False:
+            if os.path.isfile("ressources/texts/"+intent+".json") == False:
                 print("Failed to load intent text: "+intent)
                 return ""
             self.content[intent] = ContentFile.ContentFile(intent+".json")
         return self.content[intent].getText(tags)
 
-    def executeText(self, intent, tags):
+    def executeText(self, intent:str, tags) -> str:
         if intent not in self.content:
-            if os.path.isfile("text/"+intent+".json") == False:
+            if os.path.isfile("ressources/texts/"+intent+".json") == False:
                 print("Failed to load intent text: "+intent)
                 return ""
             self.content[intent] = ContentFile.ContentFile(intent+".json")
@@ -113,7 +115,7 @@ class Text:
                         deadcounter+=1
                         if deadcounter > 40:
                             break
-                print("Eexit Replacer Loop")
+                print("Exit Replacer Loop")
         return text
 
     def _formatText_DateTime(self,text:str,dt:datetime.datetime,name:str):
@@ -140,7 +142,7 @@ class Text:
 
     def readReplacer(self):
         tmp = {}
-        with open("text/Replacer.json") as json_file:
+        with open("ressources/texts/Replacer.json") as json_file:
             data = json.load(json_file)
         for k in data:
             tmp[k] = list()
@@ -151,10 +153,10 @@ class Text:
                                 "freezy","funny","happyness","hot","humanity","hungry","intelligent","irritated","lonely","naiv",
                                 "playful","sad","shy","sleepy","soziality","temperate","toLoud","toQuiet","usefull","useless"]
                     for sk in statKeys:
-                        if sk+"_max" in i["mood_required"] and i["mood_required"][sk+"_max"] <= getattr(self.stats.deviceStats,sk):
+                        if sk+"_max" in i["mood_required"] and i["mood_required"][sk+"_max"] <= getattr(self.stats.DeviceStats,sk):
                             add = False
                             break
-                        if sk+"_min" in i["mood_required"] and i["mood_required"][sk+"_min"] >= getattr(self.stats.deviceStats,sk):
+                        if sk+"_min" in i["mood_required"] and i["mood_required"][sk+"_min"] >= getattr(self.stats.DeviceStats,sk):
                             add = False
                             break
                 if add == True and "text" in i:

+ 4 - 4
Stats/main.py

@@ -122,10 +122,10 @@ class Stats:
 
     def __UpdateMic(self):
         self.Mic.Update()
-        self.micLevel.Volume_Min = self.Mic.LastResult["min"]
-        self.micLevel.Volume_Max = self.Mic.LastResult["max"]
-        self.micLevel.Volume_Avg = self.Mic.LastResult["avg"]
-        #print(self.micLevel.getJson())
+        self._micLevel.Volume_Min = self.Mic.LastResult["min"]
+        self._micLevel.Volume_Max = self.Mic.LastResult["max"]
+        self._micLevel.Volume_Avg = self.Mic.LastResult["avg"]
+        #print(self._micLevel.getJson())
 
     def __UpdateDateTime(self):
         self._outdoorStats.MoonPhase = mp.phase(time=datetime.datetime.now())

+ 1 - 1
TextConfig/__init__.py

@@ -70,7 +70,7 @@ class TextConfig:
                     if bWritte==False:
                         tmp+=line
         except:
-            print("Failed to load stats from file for saving")
+            print("Failed to load texts from file for saving")
         if os.path.isfile(self._file):
             os.remove(self._file)
         with open(self._file, 'w') as f:

+ 17 - 0
Trixy.pyproj

@@ -24,7 +24,13 @@
     <Compile Include="DynLoader\main.py" />
     <Compile Include="DynLoader\modInfo.py" />
     <Compile Include="DynLoader\__init__.py" />
+    <Compile Include="Jessi\ContentFile.py" />
+    <Compile Include="Jessi\Contents.py" />
+    <Compile Include="Jessi\main.py" />
+    <Compile Include="Jessi\Replacer.py" />
+    <Compile Include="Jessi\__init__.py" />
     <Compile Include="lib\MoonPhase.py" />
+    <Compile Include="lib\Network.py" />
     <Compile Include="lib\RepeatTimer.py" />
     <Compile Include="main.py" />
     <Compile Include="MicCapture\WindowsCapture.py" />
@@ -73,14 +79,25 @@
     <Content Include="mods\README.md" />
     <Content Include="README.md" />
     <Content Include="ressources\email\blank.html" />
+    <Content Include="ressources\email\README.md" />
+    <Content Include="ressources\sounds\README.md" />
+    <Content Include="ressources\texts\basic.json" />
+    <Content Include="ressources\texts\README.md" />
+    <Content Include="ressources\texts\Replacer.json" />
+    <Content Include="ressources\texts\test.json" />
+    <Content Include="ressources\texts\weather.json" />
+    <Content Include="test\README.md" />
   </ItemGroup>
   <ItemGroup>
+    <Folder Include="Jessi\" />
     <Folder Include="lib\" />
     <Folder Include="MicCapture\" />
     <Folder Include="cache\" />
     <Folder Include="config\" />
     <Folder Include="mods\ModPlaySound\" />
     <Folder Include="mods\WindowsSay\" />
+    <Folder Include="ressources\texts\" />
+    <Folder Include="test\" />
     <Folder Include="ressources\" />
     <Folder Include="ressources\email\" />
     <Folder Include="ressources\sounds\" />

+ 5 - 0
main.py

@@ -4,6 +4,7 @@
 from DynLoader import DynLoaderMod as dyn
 from VoicePlay import Voice as speach
 from Stats import Stats
+from Jessi import Text as textauswahl
 
 if __name__ == "__main__":
     print("Start application")
@@ -21,3 +22,7 @@ if __name__ == "__main__":
     mod.execute("PlaySound", "welcome.mp3", False)
     print("Sound playing...")
 
+    joke = textauswahl.getInstance().executeText("test",["joke","kurzwitz"])
+    print(joke)
+    speach.getInstance().Say(joke)
+

+ 5 - 5
ressources/texts/Replacer.json

@@ -5,8 +5,8 @@
                 "angry_max": 100
             },
             "text": [
-                "blöd",
-                "mieß",
+                "blöd",
+                "mieß",
                 "doof"
             ]
         },
@@ -16,7 +16,7 @@
                 "angry_max": 200
             },
             "text": [
-                "übel",
+                "übel",
                 "kacke"
             ]
         },
@@ -36,7 +36,7 @@
                 "angry_max": 800
             },
             "text": [
-                "scheiße",
+                "scheiße",
                 "bescheuert",
                 "verkackt"
             ]
@@ -92,7 +92,7 @@
                 "niedlich",
                 "kjut",
                 "putzig",
-                "süß"
+                "süß"
             ]
         },
         {

+ 1 - 1
ressources/texts/basic.json

@@ -13,7 +13,7 @@
     "text": [
       "Ich habe keine Lust",
       "Ich will nicht",
-      "Ich möchte nicht"
+      "Ich m�chte nicht"
     ],
     "actions": ["mute","s2t","memo"]
   }

+ 17 - 17
ressources/texts/test.json

@@ -13,7 +13,7 @@
     "text": [
       "Ich habe {curse} keine Lust",
       "Ich will {curse} nicht",
-      "Ich möchte {curse} nicht"
+      "Ich m�chte {curse} nicht"
     ]
   },
   {
@@ -26,7 +26,7 @@
       "funny": -10
     },
     "text": [
-      "Ein scheiß werde ich"
+      "Ein scheiß werde ich"
     ]
   },
   {
@@ -73,7 +73,7 @@
       "funny": 10
     },
     "text": [
-      "Wie heißt der Chinesische Sexminister? Schwing dein Ding"
+      "Wie heißt der Chinesische Sexminister? Schwing dein Ding"
     ]
   },
   {
@@ -82,7 +82,7 @@
       "funny": 10
     },
     "text": [
-      "Fragt eine Frau: Siri, warum bin ich single? Siri öffnet die Frontkamera"
+      "Fragt eine Frau: Siri, warum bin ich single? Siri öffnet die Frontkamera"
     ]
   },
   {
@@ -91,7 +91,7 @@
       "funny": 10
     },
     "text": [
-      "Womit verhüten Blondinen am liebsten? Mit der Glücksspirale!",
+      "Womit verhüten Blondinen am liebsten? Mit der Glücksspirale!",
       "Was ist eine Blondine auf einer Luftmatratze? Eine Bohrinsel!",
       "Wo gehen Blondinen am liebsten einkaufen? Bei Schlecker."
     ]
@@ -115,12 +115,12 @@
     ]
   },
   {
-    "tags": [ "!joke", "clown", "büro", "beamte", "kurzwitz" ],
+    "tags": [ "!joke", "clown", "b�ro", "beamte", "kurzwitz" ],
     "mood_add": {
       "funny": 10
     },
     "text": [
-      "Was macht ein Clown im Büro? Faxen"
+      "Was macht ein Clown im Büro? Faxen"
     ]
   },
   {
@@ -138,7 +138,7 @@
       "funny": 10
     },
     "text": [
-      "Was ist weiß und stört beim essen? Eine Lawine"
+      "Was ist weiß und stört beim essen? Eine Lawine"
     ]
   },
   {
@@ -156,7 +156,7 @@
       "funny": 10
     },
     "text": [
-      "Veganer bekommen keine Kinder. Sie bekommen Sprösslinge."
+      "Veganer bekommen keine Kinder. Sie bekommen Sprösslinge."
     ]
   },
   {
@@ -165,7 +165,7 @@
       "funny": 10
     },
     "text": [
-      "Was ist rot und hat zwei schwarze Streifen? Tomate mit Hosenträgern."
+      "Was ist rot und hat zwei schwarze Streifen? Tomate mit Hosentr�gern."
     ]
   },
   {
@@ -183,7 +183,7 @@
       "funny": 10
     },
     "text": [
-      "So sieht der erste Triathlon für Beamte aus: Knicken, Lochen, Heften."
+      "So sieht der erste Triathlon für Beamte aus: Knicken, Lochen, Heften."
     ]
   },
   {
@@ -201,7 +201,7 @@
       "funny": 10
     },
     "text": [
-      "Wie nennt man einen {object_nicer} Bumerang der nicht zurück kommt? Stock"
+      "Wie nennt man einen {object_nicer} Bumerang der nicht zurück kommt? Stock"
     ]
   },
   {
@@ -210,9 +210,9 @@
       "funny": 10
     },
     "text": [
-      "Welche Beamten stören im Büro am meisten? Die, die im Schlaf reden",
-      "Warum benutzen Beamte keine Taschentücher? Weil Tempo draufsteht.",
-      "Der kürzeste Beamtenwitz: Geht ein {person_nicer|er} Beamter zur {badword|} Arbeit ..."
+      "Welche Beamten stören im Büro am meisten? Die, die im Schlaf reden",
+      "Warum benutzen Beamte keine Taschentücher? Weil Tempo draufsteht.",
+      "Der kürzeste Beamtenwitz: Geht ein {person_nicer|er} Beamter zur {badword|} Arbeit ..."
     ]
   },
   {
@@ -230,9 +230,9 @@
       "funny": 10
     },
     "text": [
-      "Im Büro sitzen sich zwei Beamte gegenüber: Weißt du, wo mein {object_nicer} Kugelschreiber ist? Ja, hinter deinem {object_nicer} Ohr.Mann, mach es nicht so kompliziert - hinter welchem?",
+      "Im Büro sitzen sich zwei Beamte gegenüber: Weißt du, wo mein {object_nicer} Kugelschreiber ist? Ja, hinter deinem {object_nicer} Ohr.Mann, mach es nicht so kompliziert - hinter welchem?",
       "Sagt der erste Beamte: Ich hasse es, wenn der {object_nicer} Wecker klingelt und man aus dem {object_nicer} Schlaf gerissen wird. Meint der zweite Beamte: Feierabend ist Feierabend!",
-      "Treffen sich zwei Beamte auf dem {place_nicer} Büroflur. Sagt der eine zum anderen: Na, kannst du auch nicht einschlafen?"
+      "Treffen sich zwei Beamte auf dem {place_nicer} Büroflur. Sagt der eine zum anderen: Na, kannst du auch nicht einschlafen?"
     ]
   }