class ImportData(object):

    """import stock codes into MySQL


    Attributes:
        no.
    """

    def __init__(self):

        """initiate object


        Attributes:
            no.
        """
        self.func = FunctionModule()
        self.dir = 'D:/stock_list.csv'

    def main(self):

        """main function


        Attributes:
            no.
        """
        file = self.func.get_data_from_text(self.dir, 'r', 'utf8')
        for line in file:
            sql = "INSERT INTO stock_codes (stock_code, stock_name, industry_1_id, industry_1_name, " \
                  "industry_2_id, industry_2_name) VALUES ('%s', '%s','%s', '%s', '%s', '%s')" \
                  % (line['stock_code'], line['stock_name'], line['industry_1_id'],
                     line['industry_1_name'], line['industry_2_id'], line['industry_2_name'])
            self.func.insert_into_mysql(sql)
    def __init__(self):

        """initiate object


        Attributes:
            no.
        """
        self.func = FunctionModule()
        self.dir = 'D:/stock_list.csv'
Example #3
0
    def _fun_input_generate(self, fun_node):
        assert (isinstance(fun_node, ast.FunctionDef))

        fun_obj = FunctionModule(self.whole_ast, fun_node.name)
        for cf_key in fun_obj.cf_input.keys():
            if fun_obj.cf_input[cf_key] is None:
                avm_obj = AvmSearch(fun_obj, *cf_key, self.precision,
                                    self.avm_random_range,
                                    self.avm_variable_max_iter,
                                    self.avm_optimize_max_iter)
                avm_obj.optimize()

        return fun_obj
    def __init__(self):

        """initiate object


        Attributes:
            no.
        """
        self.sql_get_data = 'SELECT * FROM shangshi_zixun'
        self.sql_get_codes = 'SELECT stock_code, stock_name, industry_1_id FROM stock_codes'
        self.sql_get_keywords = 'SELECT industry_1_id, keywords FROM industry_keywords'
        # self.ele_list = ('title', 'article', 'tag')
        self.control = ('t_title', 'industry_1_id')
        self.func = FunctionModule()
class FinanceClassification(object):

    """industry classification function module


    Attributes:
        no.
    """

    def __init__(self):

        """initiate object


        Attributes:
            no.
        """
        self.sql_get_data = 'SELECT * FROM shangshi_zixun'
        self.sql_get_codes = 'SELECT stock_code, stock_name, industry_1_id FROM stock_codes'
        self.sql_get_keywords = 'SELECT industry_1_id, keywords FROM industry_keywords'
        # self.ele_list = ('title', 'article', 'tag')
        self.control = ('t_title', 'industry_1_id')
        self.func = FunctionModule()

    def _match(self, data, stcodes, args, keywords=None):

        """match function


        Attributes:
            args:four eles, stock code, stock name, title, industry id

        """
        if keywords:
            for line in keywords:
                line['keywords'] = line['keywords'].split(',')
        tag = {}
        for line in data:
            temp_stock = []
            # for code in stcodes:
            #     code_judge = code['stock_code'] in line[args[0]]
            #     name_judge = code['stock_name'] in line[args[0]]
            #     if code_judge or name_judge:
            #         temp_stock.append(code[args[1]])
            temp_keywords = []
            if keywords:
                for item in keywords:
                    for w in item['keywords']:
                        keywords_judge = w in line[args[0]]
                        if keywords_judge:
                            temp_keywords.append(item[args[1]])
            # Tag = self._merge_tags(tags_stock, tags_keywords)
            Tag = list(set(temp_stock + temp_keywords))
            tag[line['i_id']] = Tag
        return tag

    # def _merge_tags(self, *args):
    #
    #     """match function
    #
    #
    #     Attributes:
    #         args:two dict with same keys
    #
    #     """
    #     if len(args) > 1:
    #         new_dict = {}
    #         for k_1, v_1 in args[0].items():
    #             for k_2, v_2 in args[1].items():
    #                 if k_1 == k_2:
    #                     temp_value = v_1 + v_2
    #                     temp_value = list(set(temp_value))
    #             new_dict[k_1] = temp_value
    #         return new_dict
    #     else:
    #         return args




    def main(self):

        """main function


        Attributes:
            no.
        """
        data = self.func.get_data_from_MySQL(self.sql_get_data)
        stock_codes = self.func.get_data_from_MySQL(self.sql_get_codes)
        keywords = self.func.get_data_from_MySQL(self.sql_get_keywords)
        tags = self._match(data, stock_codes,self.control,keywords=keywords)
        for k, v in tags.items():
            if len(v) > 1:
                print k, v
        print tags