#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import oneshot_common
import helper

import datetime
import logging

# 최종 카테고리를 설정한다. 우선순위: 1.Man, 2.Calc, 3.Xls -> categoryFinal

configs = helper.load_config("../ntrust.ini")

helper.mongo.connect(configs["DEST_MONGODB"])

coll_news = helper.mongo.get_collection("news")

docs = coll_news.find({}, {
    "categoryXls": 1,
    "categoryMan": 1,
    "categoryCalc": 1
})  #.limit(1000)
for doc in docs:
    final = doc["categoryXls"]
    calc = None
    if "categoryCalc" in doc:
        calc = doc["categoryCalc"]
        final = calc
    man = None
    if "categoryMan" in doc:
        man = doc["categoryMan"]
        final = man
        ne_person = toks[1].split(",")
        ne_organ = toks[2].split(",")
        ne_location = toks[3].split(",")
        NewsDic[toks[0]] = [ne_person, ne_organ, ne_location]


for (dirpath, dirnames, filenames) in os.walk("../data/ner"):
    for filename in filenames:
        if not filename.endswith(".csv"):
            continue
        pathname = os.path.join(dirpath, filename)
        parse_csv(pathname)

print("Total news: %d" % len(NewsDic))

configs = helper.load_config("../dev.ini")

helper.mongo.connect(configs["DEST_MONGODB"])

coll_news = helper.mongo.get_collection("news")

for k, v in NewsDic.items():
    coll_news.update_one(
        {"newsId": k},
        {"$set": {
            "ner_PS": v[0],
            "ner_OG": v[1],
            "ner_LC": v[2]
        }},
        upsert=False)
Beispiel #3
0
            hosts_to_be_deleted = [result["host_id"]
                                   for result in results if result["action"] == "delete"]
            hosts_to_be_disabled = [result["host_id"]
                                    for result in results if result["action"] == "disable"]
            if hosts_to_be_disabled != []:
                zapi.set_hosts_status(hosts_to_be_disabled, DISABLE_HOST)
            if hosts_to_be_deleted != []:
                zapi.delete_hosts(hosts_to_be_deleted)
            print("Hosts not in openstack:" + str(len(hosts_not_in_openstack)))
            print("hosts_disabled:" + str(len(hosts_to_be_disabled)))
            print("hosts_deleted:" + str(len(hosts_to_be_deleted)))
        finally:
            os.remove(lockfile)


if __name__ == "__main__":
    load_config()
    USER = config['general']['API_USER']
    PASSWORD = config['general']['PASSWORD']
    ZABBIX_SERVER = config['general']['ZABBIX_SERVER']
    LOG_DIR = config['general']['LOG_DIR']
    PSK = config['general']['PSK']
    PSK_IDENTITY = config['general']['PSK_IDENTITY']
    HOSTS_FILE = config['general']['HOSTS_FILE']
    KEY_FILE = config['general']['KEY_FILE']
    GROUP_NAME = "openstack-instances"
    TEMPLATE_NAME = "moc_libvirt_single"
    MAX_PROCESSES = 64
    main_logger = setup_logging(__name__, LOG_DIR + "/main.log")
    main()