Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
ptb-subtitle-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Hartig
ptb-subtitle-service
Merge requests
!2
Add Mailservice
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add Mailservice
mailservice
into
main
Overview
0
Commits
3
Pipelines
0
Changes
4
Merged
Jan Hartig
requested to merge
mailservice
into
main
1 year ago
Overview
0
Commits
3
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
fac2ede4
3 commits,
1 year ago
4 files
+
87
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
mailservice/mailservice.py
0 → 100644
+
59
−
0
Options
import
json
import
shutil
import
smtplib
import
tomllib
from
email.message
import
EmailMessage
from
os
import
scandir
from
pathlib
import
Path
def
main
():
with
open
(
"
../config.toml
"
,
"
rb
"
)
as
f
:
config
=
tomllib
.
load
(
f
)
with
open
(
"
../localisations.toml
"
,
"
rb
"
)
as
f
:
localisations
=
tomllib
.
load
(
f
)
finished_jobs
=
[]
with
scandir
(
config
[
"
UPLOAD_FOLDER
"
])
as
uploads
:
for
entry
in
uploads
:
if
entry
.
is_dir
():
with
scandir
(
entry
.
path
)
as
job
:
for
file
in
job
:
if
file
.
is_file
()
and
file
.
name
==
"
done
"
:
finished_jobs
.
append
(
entry
.
path
)
break
with
smtplib
.
SMTP
(
host
=
config
[
"
MAIL
"
][
"
SERVER
"
],
port
=
config
[
"
MAIL
"
][
"
PORT
"
],
local_hostname
=
config
[
"
MAIL
"
][
"
LOCAL_HOSTNAME
"
]
if
config
[
"
MAIL
"
][
"
LOCAL_HOSTNAME
"
]
else
None
,
)
as
s
:
for
job
in
finished_jobs
:
with
open
(
Path
(
job
).
joinpath
(
"
metadata.json
"
))
as
f
:
metadata
=
json
.
load
(
f
)
language
=
metadata
[
"
language
"
]
msg
=
EmailMessage
()
msg
[
"
Subject
"
]
=
localisations
[
"
mail
"
][
"
subject
"
][
language
]
msg
[
"
From
"
]
=
config
[
"
MAIL
"
][
"
FROM
"
]
msg
[
"
To
"
]
=
metadata
[
"
email
"
]
msg
.
set_content
(
localisations
[
"
mail
"
][
"
content
"
][
language
].
format
(
metadata
[
"
filename
"
]))
# filename.language.vtt
filename
=
(
Path
(
metadata
[
"
filename
"
]).
with_suffix
(
"
.{}.vtt
"
.
format
(
metadata
[
"
video_language
"
])).
name
)
with
open
(
Path
(
job
).
joinpath
(
"
subtitles.vtt
"
))
as
f
:
msg
.
add_attachment
(
f
.
read
(),
filename
=
filename
)
s
.
send_message
(
msg
)
shutil
.
rmtree
(
job
)
if
__name__
==
"
__main__
"
:
main
()
Loading