Skip to content

Commit 0051902

Browse files
committed
Database copy script
1 parent 378d15e commit 0051902

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ docs/_build/
5959
# PyBuilder
6060
target/
6161

62+
config.yml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
- python
88
- flask
9-
- mongodb
9+
- mongodb

config.dist.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mysql:
2+
host: localhost
3+
database: db
4+
username: user
5+
password: pass

db-data-copy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import MySQLdb
2+
import yaml
3+
4+
5+
def load_configuration():
6+
with open('config.yml', 'r') as f:
7+
config_file = f.read()
8+
return yaml.load(config_file)
9+
10+
11+
def get_cursor(dbconf):
12+
db = MySQLdb.connect(host=dbconf.get('hostname'), user=dbconf.get('username'), passwd=dbconf.get('password'),
13+
db=dbconf.get('database'))
14+
return db.cursor()
15+
16+
17+
config = load_configuration()
18+
cursor = get_cursor(config.get('mysql', {}))
19+
20+

makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db-data-copy:
2+
python db-data-copy.py

0 commit comments

Comments
 (0)