At /packets, return 10 records by default and add n=x to return x packets.
This commit is contained in:
		@@ -17,8 +17,9 @@ You can use screen to detach the session.
 | 
			
		||||
3. Access the API from whatever other system you want.
 | 
			
		||||
 | 
			
		||||
## Endpoints:
 | 
			
		||||
-`/packets` - gives the most recent packets, with the fields from the Dire Wolf
 | 
			
		||||
User Guide.
 | 
			
		||||
-`/packets` - gives the most recent packets, sorted descending by time received.
 | 
			
		||||
    - argument `n` will return a specific number of packets, default 10. E.g.,
 | 
			
		||||
    `https://digi.w1cdn.net/aprs_api/packets?n=1` returns one packet.
 | 
			
		||||
 | 
			
		||||
Example of an object packet sent by W1CDN-1 and digipeated by K0UND-2:
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								api_app.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								api_app.py
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
from flask import Flask
 | 
			
		||||
from flask import Flask, request
 | 
			
		||||
from flask_restful import Resource, Api, reqparse
 | 
			
		||||
from datetime import date, timedelta
 | 
			
		||||
import configparser
 | 
			
		||||
@@ -67,9 +67,13 @@ def select_all_frames(conn):
 | 
			
		||||
 | 
			
		||||
class Packets(Resource):
 | 
			
		||||
    def get(self):
 | 
			
		||||
        #data = read_logs(log_folder)
 | 
			
		||||
        try:
 | 
			
		||||
            n = int(request.args.get('n'))
 | 
			
		||||
        except:
 | 
			
		||||
            n = 10
 | 
			
		||||
        print(n)
 | 
			
		||||
        conn = get_db_connection()
 | 
			
		||||
        data = select_all_frames(conn)
 | 
			
		||||
        data = select_all_frames(conn)[-n:]
 | 
			
		||||
        # Sort by created date, descending (https://stackoverflow.com/a/45266808)
 | 
			
		||||
        data.sort(key=operator.itemgetter('created'), reverse=True)
 | 
			
		||||
        #data.sort(key=created, reverse=True)
 | 
			
		||||
 
 | 
			
		||||
@@ -82,7 +82,7 @@ def main():
 | 
			
		||||
        path=["WIDE1-1"],
 | 
			
		||||
        info=b">Hello World!",
 | 
			
		||||
    )
 | 
			
		||||
    ki.write(frame)
 | 
			
		||||
    #ki.write(frame)
 | 
			
		||||
 | 
			
		||||
    # Watch for new packets to come in
 | 
			
		||||
    while True:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user