Browse Source

Find way to display articles content from API

Carlos Hernandez 3 years ago
parent
commit
78de320aef

+ 138
- 0
.gitignore View File

1
+# Byte-compiled / optimized / DLL files
2
+__pycache__/
3
+*.py[cod]
4
+*$py.class
5
+
6
+# C extensions
7
+*.so
8
+
9
+# Distribution / packaging
10
+.Python
11
+build/
12
+develop-eggs/
13
+dist/
14
+downloads/
15
+eggs/
16
+.eggs/
17
+lib/
18
+lib64/
19
+parts/
20
+sdist/
21
+var/
22
+wheels/
23
+share/python-wheels/
24
+*.egg-info/
25
+.installed.cfg
26
+*.egg
27
+MANIFEST
28
+
29
+# PyInstaller
30
+#  Usually these files are written by a python script from a template
31
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+*.manifest
33
+*.spec
34
+
35
+# Installer logs
36
+pip-log.txt
37
+pip-delete-this-directory.txt
38
+
39
+# Unit test / coverage reports
40
+htmlcov/
41
+.tox/
42
+.nox/
43
+.coverage
44
+.coverage.*
45
+.cache
46
+nosetests.xml
47
+coverage.xml
48
+*.cover
49
+*.py,cover
50
+.hypothesis/
51
+.pytest_cache/
52
+cover/
53
+
54
+# Translations
55
+*.mo
56
+*.pot
57
+
58
+# Django stuff:
59
+*.log
60
+local_settings.py
61
+db.sqlite3
62
+db.sqlite3-journal
63
+
64
+# Flask stuff:
65
+instance/
66
+.webassets-cache
67
+
68
+# Scrapy stuff:
69
+.scrapy
70
+
71
+# Sphinx documentation
72
+docs/_build/
73
+
74
+# PyBuilder
75
+.pybuilder/
76
+target/
77
+
78
+# Jupyter Notebook
79
+.ipynb_checkpoints
80
+
81
+# IPython
82
+profile_default/
83
+ipython_config.py
84
+
85
+# pyenv
86
+#   For a library or package, you might want to ignore these files since the code is
87
+#   intended to run in multiple environments; otherwise, check them in:
88
+# .python-version
89
+
90
+# pipenv
91
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+#   install all needed dependencies.
95
+#Pipfile.lock
96
+
97
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98
+__pypackages__/
99
+
100
+# Celery stuff
101
+celerybeat-schedule
102
+celerybeat.pid
103
+
104
+# SageMath parsed files
105
+*.sage.py
106
+
107
+# Environments
108
+.env
109
+.venv
110
+env/
111
+venv/
112
+ENV/
113
+env.bak/
114
+venv.bak/
115
+
116
+# Spyder project settings
117
+.spyderproject
118
+.spyproject
119
+
120
+# Rope project settings
121
+.ropeproject
122
+
123
+# mkdocs documentation
124
+/site
125
+
126
+# mypy
127
+.mypy_cache/
128
+.dmypy.json
129
+dmypy.json
130
+
131
+# Pyre type checker
132
+.pyre/
133
+
134
+# pytype static type analyzer
135
+.pytype/
136
+
137
+# Cython debug symbols
138
+cython_debug/

+ 4
- 0
Files-API/articles/article_1.txt View File

1
+Utilitatis causa amicitia est quaesita.
2
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Collatio igitur ista te nihil iuvat. Honesta oratio, Socratica, Platonis etiam. Primum in nostrane potestate est, quid meminerimus? Duo Reges: constructio interrete. Quid, si etiam iucunda memoria est praeteritorum malorum? Si quidem, inquit, tollerem, sed relinquo. An nisi populari fama?
3
+
4
+Quamquam id quidem licebit iis existimare, qui legerint. Summum a vobis bonum voluptas dicitur. At hoc in eo M. Refert tamen, quo modo. Quid sequatur, quid repugnet, vident. Iam id ipsum absurdum, maximum malum neglegi.

+ 13
- 0
Files-API/articles/article_2.txt View File

1
+Aeque enim contingit omnibus fidibus, ut incontentae sint.
2
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quae cum ita sint, effectum est nihil esse malum, quod turpe non sit. Itaque nostrum est-quod nostrum dico, artis est-ad ea principia, quae accepimus. Quod totum contra est. Duo Reges: constructio interrete. Atqui iste locus est, Piso, tibi etiam atque etiam confirmandus, inquam; Quamvis enim depravatae non sint, pravae tamen esse possunt. Duarum enim vitarum nobis erunt instituta capienda.
3
+
4
+Non igitur de improbo, sed de callido improbo quaerimus, qualis Q. Audio equidem philosophi vocem, Epicure, sed quid tibi dicendum sit oblitus es. Ex ea difficultate illae fallaciloquae, ut ait Accius, malitiae natae sunt. At multis malis affectus. Nam quibus rebus efficiuntur voluptates, eae non sunt in potestate sapientis. Quis est tam dissimile homini. Ut proverbia non nulla veriora sint quam vestra dogmata. Si quicquam extra virtutem habeatur in bonis. Sed plane dicit quod intellegit. Paulum, cum regem Persem captum adduceret, eodem flumine invectio?
5
+
6
+Qui ita affectus, beatum esse numquam probabis; Sed nimis multa. Nam prius a se poterit quisque discedere quam appetitum earum rerum, quae sibi conducant, amittere. Familiares nostros, credo, Sironem dicis et Philodemum, cum optimos viros, tum homines doctissimos. Quod iam a me expectare noli. Quid ergo?
7
+
8
+Eademne, quae restincta siti? Ita relinquet duas, de quibus etiam atque etiam consideret. Illa videamus, quae a te de amicitia dicta sunt. Eaedem res maneant alio modo. Quid ergo attinet gloriose loqui, nisi constanter loquare? Prioris generis est docilitas, memoria; Portenta haec esse dicit, neque ea ratione ullo modo posse vivi; Beatum, inquit. Bestiarum vero nullum iudicium puto.
9
+
10
+Quem Tiberina descensio festo illo die tanto gaudio affecit, quanto L. Quorum sine causa fieri nihil putandum est. Tria genera bonorum; Nunc dicam de voluptate, nihil scilicet novi, ea tamen, quae te ipsum probaturum esse confidam. Illud dico, ea, quae dicat, praeclare inter se cohaerere. Fortemne possumus dicere eundem illum Torquatum? Hoc tu nunc in illo probas. Cur post Tarentum ad Archytam?
11
+
12
+Indicant pueri, in quibus ut in speculis natura cernitur.
13
+Sed tamen est aliquid, quod nobis non liceat, liceat illis. Virtutis, magnitudinis animi, patientiae, fortitudinis fomentis dolor mitigari solet. Piso igitur hoc modo, vir optimus tuique, ut scis, amantissimus. Non prorsus, inquit, omnisque, qui sine dolore sint, in voluptate, et ea quidem summa, esse dico. Potius inflammat, ut coercendi magis quam dedocendi esse videantur. Virtutis, magnitudinis animi, patientiae, fortitudinis fomentis dolor mitigari solet. Quae fere omnia appellantur uno ingenii nomine, easque virtutes qui habent, ingeniosi vocantur. Nec enim, dum metuit, iustus est, et certe, si metuere destiterit, non erit;

+ 21
- 0
Files-API/articles/article_3.txt View File

1
+Quod equidem non reprehendo;
2
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quibus natura iure responderit non esse verum aliunde finem beate vivendi, a se principia rei gerendae peti; Quae enim adhuc protulisti, popularia sunt, ego autem a te elegantiora desidero. Duo Reges: constructio interrete. Tum Lucius: Mihi vero ista valde probata sunt, quod item fratri puto. Bestiarum vero nullum iudicium puto. Nihil enim iam habes, quod ad corpus referas; Deinde prima illa, quae in congressu solemus: Quid tu, inquit, huc? Et homini, qui ceteris animantibus plurimum praestat, praecipue a natura nihil datum esse dicemus?
3
+
4
+Iam id ipsum absurdum, maximum malum neglegi. Quod ea non occurrentia fingunt, vincunt Aristonem; Atqui perspicuum est hominem e corpore animoque constare, cum primae sint animi partes, secundae corporis. Fieri, inquam, Triari, nullo pacto potest, ut non dicas, quid non probes eius, a quo dissentias. Equidem e Cn. An dubium est, quin virtus ita maximam partem optineat in rebus humanis, ut reliquas obruat?
5
+
6
+Quis istum dolorem timet?
7
+Summus dolor plures dies manere non potest? Dicet pro me ipsa virtus nec dubitabit isti vestro beato M. Tubulum fuisse, qua illum, cuius is condemnatus est rogatione, P. Quod si ita sit, cur opera philosophiae sit danda nescio.
8
+
9
+Ex eorum enim scriptis et institutis cum omnis doctrina liberalis, omnis historia.
10
+Quod si ita est, sequitur id ipsum, quod te velle video, omnes semper beatos esse sapientes. Cum enim fertur quasi torrens oratio, quamvis multa cuiusque modi rapiat, nihil tamen teneas, nihil apprehendas, nusquam orationem rapidam coerceas. Ita redarguitur ipse a sese, convincunturque scripta eius probitate ipsius ac moribus. At quanta conantur! Mundum hunc omnem oppidum esse nostrum! Incendi igitur eos, qui audiunt, vides. Vide, ne magis, inquam, tuum fuerit, cum re idem tibi, quod mihi, videretur, non nova te rebus nomina inponere. Qui-vere falsone, quaerere mittimus-dicitur oculis se privasse; Si ista mala sunt, in quae potest incidere sapiens, sapientem esse non esse ad beate vivendum satis. At vero si ad vitem sensus accesserit, ut appetitum quendam habeat et per se ipsa moveatur, quid facturam putas?
11
+
12
+Quem si tenueris, non modo meum Ciceronem, sed etiam me ipsum abducas licebit.
13
+Stulti autem malorum memoria torquentur, sapientes bona praeterita grata recordatione renovata delectant.
14
+Esse enim quam vellet iniquus iustus poterat inpune.
15
+Quae autem natura suae primae institutionis oblita est?
16
+Verum tamen cum de rebus grandioribus dicas, ipsae res verba rapiunt;
17
+Hoc est non modo cor non habere, sed ne palatum quidem.
18
+Voluptatem cum summum bonum diceret, primum in eo ipso parum vidit, deinde hoc quoque alienum; Sed tu istuc dixti bene Latine, parum plane. Nam haec ipsa mihi erunt in promptu, quae modo audivi, nec ante aggrediar, quam te ab istis, quos dicis, instructum videro. Fatebuntur Stoici haec omnia dicta esse praeclare, neque eam causam Zenoni desciscendi fuisse. Non autem hoc: igitur ne illud quidem. Ratio quidem vestra sic cogit. Cum audissem Antiochum, Brute, ut solebam, cum M. An quod ita callida est, ut optime possit architectari voluptates?
19
+
20
+Idemne, quod iucunde?
21
+Haec mihi videtur delicatior, ut ita dicam, molliorque ratio, quam virtutis vis gravitasque postulat. Sed quoniam et advesperascit et mihi ad villam revertendum est, nunc quidem hactenus; Cuius ad naturam apta ratio vera illa et summa lex a philosophis dicitur. Neque solum ea communia, verum etiam paria esse dixerunt. Sed nunc, quod agimus; A mene tu?

+ 1
- 0
Files-API/articles/article_4.txt View File

1
+Hello world!

+ 32
- 0
Files-API/files_api.py View File

1
+import os
2
+from flask import Flask, send_from_directory, jsonify
3
+from flask_cors import CORS, cross_origin
4
+
5
+
6
+app = Flask(__name__, static_url_path='')
7
+app.config["SECRET_KEY"] = "f82abccd93a28b6cdda4525c9afa7a30"
8
+app.config["CORS_HEADERS"] = "Content-Type"
9
+
10
+cors = CORS(app, resources={r"/articles": {"origins": "http://localhost:5500"}})
11
+
12
+
13
+@app.route("/articles/<path:article>")
14
+@cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
15
+def send_text_file(article):
16
+    return send_from_directory(directory="articles", path=article)
17
+
18
+
19
+@app.route("/articles")
20
+@cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
21
+def list_files():
22
+    files = list()
23
+    for filename in os.listdir("articles"):
24
+        path = os.path.join("articles", filename)
25
+        if os.path.isfile(path):
26
+            files.append(filename)
27
+    return jsonify(files)
28
+
29
+
30
+if __name__ == "__main__":
31
+    app.run()
32
+

+ 24
- 0
Files-API/requirements.txt View File

1
+backcall==0.2.0
2
+click==8.0.3
3
+decorator==5.1.0
4
+flake8==4.0.1
5
+Flask==2.0.2
6
+ipython==7.29.0
7
+itsdangerous==2.0.1
8
+jedi==0.18.0
9
+Jinja2==3.0.2
10
+MarkupSafe==2.0.1
11
+matplotlib-inline==0.1.3
12
+mccabe==0.6.1
13
+parso==0.8.2
14
+pexpect==4.8.0
15
+pickleshare==0.7.5
16
+pkg_resources==0.0.0
17
+prompt-toolkit==3.0.21
18
+ptyprocess==0.7.0
19
+pycodestyle==2.8.0
20
+pyflakes==2.4.0
21
+Pygments==2.10.0
22
+traitlets==5.1.1
23
+wcwidth==0.2.5
24
+Werkzeug==2.0.2

+ 183
- 0
app_template/www/articles.html View File

1
+
2
+<!DOCTYPE html>
3
+<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
4
+<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
5
+<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
6
+<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
7
+	<head>
8
+		<meta charset="utf-8">
9
+		<meta http-equiv="X-UA-Compatible" content="IE=edge">
10
+		<title>dato.pr</title>
11
+		<meta name="viewport" content="width=device-width, initial-scale=1">
12
+		<meta name="description" content="No" />
13
+
14
+			<!-- Facebook and Twitter integration -->
15
+		<meta property="og:title" content=""/>
16
+		<meta property="og:image" content=""/>
17
+		<meta property="og:url" content=""/>
18
+		<meta property="og:site_name" content=""/>
19
+		<meta property="og:description" content=""/>
20
+		<meta name="twitter:title" content="" />
21
+		<meta name="twitter:image" content="" />
22
+		<meta name="twitter:url" content="" />
23
+		<meta name="twitter:card" content="" />
24
+
25
+		<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
26
+		<link rel="shortcut icon" href="favicon.ico">
27
+
28
+		<link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700" rel="stylesheet">
29
+
30
+		<!-- Custom css -->
31
+		<link rel="stylesheet" href="css/main.css">
32
+
33
+		<!-- Animate.css -->
34
+		<link rel="stylesheet" href="css/animate.css">
35
+		<!-- Icomoon Icon Fonts-->
36
+		<link rel="stylesheet" href="css/icomoon.css">
37
+		<!-- Simple Line Icons -->
38
+		<link rel="stylesheet" href="css/simple-line-icons.css">
39
+		<!-- Bootstrap  -->
40
+		<link rel="stylesheet" href="css/bootstrap.css">
41
+		<!-- Style -->
42
+		<link rel="stylesheet" href="css/style.css">
43
+
44
+
45
+		<!-- Modernizr JS -->
46
+		<script src="js/modernizr-2.6.2.min.js"></script>
47
+		<!-- FOR IE9 below -->
48
+		<!--[if lt IE 9]>
49
+		<script src="js/respond.min.js"></script>
50
+		<![endif]-->
51
+
52
+		<!-- Custom JS -->
53
+		<script src="sortposts.js"></script>
54
+		<script src="fetch_articles.js"></script>
55
+
56
+		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
57
+		<script>
58
+			var articles;
59
+			axios.get(`http://localhost:5000/articles`)
60
+					.then(response => {
61
+						articles = response.data;
62
+
63
+						for (element of articles) {
64
+							axios.get(`http://localhost:5000/articles/${element}`)
65
+								.then(response => {
66
+									let articlesHeading = document.querySelector("#articles-heading");
67
+									let articleElm = document.createElement("pre");
68
+									articleElm.textContent = response.data;
69
+									articlesHeading.appendChild(articleElm);
70
+								})
71
+								.catch(error => console.error(error));
72
+						}
73
+					})
74
+					.catch(error => console.error(error));
75
+
76
+		</script>
77
+	</head>
78
+	<body>
79
+	<header role="banner" id="fh5co-header">
80
+		<div class="fluid-container">
81
+			<nav class="navbar navbar-default navbar-fixed-top js-fullheight">
82
+				<div id="navbar" class="navbar-collapse js-fullheight">
83
+					<ul class="nav navbar-nav navbar-left">
84
+						<li class="active"><a href="#" data-nav-section="home"><span>Home</span></a></li>
85
+						<li><a href="#" data-nav-section="services"><span>Services</span></a></li>
86
+					</ul>
87
+				</div>
88
+			</nav>
89
+	  </div>
90
+	</header>
91
+
92
+	<section id="fh5co-home" data-section="home" style="background-image: url(images/project-5.jpg);">
93
+		<div class="gradient"></div>
94
+		<div class="container">
95
+			<div class="text-wrap">
96
+				<div class="text-inner">
97
+					<div class="row">
98
+						<div class="col-md-8 col-md-offset-2 text-center">
99
+							<h1 style="color :white;" class="to-animate">dato.pr</h1>
100
+							<h2 style="color :white;" class="to-animate">"Estudiando lo ambiguo e investigando lo desconocido."</h2>
101
+						</div>
102
+					</div>
103
+				</div>
104
+			</div>
105
+		</div>
106
+	</section>
107
+
108
+	<section id="fh5co-services" data-section="services">
109
+		<div class="fh5co-services">
110
+			<div class="container">
111
+				<div class="row">
112
+					<div class="col-md-12 section-heading text-center">
113
+						<h2 class="to-animate">Home</h2>
114
+						<div class="row">
115
+							<div class="col-md-8 col-md-offset-2 subtext">
116
+								<h3 class="to-animate"> Hablando sobre lo que importa. </h3>
117
+							</div>
118
+						</div>
119
+					</div>
120
+				</div>
121
+				<div class="row">
122
+					<div class="core-features">
123
+						<div class="grid2">
124
+							<div id="rows-parent" class="core-f">
125
+								<div class="row" id="articles-row">
126
+									<div class="col-md-12">
127
+										<div class="core">
128
+											<i class="icon-columns to-animate-2"></i>
129
+											<div class="fh5co-post to-animate">
130
+												<!-- <h3 async onload="fetchArticle();">Articles</h3> -->
131
+												<h3 id="articles-heading">Articles</h3>
132
+											</div>
133
+										</div>
134
+									</div>
135
+								</div>
136
+							</div>
137
+						</div>
138
+					</div>
139
+				</div>
140
+				<div id="fh5co-counter-section" class="fh5co-counters">
141
+					<div class="container">
142
+						<div class="row to-animate">
143
+							<div class="col-md-3 text-center">
144
+								<span class="fh5co-counter js-counter" data-from="0" data-to="3452" data-speed="5000" data-refresh-interval="50"></span>
145
+								<span class="fh5co-counter-label">Tazas de Café Consumidas</span>
146
+							</div>
147
+							<div class="col-md-3 text-center">
148
+								<span class="fh5co-counter js-counter" data-from="0" data-to="234" data-speed="5000" data-refresh-interval="50"></span>
149
+								<span class="fh5co-counter-label">Días sin Luz</span>
150
+							</div>
151
+							<div class="col-md-3 text-center">
152
+								<span class="fh5co-counter js-counter" data-from="0" data-to="6542" data-speed="5000" data-refresh-interval="50"></span>
153
+								<span class="fh5co-counter-label">Cosas que Hacer</span>
154
+							</div>
155
+							<div class="col-md-3 text-center">
156
+								<span class="fh5co-counter js-counter" data-from="0" data-to="0" data-speed="5000" data-refresh-interval="50"></span>
157
+								<span class="fh5co-counter-label">Tiempo para perder</span>
158
+							</div>
159
+						</div>
160
+					</div>
161
+				</div>
162
+			</div>
163
+		</div>
164
+	</section>
165
+
166
+
167
+	<!-- jQuery -->
168
+	<script src="js/jquery.min.js"></script>
169
+	<!-- jQuery Easing -->
170
+	<script src="js/jquery.easing.1.3.js"></script>
171
+	<!-- Bootstrap -->
172
+	<script src="js/bootstrap.min.js"></script>
173
+	<!-- Waypoints -->
174
+	<script src="js/jquery.waypoints.min.js"></script>
175
+	<!-- Stellar Parallax -->
176
+	<script src="js/jquery.stellar.min.js"></script>
177
+	<!-- Counters -->
178
+	<script src="js/jquery.countTo.js"></script>
179
+	<!-- Main JS (Do not remove) -->
180
+	<script src="js/main.js"></script>
181
+
182
+	</body>
183
+</html>

+ 12
- 0
app_template/www/fetch_articles.js View File

1
+async function fetchArticle() {
2
+    let response = await fetch("http://localhost:5000/articles/article_1.txt");
3
+
4
+    console.log(response);
5
+    console.log(response.status);
6
+    console.log(response.statusText);
7
+
8
+    if (response.status == 200) {
9
+        let data = await response.text();
10
+        document.querySelector("#preview-text").textContent = data;
11
+    }
12
+}