Skip to content

Instantly share code, notes, and snippets.

@claudehang
Created October 28, 2021 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudehang/d56589345ea98b2d27e3df9e3ec353a7 to your computer and use it in GitHub Desktop.
Save claudehang/d56589345ea98b2d27e3df9e3ec353a7 to your computer and use it in GitHub Desktop.
import os
import json
from avro.datafile import DataFileReader
from avro.io import DatumReader
path = './na'
res = []
def readRawData(fileName):
reader = DataFileReader(open(fileName, 'rb'), DatumReader())
dict = {}
print(fileName)
for reading in reader:
parsed_json = json.loads(reading["Body"])
if 'UserSignOn'not in parsed_json['ScenarioName']:
continue
val = []
for key in parsed_json:
val.append(parsed_json[key])
res.append(val)
reader.close()
def getFiles(dir):
for home, dirs, files in os.walk(dir):
for fileName in files:
readRawData(home + '\\' + fileName)
csvFile ='./haha.csv'
csvContent = open(csvFile, "a")
for item in res:
csvContent.write(", ".join([str(x) for x in item])+'\n')
getFiles(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment