import dateutil.parser

from pivoteer.writer.core import CsvWriter
from core.lookups import geolocate_ip

class HostCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecord objects with a record type of "HR" (Host Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Host Records using the given writer.

        :param writer: The writer
        """
        super(HostCsvWriter, self).__init__(writer)

    def create_header(self):
        return ["Date", "Source", "Domain", "IP", "IP Location", "First Seen", "Last Seen"]

    def create_rows(self, record):
        if record is not None:
            yield [record["info_date"],
                   record["get_info_source_display"],
                   record["domain"],
                   record["ip"],
                   record["location"]["country"],
                   record["firstseen"],
                   record["lastseen"]]

import dateutil.parser

from pivoteer.writer.core import CsvWriter
from core.lookups import geolocate_ip

class HostCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecord objects with a record type of "HR" (Host Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Host Records using the given writer.

        :param writer: The writer
        """
        super(HostCsvWriter, self).__init__(writer)

    def create_header(self):
        return ["Date", "Source", "Domain", "IP", "IP Location", "First Seen", "Last Seen"]

    def create_rows(self, record):
        if record is not None:
            yield [record["info_date"],
                   record["get_info_source_display"],
                   record["info"]["domain"],
                   record["info"]["ip"],
                   record["location"]["country"],
                   record["info"]["firstseen"],
                   record["info"]["lastseen"]]

Update historical export with latest data model changes
Update historical export with latest data model changes

  import dateutil.parser
  
  from pivoteer.writer.core import CsvWriter
  from core.lookups import geolocate_ip
  
  class HostCsvWriter(CsvWriter):
      """
      A CsvWriter implementation for IndicatorRecord objects with a record type of "HR" (Host Record)
      """
  
      def __init__(self, writer):
          """
          Create a new CsvWriter for Host Records using the given writer.
  
          :param writer: The writer
          """
          super(HostCsvWriter, self).__init__(writer)
  
      def create_header(self):
          return ["Date", "Source", "Domain", "IP", "IP Location", "First Seen", "Last Seen"]
  
      def create_rows(self, record):
          if record is not None:
              yield [record["info_date"],
                     record["get_info_source_display"],
-                    record["domain"],
+                    record["info"]["domain"],
-                    record["ip"],
+                    record["info"]["ip"],
                     record["location"]["country"],
-                    record["firstseen"],
+                    record["info"]["firstseen"],
-                    record["lastseen"]]
+                    record["info"]["lastseen"]]
  
Update historical export with latest data model changes
## Code Before:
import dateutil.parser

from pivoteer.writer.core import CsvWriter
from core.lookups import geolocate_ip

class HostCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecord objects with a record type of "HR" (Host Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Host Records using the given writer.

        :param writer: The writer
        """
        super(HostCsvWriter, self).__init__(writer)

    def create_header(self):
        return ["Date", "Source", "Domain", "IP", "IP Location", "First Seen", "Last Seen"]

    def create_rows(self, record):
        if record is not None:
            yield [record["info_date"],
                   record["get_info_source_display"],
                   record["domain"],
                   record["ip"],
                   record["location"]["country"],
                   record["firstseen"],
                   record["lastseen"]]

## Instruction:
Update historical export with latest data model changes
## Code After:
import dateutil.parser

from pivoteer.writer.core import CsvWriter
from core.lookups import geolocate_ip

class HostCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecord objects with a record type of "HR" (Host Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Host Records using the given writer.

        :param writer: The writer
        """
        super(HostCsvWriter, self).__init__(writer)

    def create_header(self):
        return ["Date", "Source", "Domain", "IP", "IP Location", "First Seen", "Last Seen"]

    def create_rows(self, record):
        if record is not None:
            yield [record["info_date"],
                   record["get_info_source_display"],
                   record["info"]["domain"],
                   record["info"]["ip"],
                   record["location"]["country"],
                   record["info"]["firstseen"],
                   record["info"]["lastseen"]]
