Skip to content

Instantly share code, notes, and snippets.

@mdecourse
Last active November 28, 2021 13:48
Show Gist options
  • Select an option

  • Save mdecourse/b11a88a98655d41055c47f08fe94788f to your computer and use it in GitHub Desktop.

Select an option

Save mdecourse/b11a88a98655d41055c47f08fe94788f to your computer and use it in GitHub Desktop.
cad2021 scripts
cad2021 2a w5 Github 帳號
40823143
40923101 a40923101
40923102 40923102
40923103 40923103
40923104 409231044
40923105 40923105
40923106 40923106
40923107 40923107
40923108 40923108
40923109 CYC40923109
40923110 40923110
40923111 40923111
40923113
40923114 40923114
40923115 jason60714
40923116 40923116
40923117 40923117
40923118 40923118
40923119 40923119
40923120 40923120
40923121 40923121
40923122 40923122
40923123 40923123
40923124 40923124
40923125 40923125
40923126 40923126-1
40923127 40923127
40923128 40923128
40923129 40923129
40923130 40923130
40923131 40923131
40923133 40923133
40923134 40923134
40923135 40923135
40923136 40923136-1
40923137 s40923137
40923138 40923138
40923139 40923139
40923140 40923140
40923142 40923142
40923143 40923143
40923144 40923144
40923145 40923145
40923146 a40923146
40923147 40923147
40923148 40923148
40923149 40923149
40923150
40923151 40923151
40923152 40923152
40923153 40923153
40923154
40923156 40923156
40923157
40971134 40971134
cad2b w2 github account
40723126
40723135
40723217 40723217
40732331 40732331
40823115 40823115
40823117 pyc40823117
40823119
40823122 40823122
40823127 40823127
40823146 40823146
40823148 40823148
40823215
40871106 40871106
40923201 40923201
40923203 youshin40923203
40923204 40923204
40923205 40923205
40923206 40923206-1
40923207 40923207
40923208 nfu40923208
40923209 nfu40923209
40923210 40923210
40923211 a40923211
40923212 40923212
40923213 40923213
40923214 40923214
40923216 40923216
40923217 40923217
40923218 40923218
40923219 nfu40923219
40923220 40923220
40923221 40923221
40923223 40923223
40923224 s40923224
40923225 40923225
40923226 40923226
40923227 40923227
40923228 40923228
40923229 40923229
40923230 40923230
40923231 40923231
40923232 40923232
40923233 40923233
40923234 40923234
40923235 40923235
40923236 40923236
40923237 40923237
40923238 40923238
40923239 40923239
40923240 40923240
40923241 40923241
40923242 40923242
40923243 40923243
40923244 40923244
40923245 40923245-1
40923246 40923246
40923247 40923247
40923248 40923248
40923249 40923249-1
40923250 40923250
40923251 40923251
40923252 40923252
40923253 40923253
40971220 40971220
40971227 40971227
# 從 browser.local_storage 導入 storage
from browser.local_storage import storage
# 從 browser 導入 window, 主要在 Brython 中承接 Javascript 物件
from browser import window
# 假設目前資料存在 cmsimde 動態網站中的 downloads 目錄下
url = "./../downloads/spur.py.txt"
# 利用 open() 以及 read() 將資料取出
data = open(url).read()
# 瀏覽器中的程式運算結果可以暫存至 storage[] 中
storage["data"] = data
# 查驗所存入的資料是否正確
#print(storage["data"])
# 利用 window 將 Javascript 的 Blob 轉為 Brython 物件
blob = window.Blob.new
# 利用 blob 按照其內容格式編碼, 從 storage 中取出
blob = blob([storage["data"]],{"type": "text/plain;charset=utf-8"})
# 由 window 居中取用 Javascript 的 saveAS()
# 執行至此, 瀏覽器會跳出與近端檔案存檔有關的視窗, 同檔案下載流程
window.saveAs(blob, "test.txt")
print("done")
from browser import html
from browser import document
import random
brython_div = document["brython_div"]
url = "https://mde.tw/studlist/2021fall/2a.txt"
data = open(url).readlines()
# 檢查資料筆數, 第一筆為 title
#print(data)
#print(len(data))
data = data[1:]
#print(data)
# 根據 href 與 content 將 html 元件中的 anchor 插入頁面
def makeLink(href, content):
brython_div <= html.A(content, href=href)
#brython_div <= html.BR()
# 從學員資料中隨機取出 10 位學員的網頁進行查核
select = 10
#random.shuffle(data)
#data = data[:select]
course = "cad2021"
for i in range(len(data)):
num_github = data[i]
num = num_github.split("\t")[0]
account = num_github.split("\t")[1]
if account == "":
account = num
content = str(num)
hwhref = "https://"+ str(account) + ".github.io/"+course+ "_hw"
repohref = "https://github.com/"+ str(account) +"/"+course +"_hw"
brython_div <= "repo: "
makeLink(repohref, content)
brython_div <= " www: "
makeLink(hwhref, content)
brython_div <= html.BR()
from browser import html
from browser import document
import random
brython_div = document["brython_div"]
url = "https://mde.tw/studlist/2021fall/2a.txt"
data = open(url).readlines()
# 檢查資料筆數, 第一筆為 title
#print(data)
#print(len(data))
data = data[1:]
#print(data)
# 根據 href 與 content 將 html 元件中的 anchor 插入頁面
def makeLink(href, content):
brython_div <= html.A(content, href=href)
#brython_div <= html.BR()
# 從學員資料中隨機取出 10 位學員的網頁進行查核
select = 10
random.shuffle(data)
data = data[:select]
course = "cad2021"
for i in range(len(data)):
num_github = data[i]
num = num_github.split("\t")[0]
account = num_github.split("\t")[1]
if account == "":
account = num
content = str(num)
hwhref = "https://"+ str(account) + ".github.io/"+course+ "_hw"
repohref = "https://github.com/"+ str(account) +"/"+course +"_hw"
brython_div <= "repo: "
makeLink(repohref, content)
brython_div <= " www: "
makeLink(hwhref, content)
brython_div <= html.BR()
from browser import html
from browser import document
import random
brython_div = document["brython_div"]
url = "https://mde.tw/studlist/2021fall/2b.txt"
data = open(url).readlines()
# 檢查資料筆數, 第一筆為 title
#print(data)
#print(len(data))
data = data[1:]
#print(data)
# 根據 href 與 content 將 html 元件中的 anchor 插入頁面
def makeLink(href, content):
brython_div <= html.A(content, href=href)
#brython_div <= html.BR()
# 從學員資料中隨機取出 10 位學員的網頁進行查核
select = 10
#random.shuffle(data)
#data = data[:select]
course = "cad2021"
for i in range(len(data)):
num_github = data[i]
num = num_github.split("\t")[0]
account = num_github.split("\t")[1]
if account == "":
account = num
content = str(num)
hwhref = "https://"+ str(account) + ".github.io/"+course+ "_hw"
repohref = "https://github.com/"+ str(account) +"/"+course +"_hw"
brython_div <= "repo: "
makeLink(repohref, content)
brython_div <= " www: "
makeLink(hwhref, content)
brython_div <= html.BR()
from browser import html
from browser import document
import random
brython_div = document["brython_div"]
url = "https://mde.tw/studlist/2021fall/2b.txt"
data = open(url).readlines()
# 檢查資料筆數, 第一筆為 title
#print(data)
#print(len(data))
data = data[1:]
#print(data)
# 根據 href 與 content 將 html 元件中的 anchor 插入頁面
def makeLink(href, content):
brython_div <= html.A(content, href=href)
#brython_div <= html.BR()
# 從學員資料中隨機取出 10 位學員的網頁進行查核
select = 10
random.shuffle(data)
data = data[:select]
course = "cad2021"
for i in range(len(data)):
num_github = data[i]
num = num_github.split("\t")[0]
account = num_github.split("\t")[1]
if account == "":
account = num
content = str(num)
hwhref = "https://"+ str(account) + ".github.io/"+course+ "_hw"
repohref = "https://github.com/"+ str(account) +"/"+course +"_hw"
brython_div <= "repo: "
makeLink(repohref, content)
brython_div <= " www: "
makeLink(hwhref, content)
brython_div <= html.BR()
# 將資料存入 gist, 取其 url
url = "https://gist.githubusercontent.com/mdecourse/b11a88a98655d41055c47f08fe94788f/raw/8a27e6885ee1a5074bcf864d741679afeac796c4/2b_w2_stud_list.txt"
# 利用 open() 開啟 url 後, 以 readlines() 讀取後可納入數列
data = open(url).readlines()
# 檢查資料筆數, 第一筆為 title
#print(data)
#print(len(data))
data = data[1:]
#print(data)
for i in range(len(data)):
num_github = data[i]
num = num_github.split("\t")[0]
account = num_github.split("\t")[1]
if account == "":
account = num
print("<a href='https://" + str(account) + ".github.io/cad2021_hw'>"+ str(num) + "</a>")
<h2>run</h2>
<!-- 導入 brython 程式庫 -->
<script src="/static/brython.js"></script>
<script src="/static/brython_stdlib.js"></script>
<!-- 啟動 Brython -->
<script>// <![CDATA[
window.onload=function(){
brython({debug:1, pythonpath:['/static/','./../downloads/py/']});
}
// ]]></script>
<p><!-- 導入 FileSaver 與 filereader --></p>
<p>
<script type="text/javascript" src="/static/ace/FileSaver.min.js"></script>
<script type="text/javascript" src="/static/ace/filereader.js"></script>
</p>
<p><!-- 導入 ace --></p>
<p>
<script type="text/javascript" src="/static/ace/ace.js"></script>
<script type="text/javascript" src="/static/ace/ext-language_tools.js"></script>
<script type="text/javascript" src="/static/ace/mode-python3.js"></script>
<script type="text/javascript" src="/static/ace/snippets/python.js"></script>
</p>
<p><!-- 請注意, 這裡使用 Javascript 將 localStorage["py_src"] 中存在近端瀏覽器的程式碼, 由使用者決定存檔名稱--></p>
<p>
<script type="text/javascript">// <![CDATA[
function doSave(storage_id, filename){
var blob = new Blob([localStorage[storage_id]], {type: "text/plain;charset=utf-8"});
filename = document.getElementById(filename).value
saveAs(blob, filename+".py");
}
// ]]></script>
</p>
<p><!-- 印出版次與關鍵字程式 --></p>
<p>
<script type="text/python3">// <![CDATA[
from browser import document as doc
import ace
# 清除畫布
def clear_bd(ev):
bd = doc["brython_div"]
bd.clear()
# Brython 3.3.4 內建的 container 名稱為 'container' 且 turtle 輸出為 svg 必須使用 div 訂定 id
Ace = ace.Editor(editor_id="kw_editor", console_id="kw_console", container_id="kw__container", storage_id="kw_py_src" )
# 從 gist 取出程式碼後, 放入 editor 作為 default 程式
def run():
# 利用 get 取下 src 變數值
try:
url = doc.query["src"]
except:
url = "https://gist.githubusercontent.com/mdecourse/e896a4705a95ac8cc4147b355b0e87ef/raw/8954b8280c524c5781dc3c0b3565bc489d3aa3a3/cango_gear1.py"
prog = open(url).read()
# 將程式載入編輯區
Ace.editor.setValue(prog)
Ace.editor.scrollToRow(0)
Ace.editor.gotoLine(0)
# 直接執行程式
#ns = {'__name__':'__main__'}
#exec(prog, ns)
# 按下 run 按鈕
Ace.run()
# 執行程式, 顯示輸出結果與清除輸出結果及對應按鈕綁定
doc['kw_run'].bind('click', Ace.run)
doc['kw_show_console'].bind('click', Ace.show_console)
doc['kw_clear_console'].bind('click', Ace.clear_console)
doc['clear_bd'].bind('click', clear_bd)
# 呼叫函式執行
run()
// ]]></script>
</p>
<p><!-- 用來顯示程式碼的 editor 區域 --></p>
<div id="kw_editor" style="width: 600px; height: 300px;"></div>
<p><!-- 以下的表單與按鈕與前面的 Javascript doSave 函式以及 FileSaver.min.js 互相配合 --></p>
<!-- 存擋表單開始 --><form><label>Filename: <input id="kw_filename" placeholder="input file name" type="text">.py</label> <input onclick="doSave('kw_py_src', 'kw_filename');" type="submit" value="Save"></form><!-- 存擋表單結束 -->
<p></p>
<!-- 執行與清除按鈕開始 -->
<p><button id="kw_run">Run</button> <button id="kw_show_console">Output</button> <button id="kw_clear_console">清除輸出區</button><button id="clear_bd">清除繪圖區</button><button onclick="window.location.reload()">Reload</button></p>
<!-- 執行與清除按鈕結束 -->
<p></p>
<!-- 程式執行 ouput 區 -->
<div style="width: 100%; height: 100%;"><textarea autocomplete="off" id="kw_console"></textarea></div>
<!-- Brython 程式執行的結果, 都以 brython_div 作為切入位置 -->
<div id="brython_div"></div>
<!-- 導入 gearUtils-0.9.js Cango 齒輪繪圖程式庫 -->
<script src="https://mde.tw/cp2021/cmsimde/static/Cango-24v03-min.js"></script>
<script src="https://mde.tw/cp2021/cmsimde/static/gearUtils-09.js"></script>
<script src="https://mde.tw/cp2021/cmsimde/static/SVGpathUtils-6v03-min.js"></script>
<script src="https://mde.tw/cp2021/cmsimde/static/sylvester.js"></script>
<script src="https://mde.tw/cp2021/cmsimde/static/PrairieDraw.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment