Esempio n. 1
0
def main():
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(levelname)s %(message)s')
    epmongo = EPMongo()
    # epmongo = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')

    wb = load_workbook('defaultTerminal.xlsx')
    ws = wb.active
    max_row = ws.max_row
    for row in range(2, max_row + 1):
        default_terminal = {}
        port_id = ws.cell(row=row, column=3).value
        stdb = ws.cell(row=row, column=6).value
        stot = ws.cell(row=row, column=8).value
        if stdb:
            default_terminal.setdefault('STDB', ObjectId(stdb))
        if stot:
            default_terminal.setdefault('STOT', ObjectId(stot))
        if default_terminal:
            logging.info('row={} {}:{}'.format(row, port_id, default_terminal))
            logging.info(
                epmongo.update_one(
                    "ports", {'_id': ObjectId(port_id)},
                    {"$set": {
                        'defaultTerminal': default_terminal
                    }}))
Esempio n. 2
0
def get_organizations(verify_status=0):
    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    query = {"dateDelete": {"$exists": False}, "verifyStatus": verify_status}
    projection = {"_id": 1, "name": 1, "role": 1, "ports": 1}
    organizations = epmongo.get_docs_by_query("organizations", query, projection)
    # sort by dataUpdate
    organizations = organizations.sort([('dateUpdate', pymongo.DESCENDING)])
    logging.debug((organizations.count(), type(organizations)))

    ports = epmongo.get_docs_by_query("ports", None, {'name': 1, 'code': 1, '_id': 1})
    ports = {doc.get('_id'): (doc.get('code'), doc.get('name')) for doc in ports}

    organizations_list = []
    for doc in organizations:
        service_ports = doc.get('ports', '')
        if service_ports:
            str_ports = '\n'.join(
                [(ports.get(service_port)[0] + ': ' + ports.get(service_port)[1]) for service_port in service_ports])
            doc['ports'] = str_ports
        else:
            doc['ports'] = ''
        organizations_list.append(doc)
    return len(organizations_list), organizations_list
Esempio n. 3
0
 def __init__(self):
     with open('check_ships.txt') as f:
         self._ships = [l.strip() for l in f.readlines()]
         # self._epmongo = EPMongo()
     self._epmongo = EPMongo(
         uri=
         "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
         db_name='epdb-prod')
Esempio n. 4
0
def get_results():
    epmongo = EPMongo()
    # epmongo = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    pipeline = generate_pipeline()
    results = epmongo.aggregate('products', pipeline)
    return results
Esempio n. 5
0
def get_order_types():
    epmongo = EPMongo()
    # epmongo = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    docs = epmongo.get_docs_by_query('ordertypes',
                                     {'dateDelete': {
                                         '$exists': False
                                     }}, {
                                         'name': 1,
                                         'code': 1
                                     })
    order_types = {}
    for doc in docs:
        code = doc.get('code')
        name = doc.get('name')
        order_types[code] = name
    return order_types
Esempio n. 6
0
def main():
    # epmongo = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    epmongo = EPMongo()
    parser = argparse.ArgumentParser(prog='clear ep db',
                                     description='clear ep db')

    parser.add_argument('c',
                        choices=[
                            'clear_order_by_order_number',
                            'clear_order_by_order_id',
                            'clear_voyage_by_voyage_id',
                            'clear_ship_by_ship_id', 'clear_user_by_username',
                            'get_user_by_username', 'get_users_by_account_id',
                            'delete_users_by_account_id'
                        ],
                        help='commands for clear operations')

    parser.add_argument('d', help='query condition')

    parser.add_argument('--version', action='version', version='%(prog)s 1.0')

    args = parser.parse_args()
    c = args.c
    d = args.d
    print(c, d)
    if c == 'clear_order_by_order_number':
        order_number = d
        clear_order_by_order_number(epmongo, order_number)
    if c == 'clear_order_by_order_id':
        order_id = ObjectId(d)
        clear_order_by_order_id(epmongo, order_id, 0)
    if c == 'clear_voyage_by_voyage_id':
        voyage_id = ObjectId(d)
        clear_voyage_by_voyage_id(epmongo, voyage_id, 0)
    if c == 'clear_ship_by_ship_id':
        ship_id = ObjectId(d)
        clear_ship_by_ship_id(epmongo, ship_id, 0)
    if c == 'clear_user_by_username':
        username = d
        clear_user_by_username(epmongo, username, 0)
    if c == 'get_user_by_username':
        username = d
        get_user_by_username(epmongo, username, 0)
    if c == 'get_users_by_account_id':
        account_id = ObjectId(d)
        get_users_by_account_id(epmongo, account_id, 0)
    if c == 'delete_users_by_account_id':
        account_id = ObjectId(d)
        delete_users_by_account_id(epmongo, account_id, 0)
Esempio n. 7
0
def get_ordertypes():
    ep = EPMongo()
    # ep = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    docs = ep.get_docs_by_query('ordertypes',
                                query=None,
                                projection={
                                    'name': 1,
                                    'code': 1,
                                    'defaults': 1
                                })
    docs.sort([('code', pymongo.ASCENDING)])
    products = ep.get_docs_by_query('products',
                                    query=None,
                                    projection={
                                        'name': 1,
                                        'code': 1
                                    })
    products = {
        product.get('_id', ''): (product.get('name',
                                             ''), product.get('code', ''))
        for product in products
    }
    ordertypes = []
    for doc in docs:
        name = doc.get('name', '')
        code = doc.get('code', '')
        defaults = doc.get('defaults', '')
        default_products = []
        if defaults:
            for default in defaults:
                product_name, product_code = products.get(default, '')
                default_products.append((product_name, product_code))
        ordertypes.append((name, code, default_products))
    return ordertypes
Esempio n. 8
0
            "$unwind": {
                "path": "$position.group",
            }
        },
        {
            "$project": {
                "username": 1,
                "account": "$position.group.account"
            }
        },
    ]
    return pipeline


if __name__ == '__main__':
    epmongo = EPMongo()
    users = epmongo.get_docs_by_query('users',
                                      query=None,
                                      projection={'_id': 1})
    # print(c, users[0])
    # pipeline = generate_pipeline(users[0]['_id'])
    # docs = epmongo.aggregate('users', pipeline)
    # print(docs)
    # for each in docs:
    #     print(each)
    for each in users:
        pipeline = generate_pipeline(each['_id'])
        print(pipeline)
        for result in (epmongo.aggregate('users', pipeline)):
            print(result)
Esempio n. 9
0
@Filename: update_geo
@Author: Gui


"""
import logging
from bson.objectid import ObjectId
from openpyxl import load_workbook
from epMongo import EPMongo

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(levelname)s %(message)s')
    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri=
        "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    wb = load_workbook('ports.xlsx')
    ws = wb.active
    j = 1
    for i in range(1, ws.max_row + 1):
        port_id = ObjectId(ws.cell(row=i + 1, column=2).value)
        country = ws.cell(row=i + 1, column=5).value
        geo = ws.cell(row=i + 1, column=6).value
        if country == 'China':
            logging.debug((j, port_id, country, geo))
            j = j + 1
            logging.info(
                epmongo.update_one("ports", {'_id': port_id},
                                   {"$set": {
                                       'geo': geo
Esempio n. 10
0
# coding=utf-8
"""
Created on 2017-12-11

@Filename: update_username_status
@Author: Gui


"""
import logging
import datetime
from epMongo import EPMongo

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    epmongo = EPMongo(
        uri=
        "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    with open('mailers.txt') as f:
        users = [line.strip() for line in f.readlines()]
    now = datetime.datetime.utcnow()
    for i, username in enumerate(users, 1):
        logging.debug((i, username))
        logging.info(
            epmongo.update_one("users", {'username': username},
                               {"$set": {
                                   'status': "normal"
                               }}))
        # logging.debug(epmongo.update_one("users", {'username': username}, {"$set": {'dateDelete': now}}))
Esempio n. 11
0
class CHECK(object):
    def __init__(self):
        with open('check_ships.txt') as f:
            self._ships = [l.strip() for l in f.readlines()]
            # self._epmongo = EPMongo()
        self._epmongo = EPMongo(
            uri=
            "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
            db_name='epdb-prod')

    @timeit.timeit
    def check_orders(self):
        results = []
        docs = self._epmongo.get_docs_by_query('orders', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_inquiryorders(self):
        results = []
        docs = self._epmongo.get_docs_by_query('inquiryorders', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_voyagesegments(self):
        results = []
        docs = self._epmongo.get_docs_by_query('voyagesegments', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_messages(self):
        results = []
        docs = self._epmongo.get_docs_by_query('messages', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_operationlogs(self):
        results = []
        docs = self._epmongo.get_docs_by_query('operationlogs', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_favships(self):
        results = []
        docs = self._epmongo.get_docs_by_query('favships', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_shipcorrections(self):
        results = []
        docs = self._epmongo.get_docs_by_query('shipcorrections', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_fleets(self):
        results = []
        docs = self._epmongo.get_docs_by_query('fleets', {}, {
            '_id': 1,
            'ships': 1
        })
        for i, doc in enumerate(docs, 1):
            ships = doc.get('ships')
            for ship in ships:
                if str(ship) in self._ships:
                    results.append((doc, str(ship)))
        return results

    @timeit.timeit
    def check_ownerships(self):
        results = []
        docs = self._epmongo.get_docs_by_query('ownerships', {}, {
            '_id': 1,
            'ships': 1
        })
        for i, doc in enumerate(docs, 1):
            ships = doc.get('ships')
            for ship in ships:
                if str(ship) in self._ships:
                    results.append((doc, str(ship)))
        return results
Esempio n. 12
0
 def __init__(self):
     # self._epmongo = EPMongo()
     self._epmongo = EPMongo(
         uri=
         "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
         db_name='epdb-prod')
Esempio n. 13
0
class PORTS(object):
    def __init__(self):
        # self._epmongo = EPMongo()
        self._epmongo = EPMongo(
            uri=
            "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
            db_name='epdb-prod')

    def get_ports(self):
        self.ports = self._epmongo.get_docs_by_query(
            'ports', {'dateDelete': {
                '$exists': False
            }}, {
                'name': 1,
                'code': 1,
                'country': 1,
                'terminals': 1,
                'shipyards': 1,
                'defaultTerminal': 1
            })
        return self.ports

    def _get_country(self, country_id):
        doc = self._epmongo.get_doc_by_query('countries', {'_id': country_id},
                                             {'name': 1})
        return doc['name']

    def _get_terminal(self, terminal_id):
        doc = self._epmongo.get_doc_by_query('terminals', {'_id': terminal_id},
                                             {
                                                 'name': 1,
                                                 '_id': 1
                                             })
        return doc

    def _get_shipyard(self, shipyard_id):
        doc = self._epmongo.get_doc_by_query('shipyards', {'_id': shipyard_id},
                                             {
                                                 'name': 1,
                                                 '_id': 1
                                             })
        return doc

    def parse_one(self, port_doc):
        port_dict = {}
        _id = port_doc.get('_id')
        port_dict['_id'] = _id
        name = port_doc.get('name')
        port_dict['name'] = name
        code = port_doc.get('code')
        port_dict['code'] = code
        country = self._get_country(port_doc.get('country'))
        port_dict['country'] = country

        terminals = port_doc.get('terminals')
        if terminals is not None and len(terminals) != 0:
            terminals_list = []
            for terminal_id in terminals:
                terminal_doc = self._get_terminal(terminal_id)
                terminals_list.append(terminal_doc)
            port_dict['terminals'] = terminals_list
        shipyards = port_doc.get('shipyards')
        if shipyards is not None and len(shipyards) != 0:
            shipyards_list = []
            for shipyard_id in shipyards:
                shipyard_doc = self._get_shipyard(shipyard_id)
                shipyards_list.append(shipyard_doc)
            port_dict['shipyards'] = shipyards_list

        default_terminal = port_doc.get('defaultTerminal')
        if default_terminal:
            stdb = default_terminal.get('STDB')
            if stdb:
                port_dict['STDB'] = self._get_terminal(stdb)
            stot = default_terminal.get('STOT')
            if stot:
                port_dict['STOT'] = self._get_terminal(stot)
        return port_dict
Esempio n. 14
0
def main():
    epmongo = EPMongo()
    ports = get_ports(epmongo)
    for each in enumerate(ports):
        update_anchorages(epmongo, each[1])
Esempio n. 15
0
    ws.cell(row=1, column=5).value = 'isSuperAdmin'
    ws.cell(row=1, column=6).value = 'status'
    ws.cell(row=1, column=7).value = 'group_id'
    ws.cell(row=1, column=8).value = 'group_name'
    ws.cell(row=1, column=9).value = 'group_default'
    ws.cell(row=1, column=10).value = 'group_dateDelete'
    ws.cell(row=1, column=11).value = 'account_id'
    ws.cell(row=1, column=12).value = 'account_name'
    ws.cell(row=1, column=13).value = 'account_types'
    ws.cell(row=1, column=14).value = 'organization_id'
    ws.cell(row=1, column=15).value = 'organization_name'
    ws.cell(row=1, column=16).value = 'organization_dateDelete'

    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri=
        "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    users = epmongo.get_docs_by_query('users',
                                      query=None,
                                      projection={'_id': 1})
    j = 1
    logging.info('Total %d users.' % users.count())
    for i, each in enumerate(users, 1):
        user_id = each['_id']
        pipeline = generate_pipeline(user_id)
        logging.info("{} {}".format(i, str(user_id)))
        for result in (epmongo.aggregate('users', pipeline)):
            logging.info(result)
            ws.cell(row=j + 1, column=1).value = i
            ws.cell(row=j + 1,
                    column=2).value = str(dict_has_key(result, '_id'))
Esempio n. 16
0
        result = 0
        n = len(number_list)
        for o in range(0, n - 1):
            result = result + number_list[o] * (n - o)
        if (result % 10) == number_list[-1]:
            return 'valid'
        else:
            return 'invalid'


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(levelname)s %(message)s')
    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri=
        "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    ships = epmongo.get_docs_by_query('ships',
                                      {'dateDelete': {
                                          '$exists': False
                                      }}, {
                                          'name': 1,
                                          'imo': 1,
                                          'type': 1,
                                          'dateCreate': 1,
                                          'dateUpdate': 1
                                      })
    ships = ships.sort([('imo', pymongo.ASCENDING)])
    logging.info('total {} ships.'.format(ships.count()))
    wb = Workbook()
    ws = wb.active
Esempio n. 17
0
@Filename: update_organization_status
@Author: Gui


"""
import logging
import datetime
from epMongo import EPMongo
from bson.objectid import ObjectId

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    now = datetime.datetime.utcnow()
    print(type(now), now)
    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri=
        "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    with open('organizationIds.txt') as f:
        organizations = [line.strip() for line in f.readlines()]
    for i, organization_id in enumerate(organizations, 1):
        logging.debug((i, organization_id))
        logging.debug(
            epmongo.update_one("organizations",
                               {'_id': ObjectId(organization_id)},
                               {"$set": {
                                   'verifyStatus': 1
                               }}))
        # epmongo.update_one("organizations", {'_id': ObjectId(organization_id)}, {"$set": {"dateDelete": now}}))
Esempio n. 18
0
"""
Created on 2017-12-28

@Filename: update_organization_status
@Author: Gui


"""
import logging
import datetime
from epMongo import EPMongo
from bson.objectid import ObjectId

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    now = datetime.datetime.utcnow()
    print(type(now), now)
    epmongo = EPMongo()
    # epmongo = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    with open('shipIds.txt') as f:
        ships = [line.strip() for line in f.readlines()]
    for i, ship_id in enumerate(ships, 1):
        logging.debug((i, ship_id))
        logging.debug(
            epmongo.update_one("ships", {'_id': ObjectId(ship_id)},
                               {"$set": {
                                   "dateDelete": now
                               }}))