Пример #1
0
 def link_tickets(self):
     """Link tickets to their respective organizations and users"""
     logging.debug("+++ linking tickets with organizations...")
     for ticket in self.ticket_dao.tickets:
         tck_id = ticket.get('_id')
         # 1. link tickets to orgs
         try:
             organization_id = ticket.get("organization_id")
             if organization_id is None:
                 logging.debug(
                     f"tck = {tck_id} doesn't have an organization_id")
             else:
                 logging.debug(f"1.t->o {tck_id} -> {organization_id}")
                 org = SearchAPI.search_org_by_id(self.org_dao,
                                                  organization_id)
                 org['tickets'].append(ticket)
         except Exception as e:
             logging.warning(f"{e}, can't link tck {tck_id}")
             if config.FULL_RELATIONAL:
                 self.ticket_dao.tickets.remove(ticket)
                 continue
         # 2. link tickets to submitters
         try:
             submitter_id = ticket.get("submitter_id")
             if submitter_id is None:
                 logging.debug(f"tck = {tck_id} doesn't have a submitter")
             else:
                 submitter = SearchAPI.search_user_by_id(
                     self.user_dao, submitter_id)
                 logging.debug(
                     f"2.t->s | tck = {tck_id} -> submitter_id {submitter_id}"
                 )
                 submitter['tickets_submitted'].append(ticket)
         except Exception as e:
             logging.warning(f"submitter {e} , can't link tck {tck_id}")
             if config.FULL_RELATIONAL:
                 self.ticket_dao.tickets.remove(ticket)
                 continue
         # 3. link tickets to assignees
         try:
             assignee_id = ticket.get("assignee_id")
             if assignee_id is None:
                 logging.debug(f"tck = {tck_id} doesn't have an assignee")
             else:
                 assignee = SearchAPI.search_user_by_id(
                     self.user_dao, assignee_id)
                 logging.debug(
                     f"+3.t->a | tck = {tck_id} -> assignee_id {assignee_id}"
                 )
                 assignee['tickets_assigned'].append(ticket)
         except Exception as e:
             logging.warning(f"assignee {e} , can't link tck {tck_id}")
             if config.FULL_RELATIONAL:
                 self.ticket_dao.tickets.remove(ticket)
Пример #2
0
    def export_ticket(self, results, export_format):
        """Exports Ticket object

    Keyword arguments:
    ticket -- ticket to export
    export_format -- export type format
    """
        DataExporter.show_header('TICKET')
        if isinstance(results, ResultSet):
            ticket = results.item
            logging.debug(f"printing ticket: {ticket.get('_id')}")
            DataExporter.export_item(ticket, export_format)
            logging.debug(f"printing submitter..")
            submitter_id = ticket.get("submitter_id")
            if submitter_id is None:
                logging.info(
                    f"tck = {ticket.get('_id')} doesn't have a submitter")
            else:
                submitter = SearchAPI.search_user_by_id(
                    self.user_dao, submitter_id)
                DataExporter.show_user_relation(submitter, 'submitter',
                                                export_format)
            logging.debug(f"printing assignee...")
            assignee_id = ticket.get("assignee_id")
            logging.debug(f"assignee_id {assignee_id}..")
            if assignee_id is None:
                logging.debug(
                    f"tck = {ticket.get('_id')} doesn't have an assignee")
            else:
                assignee = SearchAPI.search_user_by_id(self.user_dao,
                                                       assignee_id)
                DataExporter.show_user_relation(assignee, 'assignee',
                                                export_format)
            # print org
            organization_id = ticket.get("organization_id")
            if organization_id is None:
                logging.warning(
                    f"{ticket.get('_id')} doesn't have an organization_id")
            else:
                org = SearchAPI.search_org_by_id(self.org_dao, organization_id)
                DataExporter.show_org_relation(org, export_format)
        else:
            DataExporter.show_not_found(results)
Пример #3
0
    def search_users(self, key_name, value):
        """Search users by all fields

    Keyword arguments:
    key_name -- name of field
    value -- value of field to search
    """

        logging.info(f"searching by: field='{key_name}',value='{value}'")
        Validator.validate_input(key_name, value)
        return SearchAPI.search_user_by_field(self.user_dao, key_name, value)
Пример #4
0
    def export_user(self, results, export_format):
        """Exports User result

    Keyword arguments:
    user -- user to export
    export_format -- export type format
    """
        logging.info(f"show_header")
        DataExporter.show_header('USER')
        if isinstance(results, ResultSet):
            user = results.item
            logging.debug(f"found: {user.get('name')}")
            DataExporter.export_item(user, export_format)
            organization_id = user.get("organization_id")
            if organization_id is None:
                logging.warning(
                    f"{user.get('_id')} doesn't have an organization_id")
            else:
                org = SearchAPI.search_org_by_id(self.org_dao,
                                                 user.get("organization_id"))
                DataExporter.show_org_relation(org, export_format)
        else:
            DataExporter.show_not_found(results)
Пример #5
0
 def link_users(self):
     """Link users to their respective organizations"""
     logging.debug(">>> linking users with organizations...")
     for user in self.user_dao.users:
         for org in self.org_dao.organizations:
             try:
                 organization_id = user.get("organization_id")
                 if organization_id is None:
                     logging.warning(
                         f"user {user.get('_id')} doesn't have an organization_id"
                     )
                     if config.FULL_RELATIONAL:
                         self.user_dao.users.remove(user)
                     break
                 else:
                     org = SearchAPI.search_org_by_id(
                         self.org_dao, organization_id)
                     self.add_user_to_org(user, org)
             except Exception as e:
                 logging.warning(
                     f"{e}, can't link user id {user.get('_id')}")
                 if config.FULL_RELATIONAL:
                     self.user_dao.users.remove(user)
                 continue
Пример #6
0
import logging

from flask import Flask, render_template, request
from flask.json import jsonify

from google.appengine.ext import deferred

from search_api import SearchAPI

app = Flask(__name__)

search_client = SearchAPI()


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/search')
def search():
    """based on user query it executes search and returns list of item in json"""
    query = request.args.get('query', '')
    results = search_client.search(query)
    return jsonify(results)


@app.route('/upload', methods=['POST'])
def upload():
    """gets data for one product and saves into search index"""
    json_data = request.get_json()
Пример #7
0
    enriched_array = []
    company_employees = []
    zoominfo_company_employees = []
    zoominfo_extra_company_array = []
    related_companies = []
    zoominfo_company_data = []
    glassdoor_company_data = []
    hiring_contacts = []
    keyword_companies = []

    try:
        #
        # Create the classes for Scrapers
        #
        # SearchAPI(api_method, use_proxy, use_selenium)
        search = SearchAPI(args_array["search_method"],
                           args_array['use_search_proxy'])
        raw_search = SearchAPI("raw", False)
        selenium_search = SearchAPI("zenserp", args_array['use_search_proxy'],
                                    True)
        # Create an object for the Email validator
        # TODO: write a script only to validate a single email address???
        email_finder = EmailValidation()
    except Exception as e:
        print(e)
        raise Exception('Error importing search API modules...')

    # Prepare an exit function
    # TODO: must delete all the temp page data after
    atexit.register(exit_handler, args_array, enriched_array,
                    company_employees, related_companies,
                    zoominfo_company_data, zoominfo_extra_company_array,