summary refs log tree commit diff
diff options
context:
space:
mode:
authortzlil <tzlils@protonmail.com>2023-09-09 01:59:59 +0300
committertzlil <tzlils@protonmail.com>2023-09-09 01:59:59 +0300
commita7cafdeeb5624fbac2296861e491681f6b862dd7 (patch)
tree4d44ee45fb09bfa6e3b9b8153df68b4532c54fd1
parentd09927ca6f7af2404e9c3a09a6e99dfdd1e87577 (diff)
whitelist categories
-rw-r--r--app.py7
-rw-r--r--templates/index.html4
2 files changed, 6 insertions, 5 deletions
diff --git a/app.py b/app.py
index b910046..fe84158 100644
--- a/app.py
+++ b/app.py
@@ -56,9 +56,8 @@ def get_probability_distribution(topic):
 
 
 taxonomy = [
-    'cs', 'econ', 'eess', 'math', 'astro-ph', 'cond-mat', 'gr-qc', 'hep-ex',
-    'hep-lat', 'hep-ph', 'hep-th', 'math-ph', 'nlin', 'nucl-ex', 'nucl-th',
-    'physics', 'quant-ph', 'q-bio', 'q-fin', 'stat'
+    'cs', 'math', 'physics', 'econ', 'eess',  'astro-ph', 'cond-mat', 'gr-qc', 'hep-ex',
+    'hep-lat', 'hep-ph', 'hep-th', 'math-ph', 'nlin', 'nucl-ex', 'nucl-th', 'quant-ph', 'q-bio', 'q-fin', 'stat'
 ]
 
 app = Flask(__name__)
@@ -71,6 +70,8 @@ def favicon():
 
 @app.route('/<topic>', methods=['GET'])
 def random(topic):
+    if topic not in taxonomy:
+        return abort(500)
     l = get_links(topic)
     p = get_probability_distribution(topic)
     d = np.random.choice(l, p=p)
diff --git a/templates/index.html b/templates/index.html
index cb91326..834cec9 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -10,8 +10,8 @@
 <pre>
 this website pulls a random arXiv publication for a given category
 <a href="https://git.tzlil.net/arXiv.git" title="if you're wondering why my code needs to scrape arXiv and build probability distributions see fuck you.py">source code</a>
-all categories: <a href="https://arxiv.org/category_taxonomy">here</a>
-examples:
+taxonomy: <a href="https://arxiv.org/category_taxonomy">here</a>
+categories:
 {% for i in taxonomy %}
   <a href='{{ i }}'>{{ i }}</a>
 {% endfor %}