Exemplo n.º 1
0
def submit_event(input_data):
    if not input_data.has_key('name'):
        input_data['name'] = input_data['keywords']

    if input_data.has_key('mid'):
        # event_id = mid
        input_data['en_name'] = input_data['mid']
        del input_data['mid']
    else:
        e_name = input_data['name']
        e_name_string = ''.join(e_name.split('&'))
        event_id = p.get_pinyin(e_name_string) + '-' + str(
            input_data['event_ts'])  #+str(int(time.time()))
        input_data['en_name'] = event_id

    if not input_data.has_key('start_ts'):
        start_ts = input_data['event_ts'] - 2 * DAY
        input_data['start_ts'] = start_ts
    if not input_data.has_key('end_ts'):
        end_ts = input_data['event_ts'] + 5 * DAY
        input_data['end_ts'] = end_ts
    input_data['submit_ts'] = int(time.time())
    del input_data['event_ts']
    try:
        result = es_event.get(index=event_task_name,
                              doc_type=event_task_type,
                              id=input_data['en_name'])['_source']
        return 'already in'
    except:
        es_event.index(index=event_task_name,
                       doc_type=event_task_type,
                       id=input_data['en_name'],
                       body=input_data)
    return True
Exemplo n.º 2
0
def create_node_and_rel(node_key1, node1_list, node1_index_name, rel, node_key2, \
                        node2_id, node2_index_name, submit_user, k_label, node2_name):
    Index = ManualIndexManager(graph)  # manage index
    theme_index = Index.get_or_create_index(Node, node2_index_name)
    p_node2_id = p.get_pinyin(node2_id)
    p_node2_id = p_node2_id.lower()
    c_string = "START end_node=node:%s(%s='%s')  RETURN end_node"\
                 % (node2_index_name, node_key2, p_node2_id)
    print c_string
    try:
        result = graph.run(c_string)
    except:
        result = []
    node_l = []
    for i in result:
        # node1_l
        node_l.append(i[0])
    if len(node_l) > 0:  #判断对否有该节点存在
        return 'theme already exist'
    else:
        theme_dict = {}
        theme_dict['topic_name'] = node2_name
        theme_dict['event'] = '&'.join(node1_list)
        theme_dict['event_count'] = len(node1_list)
        theme_dict['create_ts'] = int(time.time())
        theme_dict['user'] = submit_user
        if k_label:
            k_label = '&'.join(k_label.split(','))
            theme_dict['k_label'] = k_label
        topic_id = p.get_pinyin(node2_id)
        topic_id = topic_id.lower()
        labels = get_special_labels(node1_list)
        theme_dict['label'] = labels
        wiki_link = getUrlByKeyWordList(labels)
        theme_dict['wiki_link'] = json.dumps(wiki_link)
        # es_event.delete(index=special_event_name, doc_type=special_event_type, id='*****@*****.**')
        es_event.index(index=special_event_name,
                       doc_type=special_event_type,
                       id=topic_id,
                       body=theme_dict)
        new_theme = Node(special_event_node, event=topic_id)
        graph.create(new_theme)
        theme_index.add("event", topic_id, new_theme)
        # return 'succeed'
    info = create_rel(node_key1, node1_list, node1_index_name, rel, node_key2,
                      topic_id, node2_index_name, submit_user)
    return info
Exemplo n.º 3
0
def submit_event(input_data):
    print input_data, '555555555555555'
    if not input_data.has_key('name'):
        name_s = input_data['keywords'].split('&')[:3]
        print name_s, '==='
        name_string = '&'.join(name_s)
        input_data['name'] = name_string
    if input_data.has_key('mid'):
        # event_id = mid
        input_data['en_name'] = input_data['mid']
        del input_data['mid']
    else:
        e_name = input_data['name']
        e_name_string = ''.join(e_name.split('&'))
        event_id = p.get_pinyin(e_name_string) + '-' + str(
            input_data['event_ts'])  #+str(int(time.time()))
        input_data['en_name'] = event_id

    if not input_data.has_key('start_ts'):
        start_ts = input_data['event_ts'] - 2 * DAY
        input_data['start_ts'] = start_ts
    if not input_data.has_key('end_ts'):
        end_ts = input_data['event_ts'] + 5 * DAY
        input_data['end_ts'] = end_ts
    input_data['submit_ts'] = int(time.time())
    del input_data['event_ts']
    # result = es_event.delete(index=event_task_name, doc_type=event_task_type, id=input_data['en_name'])
    try:
        result = es_event.get(index=event_task_name,
                              doc_type=event_task_type,
                              id=input_data['en_name'])['_source']
        return '0'
    except:
        es_event.index(index=event_task_name,
                       doc_type=event_task_type,
                       id=input_data['en_name'],
                       body=input_data)
        if input_data['immediate_compute'] == '1':
            os.system(
                "nohup python ./knowledge/cron/event_analysis/event_compute.py imme %s &"
                % event_id)
    return '1'