SHARE
TWEET

Untitled

a guest Jun 17th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. triggerZipFiles = glob.glob('*.zip')
  2.   for triggerFiles in triggerZipFiles:
  3.       with zipfile.ZipFile(triggerFiles, 'r') as myzip:
  4.           for logfile in myzip.namelist():
  5.               datacc = []
  6.               zipcc = []
  7.               csvout = '{}_US.csv'.format(logfile[:-4])
  8.               f = myzip.open(logfile)
  9.               contents = f.readlines()
  10.               for line in contents:
  11.                   try:
  12.                       parsed = json.loads(line[:-2])
  13.                       if "CC" in parsed['data']['weatherType'] and "US" in parsed['zipcodes']:
  14.                           datacc.append(parsed['data'])
  15.                           zipcc.append(parsed['zipcodes'])
  16.                   except:
  17.                       pass
  18.               if len(datacc) > 0:
  19.                   df = pd.concat([pd.DataFrame(zipcc), pd.DataFrame(datacc)], axis=1)
  20.                   df = pd.concat((pd.Series((v, row['key'], row['key'], row['key'],
  21.                     row['key'], row['key'], row['key'], row['key'], row['key'],
  22.                     row['key'], row['key'], row['key'], row['key'], row['key'],
  23.                     row['key'], row['key'], row['key'], row['key'], row['key'],
  24.                     row['key'], row['key'], row['key'], row['key'], row['key'],
  25.                     row['key'], row['key'], row['key'], row['key'],
  26.                     row['key'], row['key'], row['key'], row['key'],
  27.                     row['key'], row['key'], row['key'], row['key'],
  28.                     row['key'], row['key'], row['key'], row['key'], row['key'],
  29.                     row['key'], row['key'], row['key'], row['key'],
  30.                     row['key'], row['key'], row['key'], row['key'], row['key'],
  31.                     row['key'], row['key'], row['key'], row['key'], row['key'], row['key'],
  32.                     row['key'], row['key'], row['key'], row['key'], row['key'], row['key'],
  33.                     row['key'], row['key'], row['key'], row['key'], row['key'], row['key'],
  34.                     row['key'], row['key'], row['key'], row['key']), df.columns) for _,
  35.                       row in df.iterrows() for v in row['US']), axis=1).T                
  36.                   df.to_csv(csvout, header=None, index=False)
  37.               else:
  38.                   pass
  39.               print datetime.now().strftime('%Y/%m/%d %H:%M:%S') + ": Finished: {}".format(logfile)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top