-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathget_example_from_de_brauwer.py
More file actions
47 lines (33 loc) · 1.11 KB
/
get_example_from_de_brauwer.py
File metadata and controls
47 lines (33 loc) · 1.11 KB
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
__author__ = "ipetrash"
import re
import os
from grab import Grab
"""Пример получения исходного кода с сайта www.de-brauwer.be."""
def get_example_from_de_brauwer(wakka):
g = Grab()
g.go("http://www.de-brauwer.be/wiki/wikka.php?wakka=" + wakka)
code_html = g.doc.select('//div[@class="code"]').html()
pattern = r'(<div class="code".*?>)' "|</div.*?>" "|<span.*?>" "|</span.*?>" "|<br>"
source_code = re.sub(pattern, "", code_html)
source_code = re.sub("\xa0", " ", source_code) # remove
return source_code
DIR_NAME = "PyOpenGLExample"
os.makedirs(DIR_NAME, exist_ok=True)
examples = [
"PyOpenGLHelloWorld",
"PyOpenGLSierpinski",
"PyOpenGLSquares",
"PyOpenGLCheckerBoard",
"PyOpenGLMouse",
"PyOpenGLScatter",
"PyOpenGLGingerbread",
"PyOpenGLMaze",
"PyOpenGLReshape",
"PyOpenGLTurtle",
"PyOpenGLRosette",
"PyOpenGLWireframe",
]
for e in examples:
source_code = get_example_from_de_brauwer(e)
with open(os.path.join(DIR_NAME, e + ".py"), mode="w", encoding="utf-8") as f:
f.write(source_code)