fyenne commited on
Commit
bc34042
1 Parent(s): e5ce045

done with email.

Browse files
Files changed (6) hide show
  1. js_script.js +8 -0
  2. jslearn.html +14 -0
  3. mail_sender.py +36 -23
  4. pages/❄️p2.py +2 -0
  5. pages/🎉p3.py +44 -11
  6. 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
- part1 = MIMEBase('application', "octet-stream")
38
- # part1.set_payload(payload)
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
- msg.attach(part1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- print('connecting...')
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
- print("SUCCESS", i)
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
- print("SUCCESS", receivers)
97
  else:
98
- raise Exception("mothenfucker")
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
- # a.run_('a', payload=None, receivers='fyenne@hotmail.com')
 
 
 
 
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
- file = st.file_uploader(label="file uploader",
35
  accept_multiple_files = True)
36
-
37
-
38
-
 
 
 
 
 
39
  bt = st.button('send')
40
 
 
 
41
  if bt:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  a = config()
43
- print(receiver)
44
- res = a.run_(content = str(content), payload=file, receivers = receiver)
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": 3,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  "metadata": {},
146
  "outputs": [
147
  {
148
- "ename": "AttributeError",
149
- "evalue": "'str' object has no attribute 'name'",
150
- "output_type": "error",
151
- "traceback": [
152
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
153
- "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
154
- "\u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\test.ipynb Cell 9\u001b[0m in \u001b[0;36m<cell line: 6>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=3'>4</a>\u001b[0m content \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=4'>5</a>\u001b[0m payload \u001b[39m=\u001b[39m \u001b[39mr\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mC:\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mUsers\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mdscshap3808\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mDocuments\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mfapiao\u001b[39m\u001b[39m\\\u001b[39m\u001b[39m202109.pdf\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=5'>6</a>\u001b[0m a\u001b[39m.\u001b[39;49msendEmailwithFile(account\u001b[39m=\u001b[39;49ma\u001b[39m.\u001b[39;49mmail, server\u001b[39m=\u001b[39;49mserver, content\u001b[39m=\u001b[39;49mcontent, payload\u001b[39m=\u001b[39;49mpayload, \n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=6'>7</a>\u001b[0m receivers\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39msiming.yan@sf-dsc.com\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=7'>8</a>\u001b[0m server\u001b[39m.\u001b[39mquit()\n",
155
- "File \u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\mail_sender.py:41\u001b[0m, in \u001b[0;36mconfig.sendEmailwithFile\u001b[1;34m(self, account, server, content, payload, receivers)\u001b[0m\n\u001b[0;32m 39\u001b[0m part1\u001b[39m.\u001b[39mset_payload(\u001b[39mopen\u001b[39m(payload, \u001b[39m\"\u001b[39m\u001b[39mrb\u001b[39m\u001b[39m\"\u001b[39m)\u001b[39m.\u001b[39mread())\n\u001b[0;32m 40\u001b[0m encoders\u001b[39m.\u001b[39mencode_base64(part1)\n\u001b[1;32m---> 41\u001b[0m \u001b[39mprint\u001b[39m(re\u001b[39m.\u001b[39mfindall(\u001b[39m'\u001b[39m\u001b[39m\\\u001b[39m\u001b[39m.\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mw+\u001b[39m\u001b[39m'\u001b[39m, payload\u001b[39m.\u001b[39;49mname))\n\u001b[0;32m 42\u001b[0m \u001b[39m# output_name1 = (payload)\u001b[39;00m\n\u001b[0;32m 43\u001b[0m part1\u001b[39m.\u001b[39madd_header(\u001b[39m'\u001b[39m\u001b[39mContent-Disposition\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mattachment\u001b[39m\u001b[39m'\u001b[39m, filename\u001b[39m=\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mutf-8\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39m'\u001b[39m, payload\u001b[39m.\u001b[39mname))\n",
156
- "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'name'"
157
- ]
158
  }
159
  ],
160
  "source": [
161
- "server = smtplib.SMTP(\"smtp.office365.com\", 587)\n",
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": null,
174
  "metadata": {},
175
  "outputs": [],
176
  "source": [
177
- "\n",
178
- "# # Contents of ~/my_app/streamlit_app.py\n",
179
- "\n",
180
- "# def main_page():\n",
181
- "# st.markdown(\"# Main page 🎈\")\n",
182
- "# st.sidebar.markdown(\"# Main page 🎈\")\n",
183
- "\n",
184
- "# def page2():\n",
185
- "# st.markdown(\"# Page 2 ❄️\")\n",
186
- "# st.sidebar.markdown(\"# Page 2 ❄️\")\n",
187
- "\n",
188
- "# def page3():\n",
189
- "# st.markdown(\"# Page 3 🎉\")\n",
190
- "# st.sidebar.markdown(\"# Page 3 🎉\")\n",
191
- "\n",
192
- "# page_names_to_funcs = {\n",
193
- "# \"Main Page\": main_page,\n",
194
- "# \"Page 2\": page2,\n",
195
- "# \"Page 3\": page3,\n",
196
- "# }\n",
197
- "\n",
198
- "# selected_page = st.sidebar.selectbox(\"Select a page\", page_names_to_funcs.keys())\n",
199
- "# page_names_to_funcs[selected_page]()\n"
 
 
 
 
 
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
  ],