Пример #1
0
def dump_user_infos():
    all_user_infos = []
    article_ids = get_article_ids()
    for article_id in article_ids:
        for user_info in JSONHandler.get_article_user_infos(article_id):
            all_user_infos.append(user_info)
    JsonUtil.dump('userinfos.json', all_user_infos)
def outputResultsToJson(results, prefixtitle):
    if len(results) == 0:
        return
        
    currdate = dt.datetime.now()
    outputdate = currdate.strftime('%Y-%m-%dT%H:%M:%S')
    ju.writeJsonToFile(results, f'{prefixtitle}-{prefix}{outputdate}.json')
Пример #3
0
def ping_send(remotename, interval = 100):
    ''' 向给自己发消息
        params tuple remotename   (groupname, servicename)
               int   interval  每隔多久发一次消息
    '''
    try :
        global MONITOR_RBT_WRITE 
        global MBC
        global reply_info
        while True:
            MBC._end_event.wait(interval)
            if MBC._end_event.isSet():
                break
            try:
                data = {  
                         "0003":{"0005":0x00000001},
                         "0004":{},
                       }
                data = JsonUtil.write( data )
                MONITOR_RBT_WRITE.send(remotename, data)
                if True == reply_info['is_reply']:
                    reply_info['is_reply'] = False
                    reply_info['ping_time'] = time.time()
                logging.info('send [ping] to myself through rabbitmq')
            except:
                logging.warning('from ping_send %s',traceback.format_exc())
    except Exception,ex:
        logging.error( "Error: %s" % ex )
        logging.error( traceback.format_exc() )
Пример #4
0
def dump_comments():
    JsonUtil.dump('comments.json', get_all_comments())
Пример #5
0
def SendJson(req, obj):
    # Use parenthesis to avoid mozilla issues
    req.headers_out['X-JSON'] = '(' + JsonUtil.jsonstr(obj) + ')'

    return 0
Пример #6
0
 def record(self,record_data):
     self._f.write(getNow()+':'+json.write(record_data)+'\n')