Browse Source

Added basic CSV export for global stat history.

master
James Hofstra 2 years ago
parent
commit
7767aceba4
  1. 18
      steam_stat_utils.py

18
steam_stat_utils.py

@ -2,6 +2,7 @@
"""
Command line utility for parsing detailed Steam stat information.
"""
import csv
import json
import pathlib
import struct
@ -254,6 +255,18 @@ def dump_raw_stats(stats, target_dir=None):
with fp.joinpath(statname).open('wb') as fh:
fh.write(mapper.pack(data))
def dump_history(data, startdate, enddate):
dates = [d for d in range(int(startdate), int(enddate) + 1, 86400)]
with open('history.csv', 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow([''] + dates)
for stat in data:
f = [0] * len(dates)
if data[stat] is not None:
for record in data[stat]:
f[dates.index(record['date'])] = int(record['total'])
csvwriter.writerow([stat] + f)
# Program interface
def main():
@ -293,9 +306,10 @@ def main_history():
for partial_names in divide_names(global_stat_names, 4):
global_stats = get_global_stats_history(sys.argv[2], partial_names, sys.argv[3], sys.argv[4])
global_stat_hist.update(global_stats)
print(global_stat_hist)
# Organized in CSV file for easier spreadsheet import
dump_history(global_stat_hist, sys.argv[3], sys.argv[4])
else:
print('No input specified.')
if __name__ == '__main__':
main()
main()
Loading…
Cancel
Save