Last active
July 27, 2021 11:18
-
-
Save kebman/2d3520ae366802993ebb35c9eb01c493 to your computer and use it in GitHub Desktop.
Get SSE lightning strikes from the Norwegian Meteorological Institute at https://lyn.met.no/events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from sseclient import SSEClient | |
import json | |
# get the stream | |
thundercloud = SSEClient('https://lyn.met.no/events') | |
# keep checking for new lighning strikes | |
for lightning in thundercloud: | |
# check if set is empty | |
if(lightning.data != None or lightning.data != ""): | |
# check for line breaks / new lines and act accordingly | |
if ('\n' in lightning.data): | |
# temporary list to dump data in | |
lines = [] | |
# temporary list to dump json in | |
temp_list = [] | |
# remove escapes and dumps into list | |
lines.extend(lightning.data.split()) | |
# make json out of data | |
for line in lines: | |
json_obj = json.loads(line) | |
temp_list.extend(json_obj) | |
# print json in list | |
for i in temp_list: | |
print("Latitude: %a, Longitude: %a" % (i['Point'][1], i['Point'][0])) | |
else: | |
# if no linebreaks detected | |
# make json | |
data = json.loads(lightning.data) | |
# print json | |
print("Latitude: %a, Longitude: %a" % (data[0]['Point'][1], data[0]['Point'][0])) | |
else: | |
# if set is empty | |
print(": heartbeat") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Every so often I will get this error:
I thought it might be due to an empty message, but I don't think that's it. Hope someone can help!