Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
b1a2dc0a
Commit
b1a2dc0a
authored
Apr 26, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python script to fetch alerts.
parent
a32a7dfc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
1 deletions
+96
-1
.gitignore
+5
-1
scripts/NWSAlertsHelperScripts/README.md
+2
-0
scripts/NWSAlertsHelperScripts/get_current_events.py
+80
-0
scripts/NWSAlertsHelperScripts/requirements.txt
+5
-0
scripts/NWSAlertsHelperScripts/setup_venv.sh
+4
-0
No files found.
.gitignore
View file @
b1a2dc0a
...
...
@@ -4,6 +4,9 @@
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
# Python venv
/scripts/NWSAlertsHelperScripts/nws
## Build generated
build/
DerivedData/
...
...
@@ -162,7 +165,8 @@ DerivedData
.LSOverride
# Icon must end with two \r
Icon
Icon
# Thumbnails
._*
...
...
scripts/NWSAlertsHelperScripts/README.md
0 → 100644
View file @
b1a2dc0a
This script gets the list of FIPS codes with active alerts, fetches the alerts through our NWS API for those locations, stores them in AlertFiles. Then fetches alert messages for all those alerts, and stores them into AlertFiles/Details.
\ No newline at end of file
scripts/NWSAlertsHelperScripts/get_current_events.py
0 → 100755
View file @
b1a2dc0a
import
json
import
requests
import
os
baseParams
=
{
# "echoCity": "Rapid City",
"format"
:
"json"
,
}
directory
=
"AlertFiles"
directory_details
=
os
.
path
.
join
(
directory
,
"Details"
)
url
=
"https://sta-nwsalert.onelouder.com/current_events"
from
urllib3.exceptions
import
InsecureRequestWarning
requests
.
packages
.
urllib3
.
disable_warnings
(
category
=
InsecureRequestWarning
)
# for fips_code in range(2262, 1000000):
# # for fips_code in range(46103, 46104):
# params = dict(baseParams)
# params["weather_id"] = f'{fips_code:06}'
# response = requests.get(url, params=params, verify=False)
# responseDict = json.loads(response.text)
# events = responseDict["events"]["events"]
# if events is not None and len(events) > 0:
# print(f'{fips_code:06}' + " - SAVE")
# with open(os.path.join(directory, str(fips_code) + ".json"), "w") as file:
# json.dump(events, file, indent=4, sort_keys=True)
# for event in events:
# url = event["messageURL"]
# alert_id = url.split("/")[-1]
# print(alert_id)
# response = requests.get(url, verify=False)
# with open(os.path.join(directory_details, alert_id + ".txt"), "w") as details_file:
# details_file.write(response.text)
# else:
# if fips_code % 100 == 0:
# print(f'{fips_code:06} - no')
active_fips_codes
=
set
()
active_alerts_url
=
"https://api.weather.gov/alerts/active"
response
=
requests
.
get
(
active_alerts_url
,
verify
=
False
)
responseDict
=
json
.
loads
(
response
.
text
)
features
=
responseDict
[
"features"
]
for
feature
in
features
:
properties
=
feature
[
"properties"
]
if
properties
is
None
:
continue
geocode
=
properties
[
"geocode"
]
if
geocode
is
None
:
continue
fips_codes
=
geocode
[
"SAME"
]
if
fips_codes
is
None
or
len
(
fips_codes
)
==
0
:
continue
for
fips
in
fips_codes
:
active_fips_codes
.
add
(
fips
)
print
(
"Active fips codes: "
)
print
(
active_fips_codes
)
for
fips_code
in
active_fips_codes
:
# for fips_code in range(46103, 46104):
params
=
dict
(
baseParams
)
params
[
"weather_id"
]
=
fips_code
nwsResponse
=
requests
.
get
(
url
,
params
=
params
,
verify
=
False
)
responseDict
=
json
.
loads
(
nwsResponse
.
text
)
events
=
responseDict
[
"events"
][
"events"
]
if
events
is
not
None
and
len
(
events
)
>
0
:
print
(
fips_code
+
" - SAVE"
)
with
open
(
os
.
path
.
join
(
directory
,
str
(
fips_code
)
+
".json"
),
"w"
)
as
file
:
json
.
dump
(
events
,
file
,
indent
=
4
,
sort_keys
=
True
)
for
event
in
events
:
singleUrl
=
event
[
"messageURL"
]
alert_id
=
singleUrl
.
split
(
"/"
)[
-
1
]
print
(
alert_id
)
singleResponse
=
requests
.
get
(
singleUrl
,
verify
=
False
)
with
open
(
os
.
path
.
join
(
directory_details
,
alert_id
+
".txt"
),
"w"
)
as
details_file
:
details_file
.
write
(
singleResponse
.
text
)
\ No newline at end of file
scripts/NWSAlertsHelperScripts/requirements.txt
0 → 100644
View file @
b1a2dc0a
certifi
==2020.12.5
chardet
==4.0.0
idna
==2.10
requests
==2.25.1
urllib3
==1.26.4
scripts/NWSAlertsHelperScripts/setup_venv.sh
0 → 100755
View file @
b1a2dc0a
python3
-m
venv nws
source
nws/bin/activate
pip install
-r
requirements.txt
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment