Skip to content

Instantly share code, notes, and snippets.

@darksidelemm
Created March 24, 2021 10:07
Show Gist options
  • Save darksidelemm/99a4d0fee76ab9990d333842a636f346 to your computer and use it in GitHub Desktop.
Save darksidelemm/99a4d0fee76ab9990d333842a636f346 to your computer and use it in GitHub Desktop.
#
# SSDV Image Grabber
#
# Run with:
# python ssdv_grabber.py CALLSIGN TIME
# where CALLSIGN is the payload callsign, and
# TIME is the time of the oldest image, as %Y-%m-%dT%H:%M:%SZ
#
import requests
import argparse
import datetime
import json
import sys
import wget
from sets import Set
API_URL = "http://ssdv.habhub.org/api/v0/images"
API_TIMEOUT = 60
def get_image_list(callsign="VK5ARG", from_time = ""):# time_delta=-1):
''' Get a list of SSDV images from the SSDV server, using callsign X, and from the last N days. '''
#_timedelta = datetime.timedelta(hours=time_delta*24)
#_dt_now = datetime.datetime.utcnow()
#_dt_from = (_dt_now + _timedelta).strftime("%Y-%m-%dT%H:%M:%SZ")
payload = {
'callsign': callsign,
'from': from_time
}
r = requests.get(API_URL, payload)
try:
return r.json()
except:
print(r.text)
raise IOError()
def get_detailed_image_data(image_id=1):
payload = {
'include_packets': 'true'
}
r = requests.get(API_URL+"/"+str(image_id), payload)
return r.json()
if __name__ == "__main__":
_callsign = sys.argv[1]
_from_time = sys.argv[2]
_images = get_image_list(callsign=_callsign, from_time=_from_time)
listeners = Set([])
image_urls = []
image_ids = []
for _img in _images:
_listeners = _img['received_by']
_url = _img['image_href']
_id = _img['id']
for _call in _listeners:
listeners.add(_call)
image_urls.append(_url)
image_ids.append(_id)
print("Listeners: %s" % str(listeners))
heard_packets = {}
for _listener in listeners:
heard_packets[_listener] = 0
print("Getting per Image data...")
for _id in image_ids:
print(_id)
_data = get_detailed_image_data(image_id=_id)
for _packet in _data['packets']:
for _call in _packet['received_by']:
heard_packets[_call] += 1
for _call in heard_packets.keys():
print("%s: %d packets (%.2f MB)" % (_call, heard_packets[_call], (heard_packets[_call]*256)/1024.0/1024.0))
#print(get_detailed_image_data(image_id=image_ids[-1]))
#print("Downloading Images")
#for _img in image_urls:
# print("Downloading: %s" % _img)
# wget.download(_img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment