diff --git a/README.md b/README.md index 7405ca0..b2d8076 100644 --- a/README.md +++ b/README.md @@ -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: ``` diff --git a/api_app.py b/api_app.py index b4f3da8..6ceebf1 100644 --- a/api_app.py +++ b/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) diff --git a/kiss_and_db.py b/kiss_and_db.py index a8c7072..2b6ec2f 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -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: