Ver código fonte

增加了一些基础文件,以及MySQL数据库连接文件

huanghongbo 1 ano atrás
pai
commit
f87f3212f6

+ 11 - 0
config/database_config.py

@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+"""
+Mysql数据库连接
+"""
+MYSQL_HOST = 'rm-t4n6rz18y4t5x47y70o.mysql.singapore.rds.aliyuncs.com'
+MYSQL_PORT = 3036
+MYSQL_DB = 'brand_cultivation'
+MYSQL_USER = 'BrandCultivation'
+MYSQL_PASSWD = '8BfWBc18NBXl#CMd'
+

+ 35 - 0
dao/mysql_client.py

@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+from sqlalchemy import create_engine, text
+from sqlalchemy.dialects.mysql import pymysql
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy.ext.declarative import declarative_base
+from config import database_config
+
+
+class Mysql(object):
+    def __init__(self):
+        host = database_config.MYSQL_HOST
+        port = database_config.MYSQL_PORT
+        user = database_config.MYSQL_USER
+        passwd = database_config.MYSQL_PASSWD
+        dbname = database_config.MYSQL_DB
+        self.engine = self._connect(host, port, user, passwd, dbname)
+        self.engine = create_engine(self.engine)
+        self._DBSession = sessionmaker(bind=self.engine)
+
+    def _connect(self, host, port, user, pwd, db):
+        client = "mysql+pymysql://" + user + ":" + pwd + "@" + host + ":" + str(port) + "/" + db
+        return client
+
+    @property
+    def DBSession(self):
+        return self._DBSession
+
+
+if __name__ == '__main__':
+    client = Mysql()
+    sess = client.DBSession()
+    info = sess.execute(text('show tables'))
+    for tb in info:
+        print(tb)

+ 2 - 0
models/rank/gbdt_lr.py

@@ -0,0 +1,2 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-

+ 2 - 0
models/recall/hot_recall.py

@@ -0,0 +1,2 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-

+ 2 - 0
models/recall/itemCF.py

@@ -0,0 +1,2 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-