Last active
May 22, 2017 20:05
-
-
Save inorton/5269b099a4f91d7ad2d5f6671bf916e9 to your computer and use it in GitHub Desktop.
Print out a elite dangerous journal as a csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Load a journal file from disk and turn the Scan events into a CSV File | |
""" | |
import os | |
import json | |
import sys | |
def run(filename): | |
""" | |
Make a csv of scan items and save it as a CSV | |
:param filename: | |
:return: | |
""" | |
table_cols = set() | |
table_data = list() | |
with open(filename, "r") as inputfile: | |
for line in inputfile: | |
journal_item = json.loads(line) | |
if journal_item.get("event", None) == "Scan": | |
for itemname in journal_item: | |
## build up our table header | |
if itemname not in table_cols: | |
table_cols.add(itemname) | |
table_data.append(journal_item) | |
# we now have a list of headings and some scan rows we can print out | |
sorted_heading = sorted(table_cols) | |
print ", ".join(sorted_heading) | |
for row in table_data: | |
rowvalues = list() | |
for heading in sorted_heading: | |
if heading in row: | |
value = str(row[heading]) | |
if "," in value: | |
value = "'{}'".format(value) | |
rowvalues.append(value) | |
else: | |
# not all things have all values | |
rowvalues.append("") | |
print ", ".join(rowvalues) | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print >> sys.stderr, "Usage: makecsv.py JOURNAL_FILE\n" | |
sys.exit(1) | |
else: | |
run(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AbsoluteMagnitude, Age_MY, BodyName, DistanceFromArrivalLS, Eccentricity, OrbitalInclination, OrbitalPeriod, Periapsis, Radius, Rings, RotationPeriod, SemiMajorAxis, StarType, StellarMass, SurfaceTemperature, event, timestamp | |
9.95282, 10000, Crucis Sector NN-T b3-1 A, 0.0, 0.091033, 48.048252, 1.16454449152e+11, 108.257957, 315254560.0, , 150062.453125, 1.08498790646e+13, M, 0.332031, 2639.0, Scan, 2017-05-09T21:37:10Z | |
9.95282, 10000, Crucis Sector NN-T b3-1 A, 0.0, 0.091033, 48.048252, 1.16454449152e+11, 108.257957, 315254560.0, , 150062.453125, 1.08498790646e+13, M, 0.332031, 2639.0, Scan, 2017-05-09T21:37:10Z | |
9.95282, 10000, Crucis Sector NN-T b3-1 A, 0.0, 0.091033, 48.048252, 1.16454449152e+11, 108.257957, 315254560.0, , 150062.453125, 1.08498790646e+13, M, 0.332031, 2639.0, Scan, 2017-05-09T21:37:10Z | |
9.95282, 10000, Crucis Sector NN-T b3-1 A, 0.0, 0.091033, 48.048252, 1.16454449152e+11, 108.257957, 315254560.0, , 150062.453125, 1.08498790646e+13, M, 0.332031, 2639.0, Scan, 2017-05-09T21:37:10Z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to save the file it creates rather than printing it to the screen do:
c:\python2.7\python journal2csv.py "C:\users\inb\Saved Games\Frontier Developments\Elite Dangerous\Journal.170509221031.01.log" > c:\tmp\scans.csv
And the file should appear in
c:\tmp\scans.csv