[fix] clitools: toRedis exporter should work

This commit is contained in:
alban 2020-09-30 01:04:35 +02:00
parent 3dff5d92af
commit e794ee2c5e
1 changed files with 12 additions and 17 deletions

View File

@ -17,12 +17,10 @@ by cocoa
''' '''
from __future__ import print_function from __future__ import print_function
import argparse
import ast
import json
import os
import redis
import sys import sys
import os
import argparse
import redis
import time import time
argsparser = argparse.ArgumentParser(description="Redis exporter LJ") argsparser = argparse.ArgumentParser(description="Redis exporter LJ")
@ -46,18 +44,15 @@ r=redis.StrictRedis(host=ip, port=port, db=0)
try: try:
while True: while True:
line = sys.stdin.readline() line = sys.stdin.readline()
if line == "": if line == "":
time.sleep(0.01) time.sleep(0.01)
line = line.rstrip('\n') line = line.rstrip('\n')
line=line[1:-1] line=line[1:-1]
# Decode as list of lists line = line.replace("[",'(')
pointsList = ast.literal_eval(line) line = line.replace("]",')')
# convert to list of tuples line = "[{}]".format(line)
pointsList = [tuple(elem) for elem in pointsList] if r.set(key,line)==True:
# Convert to JSON string
line = json.dumps( pointsList )
if r.set(key,line)==True:
debug("exports::redis set("+str(key)+") to "+line) debug("exports::redis set("+str(key)+") to "+line)
except EOFError: except EOFError:
debug("break")# no more information debug("break")# no more information