Closed dhsdshdhk closed 5 years ago
I would assume that you could do something like:
import re
def main():
expA_file = open("expA.json", "w+")
expB_file = open("expB.json", "w+")
for line in api.GetStreamFilter(track=['expA', 'expB'], languages=LANGUAGES):
if re.match(expA, line):
expA_file.write(json.dumps(line))
expA_file.write('\n')
elif re.match(expB, line):
expB_file.write(json.dumps(line))
expB_file.write('\n')
finally:
expA_file.close()
expB_file.close()
But that assumes that there's no overlap between matching on expA
and expB
, though I guess you could handle that in a special case.
The above code will group all my tracked tweets matching either expression into a single json file. Is it possible to separate them so each expression goes into its own file?