From e794ee2c5e6ab5535faf607762f0712946ee339c Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 30 Sep 2020 01:04:35 +0200 Subject: [PATCH] [fix] clitools: toRedis exporter should work --- clitools/exports/toRedis.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/clitools/exports/toRedis.py b/clitools/exports/toRedis.py index 0ccf208..b98f2eb 100755 --- a/clitools/exports/toRedis.py +++ b/clitools/exports/toRedis.py @@ -17,12 +17,10 @@ by cocoa ''' from __future__ import print_function -import argparse -import ast -import json -import os -import redis import sys +import os +import argparse +import redis import time argsparser = argparse.ArgumentParser(description="Redis exporter LJ") @@ -46,18 +44,15 @@ r=redis.StrictRedis(host=ip, port=port, db=0) try: while True: - line = sys.stdin.readline() - if line == "": - time.sleep(0.01) - line = line.rstrip('\n') - line=line[1:-1] - # Decode as list of lists - pointsList = ast.literal_eval(line) - # convert to list of tuples - pointsList = [tuple(elem) for elem in pointsList] - # Convert to JSON string - line = json.dumps( pointsList ) - if r.set(key,line)==True: + line = sys.stdin.readline() + if line == "": + time.sleep(0.01) + line = line.rstrip('\n') + line=line[1:-1] + line = line.replace("[",'(') + line = line.replace("]",')') + line = "[{}]".format(line) + if r.set(key,line)==True: debug("exports::redis set("+str(key)+") to "+line) except EOFError: debug("break")# no more information