Isabel Gwara commited on
Commit
3a586d4
·
1 Parent(s): ffdaafd

Create reader.py

Browse files
Files changed (1) hide show
  1. reader.py +79 -0
reader.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from yattag import Doc
3
+
4
+ ## --------------------------------- ###
5
+ ### reading: info.txt ###
6
+ ### -------------------------------- ###
7
+ # placeholders in case info.txt does not exist
8
+
9
+ def get_article():
10
+ filename = "info.txt"
11
+ placeholder = "please create an info.txt to customize this text"
12
+
13
+ title = bkgd = data_collection = priv_cons = bias_cons = ident_cons = img_src = membs = placeholder
14
+ description = "An AI project created by [name], [name], and [name]"
15
+ # check if info.txt is present
16
+ if os.path.isfile(filename):
17
+ # open info.txt in read mode
18
+ info = open(filename, "r")
19
+
20
+ # each line to a string
21
+ title = info.readline()
22
+ bkgd = info.readline()
23
+ data_collection = info.readline()
24
+ priv_cons = info.readline()
25
+ bias_cons = info.readline()
26
+ ident_cons = info.readline()
27
+ img_src = info.readline()
28
+ membs = info.readline()
29
+
30
+ # close file
31
+ info.close()
32
+
33
+ # use yattag library to generate html
34
+ doc, tag, text, line = Doc().ttl()
35
+ # create html based on info.txt
36
+ with tag('div'):
37
+ with tag('div', klass='my-div'):
38
+ line('h2', 'Project Background')
39
+ line('p', bkgd)
40
+ with tag('div', klass='my-div'):
41
+ line('h2', 'Data Collection')
42
+ line('p', data_collection)
43
+ with tag('div', klass='my-div'):
44
+ line('h2', 'Ethical Considerations')
45
+ with tag('ul'):
46
+ line('li', priv_cons)
47
+ line('li', bias_cons)
48
+ line('li', ident_cons)
49
+ with tag('div', klass='my-div'):
50
+ line('h2', 'Our Team')
51
+ line('p', membs)
52
+ doc.stag('img', src=img_src)
53
+
54
+ css = '''
55
+ .my-div {
56
+ border: 2px solid black;
57
+ text-align: center;
58
+ margin: 10px;
59
+ padding: 5%;
60
+ }
61
+ ul {
62
+ display: inline-block;
63
+ text-align: left;
64
+ }
65
+ img {
66
+ display: block;
67
+ margin: auto;
68
+ }
69
+ .description {
70
+ text-align: center;
71
+ }
72
+ '''
73
+
74
+ return {
75
+ 'article': doc.getvalue(),
76
+ 'css': css,
77
+ 'title': title,
78
+ 'description': description,
79
+ }