-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAN-65] 전체적으로 필드 이름 변경, category 매핑테이블로 변경 (#17)
- Loading branch information
1 parent
7e52a1e
commit eeb100c
Showing
5 changed files
with
126 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
|
||
delete_table_restaurants = """ | ||
DROP TABLE IF EXISTS `restaurants`; | ||
""" | ||
delete_table_restaurant_likes= """ | ||
DROP TABLE IF EXISTS `restaurant_likes`; | ||
DELETE FROM `restaurants`; | ||
""" | ||
delete_table_categories= """ | ||
DROP TABLE IF EXISTS `categories`; | ||
DELETE FROM `categories`; | ||
""" | ||
delete_table_restaurant_categories = """ | ||
DELETE FROM `restaurant_categories`; | ||
""" | ||
delete_table_operating_infos= """ | ||
DROP TABLE IF EXISTS `operating_infos`; | ||
DELETE FROM `operating_infos`; | ||
""" | ||
delete_table_menus= """ | ||
DROP TABLE IF EXISTS `menus`; | ||
DELETE FROM `menus`; | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,65 @@ | ||
import pymysql | ||
import csv | ||
|
||
import pymysql | ||
|
||
from create_table import create_table | ||
from insert import * | ||
|
||
# connect to MySQL server | ||
conn = pymysql.connect( | ||
host="127.0.0.1", | ||
port=3306, | ||
user="skku-user", | ||
password="skku-pw", | ||
db="skku", | ||
charset='utf8' | ||
host="127.0.0.1", | ||
port=3306, | ||
user="skku-user", | ||
password="skku-pw", | ||
db="skku", | ||
charset='utf8' | ||
) | ||
|
||
# table creation query(restaurants, restaurant_likes) | ||
cursor = conn.cursor() | ||
create_table(cursor) | ||
conn.commit() | ||
|
||
# Insert restaurants, categories | ||
with open('../restaurants.csv', mode='r') as file: | ||
csv_dict = csv.DictReader(file) | ||
categories = dict() | ||
category_id = 1 | ||
restaurants = [] | ||
for restaurant in csv_dict: | ||
restaurants.append(restaurant) | ||
if restaurant['custom_category'] not in categories: | ||
categories[restaurant['custom_category']] = category_id | ||
category_id += 1 | ||
|
||
for c in categories: | ||
insert_into_categories(cursor, categories[c], c) | ||
|
||
# Insert restaurants, categories | ||
with open('../restaurants.csv', mode ='r')as file: | ||
csv_dict = csv.DictReader(file) | ||
for restaurant in csv_dict: | ||
insert_into_restaurants(cursor, restaurant) | ||
insert_into_categories(cursor, restaurant) | ||
for restaurant in restaurants: | ||
insert_into_restaurants(cursor, restaurant) | ||
insert_into_restaurant_categories( | ||
cursor, | ||
restaurant['id'], | ||
categories[restaurant['custom_category']] | ||
) | ||
|
||
conn.commit() | ||
|
||
# Insert operating_infos | ||
with open('../operations.csv', mode ='r')as file: | ||
csv_dict = csv.DictReader(file) | ||
for operation in csv_dict: | ||
insert_into_operating_infos(cursor, operation) | ||
|
||
with open('../operations.csv', mode='r') as file: | ||
csv_dict = csv.DictReader(file) | ||
for operation in csv_dict: | ||
insert_into_operating_infos(cursor, operation) | ||
|
||
conn.commit() | ||
|
||
# Insert menus | ||
with open('../menus.csv', mode ='r')as file: | ||
csv_dict = csv.DictReader(file) | ||
for menu in csv_dict: | ||
insert_into_menus(cursor, menu) | ||
with open('../menus.csv', mode='r') as file: | ||
csv_dict = csv.DictReader(file) | ||
for menu in csv_dict: | ||
insert_into_menus(cursor, menu) | ||
|
||
conn.commit() | ||
|
||
|
||
# close the connection | ||
conn.close() | ||
conn.close() |