Add /log to path so I could use it on server.
This commit is contained in:
		@@ -6,7 +6,7 @@ shows what is done and not done makes it easy to check periodically.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# How?
 | 
					# How?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This tiny Flask API runs on a server (Raspberry Pi, etc.). It has very basic authentication
 | 
					This tiny Python 3 Flask API runs on a server (Raspberry Pi, etc.). It has very basic authentication
 | 
				
			||||||
and waits for a curl (or similar) GET request with some small amount of data. The data are
 | 
					and waits for a curl (or similar) GET request with some small amount of data. The data are
 | 
				
			||||||
displayed on a simple web page.
 | 
					displayed on a simple web page.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16,6 +16,10 @@ whatever data you pass.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
You can either run with the internal Flask development server or something like gunicorn.
 | 
					You can either run with the internal Flask development server or something like gunicorn.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I am experimenting with virtualenv, for which I am following the instructions at
 | 
				
			||||||
 | 
					https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask (this 
 | 
				
			||||||
 | 
					is also the place from I cribbed the basic application functions).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Other Use Cases?
 | 
					# Other Use Cases?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
I'm sure there are some.
 | 
					I'm sure there are some.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								app.py
									
									
									
									
									
								
							@@ -27,7 +27,7 @@ def get_password(username):
 | 
				
			|||||||
def unauthorized():
 | 
					def unauthorized():
 | 
				
			||||||
    return make_response(jsonify({'error': 'Unauthorized access'}), 403)
 | 
					    return make_response(jsonify({'error': 'Unauthorized access'}), 403)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@app.route('/new', methods=['POST', 'GET'])
 | 
					@app.route('/log/new', methods=['POST', 'GET'])
 | 
				
			||||||
@auth.login_required
 | 
					@auth.login_required
 | 
				
			||||||
def create_status():
 | 
					def create_status():
 | 
				
			||||||
    # At least try to clean up user-submitted data
 | 
					    # At least try to clean up user-submitted data
 | 
				
			||||||
@@ -52,11 +52,11 @@ def create_status():
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    return jsonify({'status': status}), 201
 | 
					    return jsonify({'status': status}), 201
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@app.route('/raw', methods=['GET'])
 | 
					@app.route('/log/raw', methods=['GET'])
 | 
				
			||||||
def get_statuses_raw():
 | 
					def get_statuses_raw():
 | 
				
			||||||
    return jsonify({'statuses': statuses[::-1]})
 | 
					    return jsonify({'statuses': statuses[::-1]})
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@app.route('/', methods=['GET'])
 | 
					@app.route('/log', methods=['GET'])
 | 
				
			||||||
def get_statuses():
 | 
					def get_statuses():
 | 
				
			||||||
    long_agos = [humanfriendly.format_timespan(datetime.datetime.now().timestamp() - status['timestamp']) for status in statuses[::-1]]
 | 
					    long_agos = [humanfriendly.format_timespan(datetime.datetime.now().timestamp() - status['timestamp']) for status in statuses[::-1]]
 | 
				
			||||||
    return render_template("index.html", 
 | 
					    return render_template("index.html", 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user