<commit_before><commit_msg>add sandbox script of AHPS 2 WX experiment<commit_after>"""Convert the AHPS XML into WXC format"""

import urllib2
import datetime
from twisted.words.xish import domish, xpath

xml = urllib2.urlopen('http://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=mroi4&output=xml').read()
elementStream = domish.elementStream()
roots = []
results = []
elementStream.DocumentStartEvent = roots.append
elementStream.ElementEvent = lambda elem: roots[0].addChild(elem)
elementStream.DocumentEndEvent = lambda: results.append(roots[0])

print """IEM MROI4 Test host=273805670 TimeStamp=2015-12-17T09:34:27
    4
    15 Station
     5 LocalTime
     7 Stage
     7 CFS"""

elementStream.parse(xml)
elem = results[0]
nodes = xpath.queryForNodes('/site/forecast/datum', elem)
i = 0
for node in nodes:
    utc = datetime.datetime.strptime(str(node.valid)[:15], '%Y-%m-%dT%H:%M')
    print "%12s%03i %5s %7s %7s" % ('MROI4', i, utc.strftime("%I %p"),
                                    node.primary, node.secondary)
    i += 1

{'fraction_non_alphanumeric': 0.138328530259366, 'fraction_numerical': 0.04803073967339097, 'mean_word_length': 4.082926829268293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6786206', 'n_tokens_mistral': 391, 'n_tokens_neox': 362, 'n_words': 81}