示例#1
0
文件: test.py 项目: palli/eurdep
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import pprint
import eurdep

with open('data/IS20131215-reitr.EUR') as f:
    data = f.read()
    result = eurdep.load(data)
    for i in result['EURDEP']:
        message_id = i['HEADER'][0]['MESSAGE_ID'][0]
        sent_at = i['HEADER'][0]['SENT'][0]
        importance = i['HEADER'][0]['IMPORTANCE'][0]

        value = i['RADIOLOGICAL'][0]['field_list'][0]['VALUE']
        unit = i['RADIOLOGICAL'][0]['DEFAULT'][0]['UNIT'][0]

        print "# Message ID:", message_id
        print "# Sent at %s" % sent_at
        print "%f %s" % (float(value), unit)
        print ""

# Use this to print the whole result
# pp = pprint.PrettyPrinter(indent=4)
示例#2
0
        continue
    columns = i.split()
    filename = columns.pop()
    full_path = datadir + "/" + filename
    if os.path.isfile(full_path):
        #print filename, "is already here"
        continue
    callback = lambda x: save_file(full_path, x)
    ftp.retrbinary('RETR Gammastodvar/' + filename, callback=callback)


graphite_key = "geislavarnir.gammastodvar"

for filename in os.listdir(datadir)[-10:]:
    with open(datadir + "/" + filename) as f:
        data = eurdep.load(f.read())
        for i in data.get('EURDEP', []):
            value = i['RADIOLOGICAL'][0]['field_list'][0]['VALUE']
            end_time = i['RADIOLOGICAL'][0]['field_list'][0]['END']
            locality_code = i['RADIOLOGICAL'][0]['field_list'][0]['LOCALITY_CODE']

            value = float(value)
            timestamp = datetime.datetime.strptime(end_time, '%Y-%m-%dT%H:%MZ').strftime("%s")


            # We already have location code, lets find location name
            for location in i['LOCALITY'][0]['field_list']:
                if location['LOCALITY_CODE'] == locality_code:
                    location_name = location['LOCALITY_NAME']
                    location_name = location_name.replace(' ', '_')
                    location_name = location_name.replace(' ', '')
    columns = i.split()
    filename = columns.pop()
    full_path = datadir + "/" + filename
    if os.path.isfile(full_path):
        #print filename, "is already here"
        continue
    callback = lambda x: save_file(full_path, x)
    ftp.retrbinary('RETR Gammastodvar/' + filename, callback=callback)

graphite_key = "geislavarnir.gammastodvar"

for filename in os.listdir(datadir)[:]:
    if not filename.startswith('IS'):
        continue
    with open(datadir + "/" + filename) as f:
        data = eurdep.load(f.read())
        for i in data.get('EURDEP', []):
            value = i['RADIOLOGICAL'][0]['field_list'][0]['VALUE']
            end_time = i['RADIOLOGICAL'][0]['field_list'][0]['END']
            locality_code = i['RADIOLOGICAL'][0]['field_list'][0][
                'LOCALITY_CODE']

            value = float(value)
            timestamp = datetime.datetime.strptime(
                end_time, '%Y-%m-%dT%H:%MZ').strftime("%s")

            # We already have location code, lets find location name
            for location in i['LOCALITY'][0]['field_list']:
                if location['LOCALITY_CODE'] == locality_code:
                    location_name = location['LOCALITY_NAME']
                    location_name = location_name.replace(' ', '_')