Exemple #1
0
    def process(self):

        if not self.current_event or datetime.datetime.now() > self.max_time_current:
            self.min_time_current = datetime.datetime.now()
            self.max_time_current = self.min_time_current + self.timedelta
            self.current_event = MISPEvent()
            self.current_event.info = ('IntelMQ event {begin} - {end}'
                                       ''.format(begin=self.min_time_current.isoformat(),
                                                 end=self.max_time_current.isoformat()))
            self.current_event.set_date(datetime.date.today())
            self.current_event.Orgc = self.misp_org
            self.current_event.uuid = str(uuid4())
            self.current_file = self.output_dir / '{self.current_event.uuid}.json'.format(self=self)
            with (self.output_dir / '.current').open('w') as f:
                f.write(str(self.current_file))

        event = self.receive_message().to_dict(jsondict_as_string=True)

        obj = self.current_event.add_object(name='intelmq_event')
        for object_relation, value in event.items():
            try:
                obj.add_attribute(object_relation, value=value)
            except NewAttributeError:
                # This entry isn't listed in the harmonization file, ignoring.
                pass

        feed_output = self.current_event.to_feed(with_meta=False)

        with self.current_file.open('w') as f:
            json.dump(feed_output, f)

        feed_meta_generator(self.output_dir)
        self.acknowledge_message()
Exemple #2
0
        reader = csv.reader(data)
        for row in reader:
            sample_date = parse(f'{row[0]}-{row[1]}')
            if sample_date in dates_already_imported:
                continue
            obj = MISPObject('scrippsco2-o18-daily', standalone=False)
            obj.add_attribute('sample-datetime', sample_date)
            obj.add_attribute('sample-date-excel', float(row[2]))
            obj.add_attribute('sample-date-fractional', float(row[3]))
            obj.add_attribute('number-flask', int(row[4]))
            obj.add_attribute('flag', int(row[5]))
            attr = obj.add_attribute('o18-value', float(row[6]))
            attr.add_tag(f'scrippsco2-fgi:{int(row[5])}')
            obj.add_reference(location, 'sampling-location')
            event.add_object(obj)


if __name__ == '__main__':
    output_dir = 'scrippsco2_feed'

    i = Scrippts(output_dir=output_dir)
    i.import_daily_co2_all()
    i.import_daily_c13_all()
    i.import_daily_o18_all()
    i.import_monthly_co2_all()
    i.import_monthly_c13_all()
    i.import_monthly_o18_all()

    feed_meta_generator(Path(output_dir))
Exemple #3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from pymisp.tools import feed_meta_generator
import argparse
from pathlib import Path

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Build meta files for feed')
    parser.add_argument("--feed",
                        required=True,
                        help="Path to directory containing the feed.")
    args = parser.parse_args()

    feed = Path(args.feed)

    feed_meta_generator(feed)
        if province['deadCount']:
            obj_province.add_attribute('total-death', province['deadCount'])
        if province['comment']:
            obj_province.add_attribute('comment', province['comment'])

        for city in province['cities']:
            obj_city = event.add_object(name='covid19-dxy-live-city',
                                        standalone=False)
            obj_city.add_attribute('city', city['cityName'])
            obj_city.add_attribute('update', d)
            if city['currentConfirmedCount']:
                obj_city.add_attribute('current-confirmed',
                                       city['currentConfirmedCount'])
            if city['confirmedCount']:
                obj_city.add_attribute('total-confirmed',
                                       city['confirmedCount'])
            if city['curedCount']:
                obj_city.add_attribute('total-cured', city['curedCount'])
            if city['deadCount']:
                obj_city.add_attribute('total-death', city['deadCount'])
            obj_city.add_reference(obj_province, 'part-of')

    if make_feed:
        with (Path('output') / f'{event.uuid}.json').open('w') as _w:
            json.dump(event.to_feed(), _w)
    else:
        misp.add_event(event)

if make_feed:
    feed_meta_generator(Path('output'))