Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
fix mails content + script to launch mokadi
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Apr 23, 2017
1 parent 3b274d5 commit eb6cd14
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 27 deletions.
1 change: 0 additions & 1 deletion _unittests/ut_mokadi/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def test_mail(self):
"gmail", os.environ["COMPUTERNAME"] + "user")
pwd = keyring.get_password("gmail", os.environ["COMPUTERNAME"] + "pwd")
server = "imap.gmail.com"

try:
mails = enumerate_last_mails(user, pwd, server, fLOG=fLOG)

Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install:
- "%PYTHON%\\Scripts\\pymy_install3 --set=pyensae"
- "%PYTHON%\\Scripts\\pip install cryptography"
- "%PYTHON%\\Scripts\\pip install azure"
- "%PYTHON%\\Scripts\\pymy_install3 pycrypto numba pycurl"
- "%PYTHON%\\Scripts\\pymy_install3 pycrypto numba pycurl Pillow"
- "%PYTHON%\\Scripts\\pymy_install3 basemap sympy pyqt4 mpmath reportlab statsmodels cffi scipy pylzma"
- "%PYTHON%\\Scripts\\pip install pycryptodomex jyquickhelper"
- "%PYTHON%\\Scripts\\pip install urllib3 traittypes"
Expand All @@ -43,7 +43,7 @@ install:
- "%PYTHON%\\Scripts\\pip install lifelines"
- "%PYTHON%\\Scripts\\pip install missingno pythreejs vega"
- "%PYTHON%\\Scripts\\pip install pygal_maps_fr"
- "%PYTHON%\\Scripts\\pip install ggplot==0.9.3"
- "%PYTHON%\\Scripts\\pip install ggplot" # ==0.9.3"
- "%PYTHON%\\Scripts\\pymy_install3 --task=tool --source=zip graphviz"
- "%PYTHON%\\Scripts\\pymy_install3 datashader pydy biopython scikit-image pyproj"
- "%PYTHON%\\Scripts\\pip install -r requirements.txt"
Expand Down
28 changes: 28 additions & 0 deletions bin/launch_mokadi.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

@echo off
@echo SCRIPT: windows_prefix
if "%1"=="" goto default_value_python:
if "%1"=="default" goto default_value_python:
set pythonexe=%1
goto start_script:

:default_value_python:
set pythonexe=c:\Python36_x64\python

@echo ~SET pythonexe=%pythonexe%

:start_script:
set current=%~dp0
if EXIST %current%setup.py goto current_is_setup:
set current=%current%..\
cd ..
if EXIST %current%setup.py goto current_is_setup:
@echo Unable to find %current%setup.py
exit /b 1

:current_is_setup:
@echo ~SET current=%current%


set PYTHONPATH=%PYTHONPATH%;%current%src;%current%\..\pyquickhelper\src;%current%\..\pyensae\src;%current%\..\mlstatpy\src;%current%\..\teachpyx\src;%current%\..\jyquickhelper\src;%current%\..\pymmails\src;%current%\..\ensae_teaching_cs\src
%pythonexe% -u -c "from pyquickhelper.loghelper import fLOG;fLOG(OutputPrint=True);from jupytalk.mokadi import gui_mokadi;gui_mokadi(fLOG)"
20 changes: 20 additions & 0 deletions bin/update_grammars.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

@echo off
@echo SCRIPT: windows_prefix
if "%1"=="" goto default_value_python:
if "%1"=="default" goto default_value_python:
set pythonexe=%1
goto start_script:

:default_value_python:
set pythonexe=c:\Python36_x64\python

@echo ~SET pythonexe=%pythonexe%

:start_script:
set current=%~dp0
@echo ~SET current=%current%
set PYTHONPATH=%current%\src

%pythonexe% -u %current%..\setup.py update_grammars
if %errorlevel% neq 0 exit /b %errorlevel%
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def write_version():
logging_function = pyquickhelper.get_fLOG()
from pyquickhelper.pycode import process_standard_options_for_setup
logging_function(OutputPrint=True)
if "unittests" in sys.argv and sys.platform.startswith("win"):
# There is some issues on Windows.
from PIL import Image as PIL_Image
assert PIL is not None
r = process_standard_options_for_setup(
sys.argv, __file__, project_var_name, layout=["html"],
unittest_modules=["pyquickhelper", "jyquickhelper"],
Expand Down
1 change: 1 addition & 0 deletions src/jupytalk/mokadi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .mokadi_engine import MokadiEngine
from .mokadi_exceptions import MokadiException
from .gui_mokadi import gui_mokadi
from .mokadi_grammar import interpret
from .mokadi_info import MokadiInfo
from .mokadi_mails import enumerate_last_mails
Expand Down
3 changes: 2 additions & 1 deletion src/jupytalk/mokadi/gui_mokadi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from PIL import Image, ImageTk
from pyquickhelper.loghelper import CustomLog, fLOG
from .grammars import MokadiGrammar_frParser, MokadiGrammar_frLexer, MokadiGrammar_frListener
from . import MokadiEngine, MokadiMessage
from .mokadi_message import MokadiMessage
from .mokadi_engine import MokadiEngine
from .mokadi_action_conversation import MokadiActionConversation
from .mokadi_action_emotion import MokadiActionEmotion
from .mokadi_action_mail import MokadiActionMail
Expand Down
48 changes: 28 additions & 20 deletions src/jupytalk/mokadi/mokadi_action_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from .mokadi_action import MokadiAction
from .mokadi_info import MokadiInfo
from .mokadi_exceptions import MokadiException
from .mokadi_exceptions import MokadiException, MokadiAuthentification
from .mokadi_mails import enumerate_last_mails
from .mokadi_helper import parse_string_int

Expand Down Expand Up @@ -67,7 +67,7 @@ def process_interpreted_message(self, interpretation, message):
interpretation_clean[3][1] == ":int:" and interpretation_clean[4][1] == ":entier:":
keep = parse_string_int(interpretation_clean[3][0])
good = True
body = False
body = True
elif len(interpretation) == 5:
if interpretation[1][1] == ":verb_voir:" and interpretation[2][1] == ":int:" and \
interpretation[3][1] == ":mails:":
Expand All @@ -82,25 +82,33 @@ def process_interpreted_message(self, interpretation, message):
good = True
if good:
fetch = max(keep + 1, 5)
mails = enumerate_last_mails(
self._user, self._pwd, self._server, fLOG=self.fLOG, nb=fetch)
try:
mails = enumerate_last_mails(
self._user, self._pwd, self._server, fLOG=self.fLOG, nb=fetch)
except MokadiAuthentification as e:
yield MokadiInfo("error", "Il m'est impossible de me connecter à la boîte mail de {0}.".format(self._user))

for i, mail in enumerate(mails):
if i == stop:
break
if keep != -1 and i != keep:
continue
self.fLOG(mail.get_name(), "**", mail.get_nb_attachements(),
"**", mail.get_date_str())
h = mail.get_date().hour
yield MokadiInfo("ok", "Mail reçu vers {0} heures de {1}.".format(h, mail.get_name()))
yield MokadiInfo("ok", mail.get_field("subject").split("\n")[0])
nb = mail.get_nb_attachements()
if nb > 0:
yield MokadiInfo("ok", "Ce mail a {0} pièces jointes.".format(nb))
if body:
for line in mail.body:
yield MokadiInfo("ok", line)
try:
for i, mail in enumerate(mails):
if i == stop:
break
if keep != -1 and i != keep:
continue
self.fLOG(mail.get_name(), "**", mail.get_nb_attachements(),
"**", mail.get_date_str())
h = mail.get_date().hour
yield MokadiInfo("ok", "Mail reçu vers {0} heures de {1}.".format(h, mail.get_name()))
yield MokadiInfo("ok", mail.get_field("subject").split("\n")[0])
nb = mail.get_nb_attachements()
if nb > 0:
yield MokadiInfo("ok", "Ce mail a {0} pièces jointes.".format(nb))
if body:
# The content of the mail includes past answers.
# This should be removed as well as html tags.
for line in mail.body.split("\n"):
yield MokadiInfo("ok", line)
except MokadiAuthentification as e:
yield MokadiInfo("error", "Il m'est impossible de me connecter à la boîte mail de {0}.".format(self._user))

done = True
if not done:
Expand Down
7 changes: 7 additions & 0 deletions src/jupytalk/mokadi/mokadi_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ class WikipediaException(Exception):
Issue with wikipedia
"""
pass


class MokadiAuthentification(Exception):
"""
Issue with authentification
"""
pass
6 changes: 5 additions & 1 deletion src/jupytalk/mokadi/mokadi_mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import datetime
from pyquickhelper.loghelper import noLOG
from .mokadi_exceptions import MokadiAuthentification


def enumerate_last_mails(user, pwd, server, nb=5, fLOG=noLOG):
Expand All @@ -28,7 +29,10 @@ def enumerate_last_mails(user, pwd, server, nb=5, fLOG=noLOG):
pattern = "SINCE %s" % date
fLOG("[enumerate_last_mails] pattern ", pattern)
box = MailBoxImap(user, pwd, server, ssl=True, fLOG=fLOG)
box.login()
try:
box.login()
except Exception as e:
raise MokadiAuthentification("Unable to connect to the mailbox") from e

def enumerate_mails(iter):
for mail in iter:
Expand Down
8 changes: 6 additions & 2 deletions src/jupytalk/mokadi/mokadi_picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""


def take_picture(filename=None, size=(640, 480), module="pygame"):
def take_picture(filename=None, size=(640, 480), module="cv2"):
"""
Take a picture with the camera.
Expand All @@ -21,7 +21,11 @@ def take_picture(filename=None, size=(640, 480), module="pygame"):
import pygame.camera
pygame.camera.init()
# pygame.camera.list_camera()
cam = pygame.camera.Camera(0, size)
try:
cam = pygame.camera.Camera(0, size, "RGB")
except Exception as e:
raise Exception(
"Unable to change resolution into {0}".format(size)) from e
cam.start()
img = cam.get_image()
if filename is not None:
Expand Down

0 comments on commit eb6cd14

Please sign in to comment.