Last active
January 5, 2021 20:23
-
-
Save Romern/2066fb41f5aed00b625e6ba97a27d06c to your computer and use it in GitHub Desktop.
NINA Warn-App Push API
This file contains hidden or 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
import requests | |
import json | |
import sys | |
import os | |
import requests | |
import uuid | |
# Push API | |
headers = { | |
'Authorization': 'Basic YXBwVXNlcjo0MGU4ZTQ0MC1mNTE1LTQ5YmYtYjc1OS1mZWE3YmNkMWQ1NmY=', # Static Authorization header (ID hardcoded in app) | |
'User-Agent': 'NINA/3.3.0 Build:2980 OkHTTP/4.7.2', | |
'Content-Type': 'application/json; charset=UTF-8' | |
} | |
base_url = "https://push.warnung.bund.de/v1/nina-3-1" | |
user_id = str(uuid.uuid4()) | |
# user_id can be chosen at random, should afterwards of course be always the same as we set the preferences for this id | |
# Creates the user-id, if it doesn't exist (maybe also resets the settings?) | |
# Usually uses gcm, but the token is not verified (and without firebase token you won't get notifications anyway, the data is sent through firebase and not retrived through the api!) | |
def address_gcm(): | |
data = '{"token":"ayy"}' | |
return requests.put(f'{base_url}/address/gcm/{user_id}', headers=headers, data=data) | |
## Preferences | |
def set_report_levels(mowasLevel=4, dwdLevel=4, policeLevel=4): | |
data = { | |
"preferences": [ | |
{ | |
"name": "mowasLevel", | |
"type": "INTEGER", | |
"value": str(mowasLevel) | |
}, | |
{ | |
"name": "dwdLevel", | |
"type": "INTEGER", | |
"value": str(dwdLevel) | |
}, | |
{ | |
"name": "policeLevel", | |
"type": "INTEGER", | |
"value": str(policeLevel) | |
}, | |
{ | |
"name": "androidVersionCode", | |
"type": "INTEGER", | |
"value": "2980" | |
} | |
] | |
} | |
return requests.put(f'{base_url}/preference/{user_id}', headers=headers, json=data) | |
# 3245: Aachen? How are these derived? | |
def set_regions(regions=[3245], grid=[], regionParts=[3245]): | |
data = { | |
"preferences": [ | |
{ "name": "regions", | |
"type": "INTEGER_ARRAY", | |
"value": json.dumps(regions) | |
}, | |
{ "name": "grid", | |
"type": "INTEGER_ARRAY", | |
"value": json.dumps(grid) | |
}, | |
{ "name": "regionParts", | |
"type": "INTEGER_ARRAY", | |
"value": json.dumps(regionParts) | |
} | |
] | |
} | |
return requests.put(f'{base_url}/preference/{user_id}', headers=headers, json=data) | |
def set_preference_level(preference="mowasLevel", level=1): | |
# mowas: civil protection warnings (1-4) | |
# dwd: weather warnings (1-4) | |
# lhp: flooding information (always 4 or deleted) | |
# police? Not in settings, but defaults to 0 | |
if preference not in ["mowasLevel", "dwdLevel", "lhpLevel"]: | |
raise Exception("Not a valid preference") | |
data = { | |
"type": "INTEGER", | |
"value": str(level) | |
} | |
return requests.put(f'{base_url}/preference/{user_id}/{preference}', headers=headers, json=data) | |
def disable_notifications(preference="mowasLevel"): | |
if preference not in ["mowasLevel", "dwdLevel", "lhpLevel"]: | |
raise Exception("Not a valid preference") | |
return requests.delete(f'{base_url}/preference/{user_id}/{preference}', headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment