Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. def follow(file):
  2.     file.seek(0,2)
  3.     while True:
  4.         line = file.readline()
  5.         if not line:
  6.             time.sleep(0.1)
  7.             continue
  8.         line = str(line).replace('"', '\"')
  9.         line = str(line).replace("'", "\'")
  10.         if re.findall(TO_REGEX_OFFICIAL, line) != []:
  11.             strings = re.findall(TO_REGEX_OFFICIAL, line)
  12.         elif re.findall(TO_REGEX_POE_XYZ, line) != []:
  13.             strings = re.findall(TO_REGEX_POE_XYZ, line)
  14.         else:
  15.             continue
  16.         yield strings
  17.        
  18. def filewriter(line):
  19.     with open('logs.json') as f:
  20.         jsonobj = json.load(f)
  21.    
  22.     dictionary = {}    
  23.     dictionary['name'] = line[0][0]
  24.     dictionary['item_to_buy'] = line[0][1]
  25.     dictionary['currency'] = line[0][2]
  26.     dictionary['league'] = line[0][3]
  27.     jsonobj.append(dictionary)
  28.     with open('logs.json', 'w') as f:
  29.         json.dump(jsonobj, f)
  30.  
  31.  
  32. with open(logfile) as fp:
  33.     for line in follow(fp):
  34.         filewriter(line) # writing to .json endlessly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement