<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div style=""
data-md-original="On%20Tue%2020%20May%202014%2017%3A08%3A47%20CEST%2C%20Klaus%20Darilion%20wrote%3A%3Cbr%3E%3Cbr%3E%26gt%3B%20Hi%20Daniel!%3Cbr%3E%3Cbr%3EHi!%3Cbr%3E%3Cbr%3E%26gt%3B%20Actually%20I%20tried%20it%20today%20but%20failed%20obviously%20due%20to%20my%20lack%20of%20Python.%3Cbr%3E%26gt%3B%20It%20would%20be%20great%20if%20you%20could%20add%20an%20example%20to%20the%20README%20e.g.%20with%3Cbr%3E%26gt%3B%20full%20result%20parsing%3A%3Cbr%3E%26gt%3B%3Cbr%3E%26gt%3B%20-%20load%20the%20json%20file%20from%20disk%3Cbr%3E%26gt%3B%20-%20loop%20over%20every%20result%20(json%20list)%3Cbr%3E%26gt%3B%20-%20print%20some%20value%3Cbr%3E%3Cbr%3E%3Cbr%3EThe%20full%20documentation%20already%20has%20%5Ba%20few%20examples%5D(https%3A%2F%2Fatlas.ripe.net%2Fdocs%2Fsagan%2F%23examples)%20that%20should%20be%20enough%20to%20get%20you%20going%20(I've%20just%20added%20some%20more)%2C%20but%20here's%20a%20breakdown%20of%20what%20you're%20wanting%3A%3Cbr%3E%3Cbr%3E%60%60%60python%3Cbr%3Efrom%20ripe.atlas
.sagan%20import%20Result%3Cbr%3E%3Cbr%3Emy_results_file%20%3D%20%22%2Fpath%2Fto%2Ffile.txt%22%3Cbr%3Ewith%20open(my_results_file)%20as%20results%3A%3Cbr%3E%C2%A0%C2%A0%C2%A0%20for%20result%20in%20results.readlines()%3A%3Cbr%3E%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20parsed_result%20%3D%20Result.get(result)%3Cbr%3E%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20print(parsed_result.origin)%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3EOnce%20you%20have%20a%20%60parsed_result%60%2C%20you%20have%20access%20to%20all%20of%20the%20properties%20of%20that%20result%2C%20which%20are%20%5Bdefined%20in%20the%20full%20documentation%5D(https%3A%2F%2Fatlas.ripe.net%2Fdocs%2Fsagan%2F%23attributes-methods).%3Cbr%3E%3Cbr%3E%26gt%3B%20Why%20do%20I%20have%20to%20use%20the%20responses%5B0%5D%20object%3F%20Can%20there%20be%20multiple%3Cbr%3E%26gt%3B%20responses%20with%20different%20nsids%3F%3Cbr%3E%3Cbr%3EIn%20some%20cases%2C%20DNS%20results%20*can*%20contain%20multiple%20responses.%C2%A0%20In%20an%20effort%20to%20maint
ain%20consistency%20for%20all%20DNS%20results%2C%20we%20opted%20to%20treat%20all%20DNS%20results%20as%20if%20they%20contain%20a%20list%20of%20responses%20--%20even%20if%20that%20list%20is%20of%20only%20one%20response.%C2%A0%20This%20makes%20it%20easier%20to%20write%20scripts%20that%20make%20use%20of%20the%20object%2C%20since%20you%20always%20have%20a%20consistent%20data%20type%20in%20%60parsed_result.responses%60.%3Cbr%3E%3Cbr%3EI%20hope%20that%20helps!%3Cbr%3E"
      class="markdown-here-wrapper" data-md-url="Thunderbird"
      id="markdown-here-wrapper-875303">
      <p style="margin: 1.2em 0px ! important;">On Tue 20 May 2014
        17:08:47 CEST, Klaus Darilion wrote:</p>
      <blockquote style="margin: 1.2em 0px;border-left: 4px solid
        rgb(221, 221, 221); padding: 0px 1em; color: rgb(119, 119, 119);
        quotes: none;">
        <p style="margin: 1.2em 0px ! important;">Hi Daniel!</p>
      </blockquote>
      <p style="margin: 1.2em 0px ! important;">Hi!</p>
      <blockquote style="margin: 1.2em 0px;border-left: 4px solid
        rgb(221, 221, 221); padding: 0px 1em; color: rgb(119, 119, 119);
        quotes: none;">
        <p style="margin: 1.2em 0px ! important;">Actually I tried it
          today but failed obviously due to my lack of Python.<br>
          It would be great if you could add an example to the README
          e.g. with<br>
          full result parsing:</p>
        <ul style="margin: 1.2em 0px;padding-left: 2em;">
          <li style="margin: 0.5em 0px;">load the json file from disk</li>
          <li style="margin: 0.5em 0px;">loop over every result (json
            list)</li>
          <li style="margin: 0.5em 0px;">print some value</li>
        </ul>
      </blockquote>
      <p style="margin: 1.2em 0px ! important;">The full documentation
        already has <a
          href="https://atlas.ripe.net/docs/sagan/#examples">a few
          examples</a> that should be enough to get you going (I’ve just
        added some more), but here’s a breakdown of what you’re wanting:</p>
      <pre style="font-family: Consolas,Inconsolata,Courier,monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code style="font-family: Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px 3px 3px 3px; display: inline;white-space: pre; overflow: auto; border-radius: 3px 3px 3px 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em; display: block ! important;display: block; padding: 0.5em; color: rgb(51, 51, 51);" class="language-python"><span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">from</span> ripe.atlas.sagan <span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">import</span> Result

my_results_file = <span style="color: rgb(221, 17, 68);" class="string">"/path/to/file.txt"</span>
<span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">with</span> open(my_results_file) <span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">as</span> results:
    <span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">for</span> result <span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">in</span> results.readlines():
        parsed_result = Result.get(result)
        print(parsed_result.origin)
</code></pre>
      <p style="margin: 1.2em 0px ! important;">Once you have a <code
          style="font-family:
          Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em;
          padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid
          rgb(234, 234, 234); background-color: rgb(248, 248, 248);
          border-radius: 3px 3px 3px 3px; display: inline;">parsed_result</code>,
        you have access to all of the properties of that result, which
        are <a
          href="https://atlas.ripe.net/docs/sagan/#attributes-methods">defined
          in the full documentation</a>.</p>
      <blockquote style="margin: 1.2em 0px;border-left: 4px solid
        rgb(221, 221, 221); padding: 0px 1em; color: rgb(119, 119, 119);
        quotes: none;">
        <p style="margin: 1.2em 0px ! important;">Why do I have to use
          the responses[0] object? Can there be multiple<br>
          responses with different nsids?</p>
      </blockquote>
      <p style="margin: 1.2em 0px ! important;">In some cases, DNS
        results <em>can</em> contain multiple responses. In an effort
        to maintain consistency for all DNS results, we opted to treat
        all DNS results as if they contain a list of responses — even if
        that list is of only one response. This makes it easier to write
        scripts that make use of the object, since you always have a
        consistent data type in <code style="font-family:
          Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em;
          padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid
          rgb(234, 234, 234); background-color: rgb(248, 248, 248);
          border-radius: 3px 3px 3px 3px; display: inline;">parsed_result.responses</code>.</p>
      <p style="margin: 1.2em 0px ! important;">I hope that helps!</p>
    </div>
  </body>
</html>