zipperer / migrate_database_with_michael

0 stars 0 forks source link

Make application that uses the database to link message numbers with <timestamp, book, chapter, verse> entries #50

Open zipperer opened 8 months ago

zipperer commented 8 months ago

For example:

zipperer commented 8 months ago

Examples: command line interface

get_book_chapter_verse_timestamps_for_program_number.py

get_book_chapter_verse_timestamps_for_program_number.sh

zipperer commented 8 months ago

Example: web interface (local webpage; not hosted on public web)

See files in directory flask_app

$ cd flask_app                                                                                        
$ python3 -m venv .venv                                                                               
$ source .venv/bin/activate                                                                           
(venv) $ python3 -m pip install flask                                                                 
(venv) $ python3 -m pip install psycopg2-binary                                                       
(venv) $ flask run --port 5002 

Then in a web browser visit localhost:5002/timestamped_verses/table/3192, in general localhost:5002/timestamped_verses/table/<message-id>

Screenshots

flask_app_example_page_message_3192

flask_app_example_page_message_3193

zipperer commented 8 months ago

open tabs

https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask

https://www.psycopg.org/docs/install.html#quick-install https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_cellpadding https://www.w3schools.com/html/html_table_padding_spacing.asp

zipperer commented 8 months ago

See files in directory flask_app

Basic idea:

zipperer commented 8 months ago

Example: web interface (local webpage; not hosted on public web) ... Then in a web browser visit localhost:5002/timestamped_verses/table/3192, in general >localhost:5002/timestamped_verses/table/

We can now view these pages on public web.

zipperer commented 8 months ago

edits to get flask app on zipperer.dev

/etc/nginx/nginx.conf

http {
        server {
        ...
+          location /grace_and_truth {
+            proxy_pass http://localhost:5002; # e.g. https://zipperer.dev/grace_and_truth/timestamped_verses/table/3194                           
+        proxy_redirect off;
+            proxy_set_header Host $host;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

^ see https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux

5002 comes from flask run --port 5002. TODO: use gunicorn (or other production web server) as Miguel describes.

routes.py

- @app.route('/timestamped_verses/table/<int:message_id>', methods=['GET'])                                                                           
+ @app.route('/grace_and_truth/timestamped_verses/table/<int:message_id>', methods=['GET'])                                                            
def get_timestamped_verses_table(message_id):                                                                                                        
    message_title = message_id_title(message_id)                                                                                                     
    results = message_id_timestamped_verses(message_id)                                                                                              
    return render_template('timestamp_verse_table.html', message_id=message_id, message_title=message_title, results=results)

^ note that location /grace_and_truth in nginx.conf corresponds to @app.route('/grace_and_truth/...)