Editorial Workflows

Insert NWS Nearest Current Weather Conditions

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: This very quick hack finds the nearest National Weather Service (USA) station, then pulls current conditions from that station, and inserts data at the current cursor position. This may be useful for journaling in Editorial.

Shared by: rpmik

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# coding: utf-8
# National Weather Service (U.S.A) api described at 
# https://forecast-v3.weather.gov/documentation

import urllib2, json, location, datetime, workflow

def place():
	address_dict = location.get_location()
	location.start_updates()
	
	location.stop_updates()
	latitude = address_dict['latitude']
	longitude = address_dict['longitude']
	api(latitude, longitude)

def api(latitude, longitude):
	request_header = {"accept":"application/ld+json"}
	#url = 'https://api.weather.gov/points/{0},{1}/forecast' .format (latitude, longitude) #lat long forecast

	url = 'https://api.weather.gov/points/{0},{1}/stations' .format (latitude, longitude)

	req = urllib2.Request(url,headers=request_header )
	response = urllib2.urlopen(req)
	jsonResponse = json.load(response)
	
	stations = jsonResponse['observationStations']
	nearestSta = stations[0][-5:]
	url = 'https://api.weather.gov/stations/{0}/observations/current' .format (nearestSta)
	req = urllib2.Request(url,headers=request_header )
	response = urllib2.urlopen(req)
	jsonResponse = json.load(response)
	
	tempF = jsonResponse['temperature']['value'] * 9/5 + 32
	relHumid = jsonResponse['relativeHumidity']['value']
	windGustMPH = jsonResponse['windGust']['value']* 2.37 # conv to mph
	output = "\tAt NWS {0}:\n\tTemp (f)\t{1:0.2f}\n\tRel. Humidity:\t{2:0.2f}\n\tGusts (MPH):\t{3:0.2f}\n".format(nearestSta,tempF,relHumid,windGustMPH)
	workflow.set_output(output)

output = ""
place()
Replace Selected Text ?
Replacement Text
Input