Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 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.     dictionary = {}    
  20.     dictionary['name'] = line[0][0]
  21.     dictionary['item_to_buy'] = line[0][1]
  22.     dictionary['currency'] = line[0][2]
  23.     dictionary['league'] = line[0][3]
  24.     with open('logs.json', 'a+') as f:
  25.         f.write(json.dumps(f))
  26.         f.write('\n')
  27.  
  28.  
  29. with open(logfile) as fp:
  30.     for line in follow(fp):
  31.         filewriter(line) # writing to .json endlessly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement