done with email.
Browse files- js_script.js +8 -0
- jslearn.html +14 -0
- mail_sender.py +36 -23
- pages/❄️p2.py +2 -0
- pages/🎉p3.py +44 -11
- test.ipynb +110 -43
js_script.js
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { createApp } from "vue";
|
2 |
+
createApp({
|
3 |
+
data() {
|
4 |
+
return {
|
5 |
+
count: 0,
|
6 |
+
};
|
7 |
+
},
|
8 |
+
}).mount("#app");
|
jslearn.html
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<body>
|
4 |
+
<p>Before the script...</p>
|
5 |
+
|
6 |
+
<script>
|
7 |
+
alert("Hello, world!");
|
8 |
+
</script>
|
9 |
+
<div id="app">
|
10 |
+
<button @click="count++">Count is: {{ count }}</button>
|
11 |
+
</div>
|
12 |
+
<p>...After the script.</p>
|
13 |
+
</body>
|
14 |
+
</html>
|
mail_sender.py
CHANGED
@@ -5,7 +5,8 @@ from email.mime.multipart import MIMEMultipart
|
|
5 |
from email.mime.text import MIMEText
|
6 |
from email.mime.base import MIMEBase
|
7 |
from email import encoders
|
8 |
-
|
|
|
9 |
|
10 |
class config():
|
11 |
def __init__(self):
|
@@ -34,22 +35,31 @@ class config():
|
|
34 |
# file #
|
35 |
# ============================================================================ #
|
36 |
# output_name1 = 'name'
|
37 |
-
|
38 |
-
|
39 |
-
part1.set_payload(open(payload, "rb").read())
|
40 |
-
encoders.encode_base64(part1)
|
41 |
-
try:
|
42 |
-
print(re.findall('\.\w+', payload.name))
|
43 |
-
except:
|
44 |
-
print(re.findall('?>=\.\w+', payload))
|
45 |
-
print(re.findall('\w+(?=\.\w+)', payload))
|
46 |
-
pass
|
47 |
-
output_name1 = re.findall('\w+(?=\.\w+)', payload)
|
48 |
-
part1.add_header('Content-Disposition', 'attachment', filename=('utf-8', '', payload))
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# ============================================================================ #
|
55 |
# config #
|
@@ -65,7 +75,7 @@ class config():
|
|
65 |
def run_(self, content, payload, receivers):
|
66 |
self.server.starttls()
|
67 |
self.server.login(self.mail, self.pw)
|
68 |
-
|
69 |
try:
|
70 |
print(
|
71 |
"""
|
@@ -78,12 +88,12 @@ class config():
|
|
78 |
if type(receivers) is list:
|
79 |
for i in receivers:
|
80 |
self.sendEmailwithFile(
|
81 |
-
self.mail,
|
82 |
server = self.server,
|
83 |
content = content,
|
84 |
payload=payload,
|
85 |
receivers=i)
|
86 |
-
|
87 |
pass
|
88 |
|
89 |
elif type(receivers) is str:
|
@@ -93,9 +103,9 @@ class config():
|
|
93 |
content = content,
|
94 |
payload=payload,
|
95 |
receivers=receivers)
|
96 |
-
|
97 |
else:
|
98 |
-
raise Exception("
|
99 |
except Exception as e:
|
100 |
raise ValueError(e)
|
101 |
self.server.quit()
|
@@ -111,5 +121,8 @@ class config():
|
|
111 |
# payload = r"C:\Users\dscshap3808\Documents\fapiao\202109.pdf"
|
112 |
# a.sendEmailwithFile(account=a.mail, server=server, content=content, payload=payload,
|
113 |
# receivers='siming.yan@sf-dsc.com')
|
114 |
-
# server.quit()
|
115 |
-
#
|
|
|
|
|
|
|
|
5 |
from email.mime.text import MIMEText
|
6 |
from email.mime.base import MIMEBase
|
7 |
from email import encoders
|
8 |
+
from typing import List
|
9 |
+
import streamlit as st
|
10 |
|
11 |
class config():
|
12 |
def __init__(self):
|
|
|
35 |
# file #
|
36 |
# ============================================================================ #
|
37 |
# output_name1 = 'name'
|
38 |
+
def name_mutate(name):
|
39 |
+
return re.findall('(?<=\/)\w+\.\w+', str(name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
def attach_file(payload):
|
42 |
+
part1 = MIMEBase('application', "octet-stream")
|
43 |
+
part1.set_payload(open(payload, "rb").read())
|
44 |
+
encoders.encode_base64(part1)
|
45 |
+
# try:
|
46 |
+
# st.write(re.findall('\.\w+', payload), 'format of file')
|
47 |
+
# except:
|
48 |
+
# st.write(re.findall('?>=\.\w+', payload))
|
49 |
+
# st.write(re.findall('\w+(?=\.\w+)', payload))
|
50 |
+
# pass
|
51 |
+
part1.add_header(
|
52 |
+
'Content-Disposition',
|
53 |
+
'attachment',
|
54 |
+
filename=('utf-8', '', name_mutate(payload)[0]))
|
55 |
+
msg.attach(part1)
|
56 |
+
|
57 |
+
if payload is List:
|
58 |
+
payloads = payload
|
59 |
+
for payload in payloads:
|
60 |
+
attach_file(payload)
|
61 |
+
else:
|
62 |
+
attach_file(payload)
|
63 |
|
64 |
# ============================================================================ #
|
65 |
# config #
|
|
|
75 |
def run_(self, content, payload, receivers):
|
76 |
self.server.starttls()
|
77 |
self.server.login(self.mail, self.pw)
|
78 |
+
st.write('connecting...')
|
79 |
try:
|
80 |
print(
|
81 |
"""
|
|
|
88 |
if type(receivers) is list:
|
89 |
for i in receivers:
|
90 |
self.sendEmailwithFile(
|
91 |
+
account= self.mail,
|
92 |
server = self.server,
|
93 |
content = content,
|
94 |
payload=payload,
|
95 |
receivers=i)
|
96 |
+
st.write("SUCCESS to address", i)
|
97 |
pass
|
98 |
|
99 |
elif type(receivers) is str:
|
|
|
103 |
content = content,
|
104 |
payload=payload,
|
105 |
receivers=receivers)
|
106 |
+
st.write("SUCCESS", receivers)
|
107 |
else:
|
108 |
+
raise Exception("eeeeemmmmmmmmmmm")
|
109 |
except Exception as e:
|
110 |
raise ValueError(e)
|
111 |
self.server.quit()
|
|
|
121 |
# payload = r"C:\Users\dscshap3808\Documents\fapiao\202109.pdf"
|
122 |
# a.sendEmailwithFile(account=a.mail, server=server, content=content, payload=payload,
|
123 |
# receivers='siming.yan@sf-dsc.com')
|
124 |
+
# server.quit()
|
125 |
+
# q(?=u) matches a q that is followed by a u,
|
126 |
+
# (?<=a)b (positive lookbehind) matches the b (and only the b) in cab,
|
127 |
+
|
128 |
+
|
pages/❄️p2.py
CHANGED
@@ -21,3 +21,5 @@ with st.form("my_form"):
|
|
21 |
st.write("slider", slider_val, "checkbox", checkbox_val)
|
22 |
pd.DataFrame({'message': message, 'slider_val':slider_val, 'checkbox_val': checkbox_val}, index=range(1)).to_csv('./dataup/backup.csv')
|
23 |
# with st.spinner('Wait for it...'):
|
|
|
|
|
|
21 |
st.write("slider", slider_val, "checkbox", checkbox_val)
|
22 |
pd.DataFrame({'message': message, 'slider_val':slider_val, 'checkbox_val': checkbox_val}, index=range(1)).to_csv('./dataup/backup.csv')
|
23 |
# with st.spinner('Wait for it...'):
|
24 |
+
|
25 |
+
|
pages/🎉p3.py
CHANGED
@@ -11,6 +11,13 @@ st.sidebar.markdown("# Page 3 🎉")
|
|
11 |
|
12 |
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
add_plus = st.text_input('add a mail address')
|
15 |
if add_plus is not None:
|
16 |
select_list = ["fyenne@hotmail.com"]+ [str(add_plus)]
|
@@ -31,20 +38,46 @@ st.write(select_list)
|
|
31 |
st.markdown('---')
|
32 |
|
33 |
content = st.text_input('content')
|
34 |
-
|
35 |
accept_multiple_files = True)
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
bt = st.button('send')
|
40 |
|
|
|
|
|
41 |
if bt:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
a = config()
|
43 |
-
|
44 |
-
|
45 |
-
# a.run_("content", payload=None, receivers = 'fyenne@hotmail.com')
|
46 |
-
while res is None:
|
47 |
-
with st.spinner('Wait for it...'):
|
48 |
-
pass
|
49 |
|
50 |
-
st.markdown('**succeed mail**')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
|
14 |
+
def save_uploadedfile(uploadedfile):
|
15 |
+
with open(os.path.join(tmp_dir,uploadedfile.name),"wb") as f:
|
16 |
+
f.write(uploadedfile.getbuffer())
|
17 |
+
return st.success("Saved File:{} to tempDir".format(uploadedfile.name))
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
add_plus = st.text_input('add a mail address')
|
22 |
if add_plus is not None:
|
23 |
select_list = ["fyenne@hotmail.com"]+ [str(add_plus)]
|
|
|
38 |
st.markdown('---')
|
39 |
|
40 |
content = st.text_input('content')
|
41 |
+
files = st.file_uploader(label="file uploader",
|
42 |
accept_multiple_files = True)
|
43 |
+
if files != None:
|
44 |
+
# st.write(file.name)
|
45 |
+
for file in files:
|
46 |
+
file_details = {"filename":file.name,
|
47 |
+
"filetype":file.type,
|
48 |
+
"filesize":file.size}
|
49 |
+
st.write(file_details)
|
50 |
+
# ---
|
51 |
bt = st.button('send')
|
52 |
|
53 |
+
|
54 |
+
res = None
|
55 |
if bt:
|
56 |
+
# ============================================================================ #
|
57 |
+
# create file path for tmp storage #
|
58 |
+
# ============================================================================ #
|
59 |
+
import os
|
60 |
+
import time
|
61 |
+
tmp_dir = './tmp_files/'
|
62 |
+
try:
|
63 |
+
os.mkdir(tmp_dir)
|
64 |
+
except:
|
65 |
+
pass
|
66 |
+
for file in files:
|
67 |
+
save_uploadedfile(file)
|
68 |
+
|
69 |
+
# ============================================================================ #
|
70 |
a = config()
|
71 |
+
res = a.run_(content = str(content), payload=(tmp_dir+file.name), receivers = receiver)
|
72 |
+
|
|
|
|
|
|
|
|
|
73 |
|
74 |
+
st.markdown('**succeed mail**')
|
75 |
+
while a == 0:
|
76 |
+
with st.spinner('Wait for it...'):
|
77 |
+
time.sleep(1)
|
78 |
+
del a
|
79 |
+
try:
|
80 |
+
import shutil
|
81 |
+
shutil.rmtree('./tmp_files/')
|
82 |
+
except:
|
83 |
+
pass
|
test.ipynb
CHANGED
@@ -141,62 +141,129 @@
|
|
141 |
},
|
142 |
{
|
143 |
"cell_type": "code",
|
144 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
"metadata": {},
|
146 |
"outputs": [
|
147 |
{
|
148 |
-
"
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
"\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'name'"
|
157 |
-
]
|
158 |
}
|
159 |
],
|
160 |
"source": [
|
161 |
-
"
|
162 |
-
"server.starttls()\n",
|
163 |
-
"server.login(a.mail,a.pw)\n",
|
164 |
-
"content = ''\n",
|
165 |
-
"payload = r\"C:\\Users\\dscshap3808\\Documents\\fapiao\\202109.pdf\"\n",
|
166 |
-
"a.sendEmailwithFile(account=a.mail, server=server, content=content, payload=payload, \n",
|
167 |
-
" receivers='siming.yan@sf-dsc.com')\n",
|
168 |
-
"server.quit()"
|
169 |
]
|
170 |
},
|
171 |
{
|
172 |
"cell_type": "code",
|
173 |
-
"execution_count":
|
174 |
"metadata": {},
|
175 |
"outputs": [],
|
176 |
"source": [
|
177 |
-
"
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
200 |
]
|
201 |
}
|
202 |
],
|
|
|
141 |
},
|
142 |
{
|
143 |
"cell_type": "code",
|
144 |
+
"execution_count": 4,
|
145 |
+
"metadata": {},
|
146 |
+
"outputs": [],
|
147 |
+
"source": [
|
148 |
+
"def parchecker(str1):\n",
|
149 |
+
" s = []\n",
|
150 |
+
" bal = True\n",
|
151 |
+
" index = 0\n",
|
152 |
+
" while index < len(str1) and bal:\n",
|
153 |
+
" symbol = str1[index]\n",
|
154 |
+
" print(s, symbol, 'aaaaaaaa')\n",
|
155 |
+
" if symbol == \"(\":\n",
|
156 |
+
" s.append(symbol) # -- 只有 ( 入栈\n",
|
157 |
+
" else:\n",
|
158 |
+
" if s == []:\n",
|
159 |
+
" bal = False\n",
|
160 |
+
" else:\n",
|
161 |
+
" s.pop() # -- 有一个 ) 则pop 一个\n",
|
162 |
+
" index += 1\n",
|
163 |
+
" \n",
|
164 |
+
" if bal and s == []:\n",
|
165 |
+
" return True \n",
|
166 |
+
" else:\n",
|
167 |
+
" return False"
|
168 |
+
]
|
169 |
+
},
|
170 |
+
{
|
171 |
+
"cell_type": "code",
|
172 |
+
"execution_count": 16,
|
173 |
+
"metadata": {},
|
174 |
+
"outputs": [],
|
175 |
+
"source": [
|
176 |
+
"def parchecker(str1):\n",
|
177 |
+
" s = []\n",
|
178 |
+
" bal = True\n",
|
179 |
+
" index = 0\n",
|
180 |
+
" while index < len(str1) and bal:\n",
|
181 |
+
" symbol = str1[index] \n",
|
182 |
+
" # ============================================================================ #\n",
|
183 |
+
" # 前括号 #\n",
|
184 |
+
" # ============================================================================ #\n",
|
185 |
+
" if symbol in \"([{\":\n",
|
186 |
+
" s.append(symbol) # -- 只有 ([{ 入栈\n",
|
187 |
+
" # ============================================================================ #\n",
|
188 |
+
" # 后括号 #\n",
|
189 |
+
" # ============================================================================ #\n",
|
190 |
+
" else: \n",
|
191 |
+
" if s == []:\n",
|
192 |
+
" bal = False\n",
|
193 |
+
" else:\n",
|
194 |
+
" top = s.pop() # -- 有一个 \")]}\" 则 pop 一个 ([{\n",
|
195 |
+
" if not matches(top, symbol):\n",
|
196 |
+
" bal = False\n",
|
197 |
+
" index += 1\n",
|
198 |
+
" # ============================================================================ #\n",
|
199 |
+
" # next #\n",
|
200 |
+
" # ============================================================================ #\n",
|
201 |
+
" if bal and s == []:\n",
|
202 |
+
" return True \n",
|
203 |
+
" else:\n",
|
204 |
+
" return False\n",
|
205 |
+
" \n",
|
206 |
+
"def matches(open, close):\n",
|
207 |
+
" opens = \"([{\"\n",
|
208 |
+
" closes = \")]}\"\n",
|
209 |
+
" return opens.index(open) == closes.index(close)\n",
|
210 |
+
"\n"
|
211 |
+
]
|
212 |
+
},
|
213 |
+
{
|
214 |
+
"cell_type": "code",
|
215 |
+
"execution_count": 18,
|
216 |
"metadata": {},
|
217 |
"outputs": [
|
218 |
{
|
219 |
+
"data": {
|
220 |
+
"text/plain": [
|
221 |
+
"True"
|
222 |
+
]
|
223 |
+
},
|
224 |
+
"execution_count": 18,
|
225 |
+
"metadata": {},
|
226 |
+
"output_type": "execute_result"
|
|
|
|
|
227 |
}
|
228 |
],
|
229 |
"source": [
|
230 |
+
"parchecker(\"((({})))\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
]
|
232 |
},
|
233 |
{
|
234 |
"cell_type": "code",
|
235 |
+
"execution_count": 19,
|
236 |
"metadata": {},
|
237 |
"outputs": [],
|
238 |
"source": [
|
239 |
+
"# 中序表达式转换后序, 前序"
|
240 |
+
]
|
241 |
+
},
|
242 |
+
{
|
243 |
+
"cell_type": "code",
|
244 |
+
"execution_count": 21,
|
245 |
+
"metadata": {},
|
246 |
+
"outputs": [],
|
247 |
+
"source": []
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"cell_type": "code",
|
251 |
+
"execution_count": 23,
|
252 |
+
"metadata": {},
|
253 |
+
"outputs": [
|
254 |
+
{
|
255 |
+
"data": {
|
256 |
+
"text/plain": [
|
257 |
+
"'123.jpg'"
|
258 |
+
]
|
259 |
+
},
|
260 |
+
"execution_count": 23,
|
261 |
+
"metadata": {},
|
262 |
+
"output_type": "execute_result"
|
263 |
+
}
|
264 |
+
],
|
265 |
+
"source": [
|
266 |
+
"name_mutate('./tmp_files/123.jpg')[0]"
|
267 |
]
|
268 |
}
|
269 |
],
|