forked from LoRexxar/Pansidong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateTables.py
32 lines (24 loc) · 875 Bytes
/
CreateTables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python2
# coding: utf-8
import ConfigParser
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from utils.data.LoggerHelp import logger
from utils.data.Tables import Proxy
__author__ = "lightless"
__email__ = "[email protected]"
if __name__ == "__main__":
cf = ConfigParser.ConfigParser()
cf.read("config.ini")
db_name = cf.get("ProxySpider", "database")
username = cf.get(db_name, "username")
password = cf.get(db_name, "password")
host = cf.get(db_name, "host")
database = cf.get(db_name, "database")
engine = create_engine("mysql://" + username + ":" + password + "@" + host + "/" + database)
db_session = sessionmaker(bind=engine)
try:
Proxy.metadata.create_all(engine)
logger.debug("Tables create success.")
except Exception, e:
logger.error(e.message)