This repository has been archived by the owner on Aug 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
recipes.py
69 lines (60 loc) · 2.22 KB
/
recipes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
#
# Copyright 2017 Ramil Nugmanov <stsouko@live.ru>
# This file is part of predictor.
#
# predictor
# is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
"""
Email SPAM sender.
"""
from MWUI import init
from pandas import read_csv
from MWUI.models import Email
from MWUI.views._sendmail import send_mail, attach_mixin
app = init()
data = read_csv('/path/to/addr.csv', sep=';', encoding='cp1251')
m = Email[123]
attach_files, attach_names = attach_mixin(m)
for _, x in data.iterrows():
full_name = '%s %s' % (x['name'], x['surname'])
with app.app_context():
send_mail(m.body % full_name, x['e-mail'], to_name=full_name, title=m.title, subject=m.title, banner=m.banner,
from_name=m.from_name, reply_mail=m.reply_mail, reply_name=m.reply_name,
attach_files=attach_files, attach_names=attach_names)
"""
load abstracts
"""
from MWUI import init
from MWUI.models import Thesis, Attachment, User, Meeting
from MWUI.config import UPLOAD_ROOT
from pathlib import Path
from werkzeug.utils import secure_filename
import shutil
app = init()
m = Meeting[312]
path = Path('/tmp') / 'meeting_{0.id}'.format(m)
path.mkdir()
for t in Thesis.select(lambda x: x._parent == m).prefetch(Attachment, User):
cat = path / t.type.fancy
if not cat.exists():
cat.mkdir()
for a in t.attachments:
in_file = UPLOAD_ROOT / a.file
out_file = cat / '{}.{}_{}.{}'.format(secure_filename(t.author_name), t.id, a.id, a.file.split('.')[1])
shutil.copy(str(in_file), str(out_file))