#-*-coding: utf-8 -*-


from __future__ import print_function
from datetime import date, datetime, timedelta
import mysql.connector
import os
from mysql.connector import errorcode

DB_NAME = 'dbdbdeep'
print("DB loading...\n\n")
#login(connect to mysql)---------------------------------------------------------------------------------
try:
  cnx = mysql.connector.connect(host= 'dbdbdeep.co7zvonejcs7.ap-northeast-2.rds.amazonaws.com',
                                user='blcocas',
                                password = '201221027',
                                charset='utf8mb4')
  cursor = cnx.cursor()
  print("success to connect")

except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exist")
  else:
    print(err)

#create database-----------------------------------------------------------------------------------------
def create_database(cursor):
    try:
        cursor.execute(
            "CREATE DATABASE {} DEFAULT CHARACTER SET 'utf8'".format(DB_NAME))
        print("success to creat DB")
    except mysql.connector.Error as err:
        print("Failed creating database: {}".format(err))
        exit(1)

try:
    cnx.database = DB_NAME  
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_BAD_DB_ERROR:
        create_database(cursor)
        cnx.database = DB_NAME
    else:
        print(err)
        exit(1)

#Relation-----------------------------------------------------------------------------------------------

TABLES = {}

TABLES['FOOD'] = (
"CREATE TABLE  `FOOD`(" 
"`Food_Name`        varchar(15)     NOT NULL,"
"`Food_Num`         char(8)         NOT NULL,"
"PRIMARY KEY (`Food_Num`)"
") ENGINE=InnoDB")


TABLES['FOOD_TYPE'] = (
"CREATE TABLE  `FOOD_TYPE` ("
"`Type_Name`       varchar(15)       NOT NULL,"
"`Type_Num`        char(8)           NOT NULL,"
"PRIMARY KEY (`Type_Num`)"
")ENGINE=InnoDB")

TABLES['COOKED_BY'] = (
"CREATE TABLE  `COOKED_BY` ("   
"`F_Num`        char(8)     NOT NULL,"
"`R_Num`        char(8)     NOT NULL,"
"PRIMARY KEY(`F_Num`, `R_Num`),"
"FOREIGN KEY (`F_Num`) REFERENCES `FOOD`(`Food_Num`),"
"FOREIGN KEY (`R_Num`) REFERENCES `RESTAURANT`(`Rest_Num`)"
")ENGINE=InnoDB")

    
TABLES['RESTAURANT'] = (
"CREATE TABLE  RESTAURANT ( "
"`Rest_Name`       varchar(15)     NOT NULL,"
"`Rest_Num`        char(8)     NOT NULL,"
"`T_Num`           char(8)     NOT NULL,"
"`Map`            varchar(100)     ,"
"`Average_Cost`    varchar(15)         ,"
"PRIMARY KEY (`Rest_Num`),"
"FOREIGN KEY (`T_Num`) REFERENCES FOOD_TYPE(`Type_Num`)"
")ENGINE=InnoDB")



 #foreign key constraints unlock argument-----------------------------------------------------------------               

disable_foreign = ''' 
    SET FOREIGN_KEY_CHECKS = 0;
'''
enable_foreign = ''' 
    SET FOREIGN_KEY_CHECKS = 1;
'''

#create tables------------------------------------------------------------------------------------------
cursor.execute(disable_foreign) #foreign key constraint no check

for name, ddl in TABLES.iteritems():
    try:
        print("Creating table {}: ".format(name), end='')
        cursor.execute(ddl)
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
            print("already exists.")
        else:
            print(err.msg)
    else:
        print("OK")
#insert data form---------------------------------------------------------------------------------------
INSERT_TABLES = {}
INSERT_TABLES['FOOD'] = ("INSERT INTO FOOD "
            "(Food_Name, Food_Num)"
            "VALUES (%s, %s)")

INSERT_TABLES['FOOD_TYPE'] = ("INSERT INTO FOOD_TYPE "
            "(Type_Name,Type_Num)"
            "VALUES (%s, %s)")

INSERT_TABLES['COOKED_BY'] = ("INSERT INTO COOKED_BY "
            "(F_Num,R_Num)"
            "VALUES (%s, %s)")

INSERT_TABLES['RESTAURANT'] = ("INSERT INTO RESTAURANT "
            "(Rest_Name,Rest_Num,T_Num,Map,Average_Cost)"
            "VALUES (%s, %s, %s, %s, %s)")

#tuples-------------------------------------------------------------------------------------------------
DATA_TABLES = {}
DATA_TABLES['FOOD'] = [ #40ea
('카레','F145'),
('고씨네 돈까스 카레','F001'),
('고씨네 스페셜 카레','F002'),
('고씨네 프리미엄 카레','F003'),
('돈까스 카레 우동','F004'),
('버섯 카레 우동','F005'),
('버섯 카레','F006'),

('스테이크','F146'),
('스테이크삼겹정식','F007'),
('스테이크정식(소)','F008'),
('삼겹테이크정식(소)','F009'),
('안창불고기스테이크정식','F010'),
('목살스테이크볶음밥','F011'),
('모듬스테이크정식','F012'),

('우동','F147'),
('김치돈까스나베','F013'),
('할라피뇨연어덮밥','F014'),
('수제돈까스','F015'),
('해물야끼우동','F016'),
('달인냉우동','F017'),
('마약냉우동','F018'),

('아주세트','F019'),
('치즈세트','F020'),
('치즈더블세트','F021'),
('솥뚜껑 해물파전','F022'),
('철판 모듬 스페셜','F023'),
('철판 제육 볶음','F024'),

('닭갈비','F148'),
('닭갈비철판볶음밥','F025'),
('매운철판볶음밥','F026'),
('모듬철판볶음밥','F027'),
('유가네닭갈비','F028'),
('미소허니퐁닭','F029'),
('해물철판볶음밥','F030'),

('그릴 목살 스테이크','F031'),
('살치살 소고기 스테이크','F032'),
('핫치킨 꿀치즈 퀘사디아','F033'),
('페퍼로니 토마토 퀘사디아','F034'),
('소고기 감자 스튜','F035'),
('모든치즈크래커','F036'),

('라멘','F149'),
('돈코츠라멘','F037'),
('소유라멘','F038'),
('미소라멘','F039'),
('규동','F040'),
('부타동','F041'),
('차슈동','F042'),

('부리또','F150'),
('치킨라이스','F043'),
('치킨감자','F044'),
('소고기라이스','F045'),
('소세지감자','F046'),
('새우감자','F047'),
('핫도그','F048'),

('제육볶음','F151'),
('해물뚝배기','F049'),
('제육두루치기','F050'),
('참치김치찌개','F051'),
('카레덮밥','F052'),
('돈까스덮밥','F053'),
('곱창순두부찌개','F054'),

('밥버거','F152'),
('봉구스밥버거','F055'),
('햄치즈밥버거','F056'),
('치즈제육밥버거','F057'),
('청양불고기밥버거','F058'),
('소불고기밥버거','F059'),
('통살돈까스마요밥버거','F060'),

('쌀국수','F153'),
('소고기 쌀국수','F061'),
('닭 쌀국수','F062'),
('사이공 볶음밥','F063'),
('사이공 볶음면','F064'),
('새우볼','F065'),
('사이공 딤섬','F066'),

('크리스피','F067'),
('양념치킨','F068'),
('간장','F069'),
('스위트갈릭','F070'),
('스위트버터','F071'),
('반반치킨','F072'),

('짜장면','F073'),
('짱뽕','F074'),
('삼선짬뽕','F075'),
('찹쌀탕수육','F076'),
('양꼬치','F077'),
('군만두','F078'),

('알밥','F155'),
('순한알밥','F079'),
('매콤알밥','F080'),
('매콤치즈알밥','F081'),
('카레알밥','F082'),
('갈릭알밥','F083'),
('갈립치즈알밥','F084'),

('삼겹살','F156'),
('벌집삼겹살','F085'),
('돼지왕구이','F086'),
('갈비탕','F087'),
('김치말이국수','F088'),
('냉면','F089'),
('항정살','F090'),

('찜닭','F157'),
('고추장찜닭','F091'),
('안동찜닭','F092'),
('순살안동장찜닭','F093'),
('순살고추장찜닭','F094'),
('치즈순살찜닭중','F095'),
('치즈순살찜닭대','F096'),

('김치찌개','F098'),
('주먹밥','F099'),
('계란말이','F100'),
('라면','F101'),
('만두','F102'),

('부대찌개','F097'),
#('부대찌개','F103'), F098
('육계장','F104'),
#('갈비탕','F105'), F087
('제육볶음','F106'),
('순두부찌개','F107'),
#('김치찌개','F108'), F097

('곱창','F158'),
('양구이','F109'),
('대창구이','F110'),
('곱창구이','F111'),
('막창구이','F112'),
('천엽','F113'),
('곱창전골','F114'),

('치킨','F154'),
('전설의치킨','F115'),
('칠리새우순살','F116'),
#('양념치킨','F117'), F068
#('크리스피','F118'), F067
('순살파닭','F119'),
('치킨떡볶이','F120'),

('소고기','F159'),
('소한마리(생고기)','F121'),
('소한마리(주물럭)','F122'),
#('김치말이국수','F123'), F088
('소고기국수','F124'),
('비빔국수','F125'),
('우거지국','F126'),

('볶음밥','F160'),
('돌판삼겹살','F127'),
('돌판닭갈비','F128'),
('돌판제육볶음','F129'),
('돌판날치알밥','F130'),
('돌판힐링볶음밥','F131'),
('돌판소불고기','F132'),

('덮밥','F161'),
('와규덮밥','F133'),
('생연어덮밥','F134'),
#('차슈덮밥','F135'),F042
#('부타동덮밥','F136'), F041
('가츠동덮밥','F137'),
('에비동덮밥','F138'),

('족발','F162'),
('참족발앞다리','F139'),
('불족발앞다리','F140'),
('석쇠구이족발앞다리','F141'),
('반반족발앞다리','F142'),
#('주먹밥','F143'), F099
('메밀전병','F144'),

('돈까스', 'F163'),
('김치치즈돈까스', 'F164'),
('간사이 오뎅나베', 'F165'),
('크림 나베', 'F166'),
('묵은지 돈까스', 'F167'),
('우동', 'F147'),

('라멘', 'F149'),
('마제멘', 'F168'),
('차슈동', 'F042'),
('카라구치라멘', 'F169'),
('미소라멘', 'F170'),
('어개라멘', 'F171'),

('부타동', 'F041'),
('라멘', 'F149'),
('돈코치라멘', 'F172'),
('츠케멘', 'F173'),
('차슈동', 'F042'),
('특차슈동', 'F174'),

('돈까스', 'F163'),
('히레돈까스', 'F175'),
('고구마돈까스', 'F176'),
('가츠동', 'F177'),
('냉모밀', 'F178'),
('에비동', 'F179'),

('떡볶이', 'F180'),
('해물떡볶이', 'F181'),
('치즈떡볶이', 'F182'),
('모듬떡볶이', 'F183'),
('치즈라면', 'F184'),
('볶음밥', 'F160'),


('김치찌개', 'F098'),
('참치찌개', 'F185'),
('알밥', 'F155'),
('제육볶음', 'F106'),
('부대찌개', 'F097'),
('갈비탕', 'F186'),

('짜장면', 'F073'),
('짬뽕', 'F074'),
('차돌박이 짬뽕', 'F187'),
('탕수육', 'F188'),
('볶음밥', 'F160'),
('꿔바로우', 'F189'),


('짬뽕', 'F074'),
('삼선볶음짬뽕', 'F190'),
('탕수육', 'F188'),
('짜장면', 'F073'),
('깐쇼새우', 'F191'),
('팔보채', 'F192'),



('프렌치 토스트', 'F193'),
('팬케이크', 'F194'),
('메리 팬케이크', 'F195'),
('타르트', 'F196'),
('다크 쇼콜라', 'F197'),
('팥빙수', 'F198'),


('푸팟퐁커리', 'F199'),
('파타이꿍', 'F200'),
('볶음밥', 'F201'),
('팟씨유꿍', 'F202'),
('파오무삽', 'F203'),
('똠양꿍', 'F204'),


('스테이크', 'F146'),
('연어 스테이크', 'F205'),
('등심 스테이크', 'F206'),
('슈바인골드 스테이크', 'F207'),
('열무소면', 'F208'),
('연어 샐러드', 'F209'),


('스테이크', 'F146'),
('리코타 샐러드', 'F210'),
('피자', 'F211'),
('리코타 피자', 'F212'),
('봉골레파스타', 'F213'),
('리조또', 'F214'),

('시금치 포카치아', 'F215'),
('바베큐 포카치아', 'F216'),
('샐러드', 'F217'),
('봉골레파스타', 'F213'),
('연어 샐러드', 'F209'),
('까르보나라', 'F218'),



('우동', 'F147'),
('도끼정 잔칫상', 'F219'),
('돈데끼', 'F220'),
('숯불구이 반반', 'F221'),
('스테이크', 'F146'),
('카레나베', 'F222'),


('스테이크', 'F146'),
('치킨샐러드', 'F223'),
('라자냐', 'F224'),
('빠네파스타', 'F225'),
('해산물 로제 파스타', 'F226'),
('필라프', 'F227'),

('오징어구이밥', 'F228'),
('리조또', 'F214'),
('봉골레파스타', 'F213'),
('까르보나라', 'F218'),
('소고기미트볼과 감자튀김', 'F229'),
('스테이크', 'F146'),

('불고기', 'F230'),
('시래기 나물밥', 'F231'),
('양념불고기나물밥', 'F232'),
('된장전골불고기', 'F233'),
('김치찌개', 'F098'),
('볶음밥', 'F160'),


('스테이크', 'F146'),
('치킨 스테이크', 'F234'),
('리조또', 'F214'),
('마르게리따', 'F235'),
('루꼴라 샐러드', 'F236'),
('필라프', 'F227'),

('마르게리따', 'F235'),
('리조또', 'F214'),
('고르곤졸라', 'F237'),
('알리오 올리오', 'F238'),
('까르보나라', 'F218'),
('필라프', 'F227'),

('샐러드', 'F217'),
('해산물 샐러드', 'F239'),
('얌운센', 'F240'),
('남똑무', 'F241'),
('치킨', 'F154'),
('볶음밥', 'F160'),

('꽃방', 'F242'),
('깐풍기', 'F243'),
('찹쌀탕수육', 'F076'),
('유산슬', 'F244'),
('볶음밥', 'F160'),
('짜장면', 'F073'),

('불고기', 'F230'),
('보쌈', 'F245'),
('숯불 돼지불고기', 'F246'),
('오리고기', 'F247'),
('묵사발 정식', 'F248'),
('정식', 'F249')



#('돌판힐링볶음밥','F145'),
#('돌판힐링볶음밥','F146'),
#('돌판힐링볶음밥','F147'),
#('돌판힐링볶음밥','F148'),
#('돌판힐링볶음밥','F149'),
#('돌판힐링볶음밥','F150')

]

DATA_TABLES['FOOD_TYPE'] = [ 
('한식',        'T001'),
('일식',        'T002'),
('중식',        'T003'),
('양식',        'T004'),
('술집',        'T005'),
('기타',        'T006')
]

DATA_TABLES['COOKED_BY'] = [ 
('F001',        'R001'),
('F002',        'R001'),
('F003',        'R001'),
('F004',        'R001'),
('F005',        'R001'),
('F006',        'R001'),

('F007',        'R002'),
('F008',        'R002'),
('F009',        'R002'),
('F010',        'R002'),
('F011',        'R002'),
('F012',        'R002'),

('F013',        'R003'),
('F014',        'R003'),
('F015',        'R003'),
('F016',        'R003'),
('F017',        'R003'),
('F018',        'R003'),

('F019',        'R004'),
('F020',        'R004'),
('F021',        'R004'),
('F022',        'R004'),
('F023',        'R004'),
('F024',        'R004'),

('F025',        'R005'),
('F026',        'R005'),
('F027',        'R005'),
('F028',        'R005'),
('F029',        'R005'),
('F030',        'R005'),

('F031',        'R006'),
('F032',        'R006'),
('F033',        'R006'),
('F034',        'R006'),
('F035',        'R006'),
('F036',        'R006'),

('F037',        'R007'),
('F038',        'R007'),
('F039',        'R007'),
('F040',        'R007'),
('F041',        'R007'),
('F042',        'R007'),

('F043',        'R008'),
('F044',        'R008'),
('F045',        'R008'),
('F046',        'R008'),
('F047',        'R008'),
('F048',        'R008'),

('F049',        'R009'),
('F050',        'R009'),
('F051',        'R009'),
('F052',        'R009'),
('F053',        'R009'),
('F054',        'R009'),

('F055',        'R010'),
('F056',        'R010'),
('F057',        'R010'),
('F058',        'R010'),
('F059',        'R010'),
('F060',        'R010'),

('F061',        'R011'),
('F062',        'R011'),
('F063',        'R011'),
('F064',        'R011'),
('F065',        'R011'),
('F066',        'R011'),

('F067',        'R012'),
('F068',        'R012'),
('F069',        'R012'),
('F070',        'R012'),
('F071',        'R012'),
('F072',        'R012'),

('F073',        'R013'),
('F074',        'R013'),
('F075',        'R013'),
('F076',        'R013'),
('F077',        'R013'),
('F078',        'R013'),

('F079',        'R014'),
('F080',        'R014'),
('F081',        'R014'),
('F082',        'R014'),
('F083',        'R014'),
('F084',        'R014'),

('F085',        'R015'),
('F086',        'R015'),
('F087',        'R015'),
('F088',        'R015'),
('F089',        'R015'),
('F090',        'R015'),

('F091',        'R016'),
('F092',        'R016'),
('F093',        'R016'),
('F094',        'R016'),
('F095',        'R016'),
('F096',        'R016'),

('F097',        'R017'),
('F098',        'R017'),
('F099',        'R017'),
('F100',        'R017'),
('F101',        'R017'),
('F102',        'R017'),

('F098',        'R018'),
('F104',        'R018'),
('F087',        'R018'),
('F106',        'R018'),
('F107',        'R018'),
('F097',        'R018'),

('F109',        'R019'),
('F110',        'R019'),
('F111',        'R019'),
('F112',        'R019'),
('F113',        'R019'),
('F114',        'R019'),

('F115',        'R020'),
('F116',        'R020'),
('F068',        'R020'),
('F067',        'R020'),
('F119',        'R020'),
('F120',        'R020'),

('F121',        'R021'),
('F122',        'R021'),
('F088',        'R021'),
('F124',        'R021'),
('F125',        'R021'),
('F126',        'R021'),

('F127',        'R022'),
('F128',        'R022'),
('F129',        'R022'),
('F130',        'R022'),
('F131',        'R022'),
('F132',        'R022'),

('F133',        'R023'),
('F134',        'R023'),
('F042',        'R023'),
('F041',        'R023'),
('F137',        'R023'),
('F138',        'R023'),

('F139',        'R024'),
('F140',        'R024'),
('F141',        'R024'),
('F142',        'R024'),
('F099',        'R024'),
('F144',        'R024'),

('F145',        'R001'),
('F146',        'R002'),
('F146',        'R006'),
('F147',        'R003'),

('F148',        'R004'),
('F148',        'R005'),

('F149',        'R007'),
('F150',        'R008'),
('F151',        'R009'),

('F152',        'R010'),
('F153',        'R011'),
('F154',        'R012'),
('F154',        'R020'),

('F155',        'R014'),
('F156',        'R015'),
('F157',        'R016'),
('F158',        'R019'),
('F159',        'R021'),
('F160',        'R022'),
('F161',        'R023'),
('F162',        'R024'),

('F163',        'R025'),
('F164',      'R025'),
('F165',      'R025'),
('F166',      'R025'),
('F167',      'R025'),
('F147',      'R025'),


('F149',      'R026'),
('F168',      'R026'),
('F042',      'R026'),
('F169',      'R026'),
('F170',      'R026'),
('F171',      'R026'),


('F041',      'R027'),
('F149',      'R027'),
('F172',      'R027'),
('F173',      'R027'),
('F042',      'R027'),
('F174',      'R027'),


('F163',      'R028'),
('F175',      'R028'),
('F176',      'R028'),
('F177',      'R028'),
('F178',      'R028'),
('F179',      'R028'),


('F180',      'R029'),
('F181',      'R029'),
('F182',      'R029'),
('F183',      'R029'),
('F184',      'R029'),
('F160',      'R029'),


('F098',      'R030'),
('F185',      'R030'),
('F155',      'R030'),
('F106',      'R030'),
('F097',      'R030'),
('F186',      'R030'),


('F073',      'R031'),
('F074',      'R031'),
('F187',      'R031'),
('F188',      'R031'),
('F160',      'R031'),
('F189',      'R031'),


('F074',      'R032'),
('F190',      'R032'),
('F188',      'R032'),
('F073',      'R032'),
('F191',      'R032'),
('F192',      'R032'),

('F193',      'R033'),
('F194',      'R033'),
('F195',      'R033'),
('F196',      'R033'),
('F197',      'R033'),
('F198',      'R033'),

('F199',      'R034'),
('F200',      'R034'),
('F201',      'R034'),
('F202',      'R034'),
('F203',      'R034'),
('F204',      'R034'),

('F146',      'R035'),
('F205',      'R035'),
('F206',      'R035'),
('F207',      'R035'),
('F208',      'R035'),
('F209',      'R035'),

('F146',      'R036'),
('F210',      'R036'),
('F211',      'R036'),
('F212',      'R036'),
('F213',      'R036'),
('F214',      'R036'),

('F215',      'R037'),
('F216',      'R037'),
('F217',      'R037'),
('F213',      'R037'),
('F209',      'R037'),
('F218',      'R037'),


('F147',      'R038'),
('F219',      'R038'),
('F220',      'R038'),
('F221',      'R038'),
('F146',      'R038'),
('F222',      'R038'),


('F146',      'R039'),
('F223',      'R039'),
('F224',      'R039'),
('F225',      'R039'),
('F226',      'R039'),
('F227',      'R039'),

('F228',      'R040'),
('F214',      'R040'),
('F213',      'R040'),
('F218',      'R040'),
('F229',      'R040'),
('F146',      'R040'),

('F230',      'R041'),
('F231',      'R041'),
('F232',      'R041'),
('F233',      'R041'),
('F098',      'R041'),
('F160',      'R041'),

('F146',      'R042'),
('F234',      'R042'),
('F214',      'R042'),
('F235',      'R042'),
('F236',      'R042'),
('F227',      'R042'),

('F235',      'R043'),
('F214',      'R043'),
('F237',      'R043'),
('F238',      'R043'),
('F218',      'R043'),
('F227',      'R043'),

('F217',      'R044'),
('F239',      'R044'),
('F240',      'R044'),
('F241',      'R044'),
('F154',      'R044'),
('F160',      'R044'),

('F242',      'R045'),
('F243',      'R045'),
('F076',      'R045'),
('F244',      'R045'),
('F160',      'R045'),
('F073',      'R045'),

('F230',      'R046'),
('F245',      'R046'),
('F246',      'R046'),
('F247',      'R046'),
('F248',      'R046'),
('F249',      'R046')



]

#한식:T001 일식:T002  중식:T003  양식:T004  술집:T005  기타:T006
DATA_TABLES['RESTAURANT'] = [ #20ea
('고씨네',       'R001','T002','https://store.naver.com/restaurants/detail?id=37269016','6000~9500'),
('모모스테이크',  'R002','T004','https://store.naver.com/restaurants/detail?id=36412392','8500~16000'),
('천애부',       'R003','T002','https://m.store.naver.com/restaurants/detail?id=33875226','2000~9500'),
('일미닭갈비',    'R004','T001','https://m.store.naver.com/restaurants/detail?id=38485469','6900~14000'),
('유가네닭갈비',  'R005','T001','https://m.store.naver.com/restaurants/detail?id=21102801','4500~28000'),
('Mr.Chef Pocha','R006','T004','https://m.store.naver.com/restaurants/detail?id=21278958','9500~50000'),
('멘야고이치',    'R007','T002','https://m.store.naver.com/restaurants/detail?id=20322446','6500~7500'),
('밀플랜비',      'R008','T006','https://m.store.naver.com/restaurants/detail?id=38009073','3000~6000'),
('Mr.chef',      'R009','T001','https://m.store.naver.com/restaurants/detail?id=30811729','5500~8000'),
('봉구스밥버거',  'R010','T001','https://m.store.naver.com/restaurants/detail?id=31077787','1800~3500'),
('미스사이공',    'R011','T006','https://m.store.naver.com/restaurants/detail?id=38762477','3900~4900'),
('도담도담치킨',  'R012','T006','https://m.store.naver.com/restaurants/detail?id=36655478&entry=plt','15000~16000'),
('뽕스토리',      'R013','T003','https://m.store.naver.com/restaurants/detail?id=342201261','4500~35000'),
('알촌',          'R014','T001','https://m.store.naver.com/restaurants/detail?id=32848717','3500~4800'),
('벌집삼겹살',     'R015','T001','https://m.store.naver.com/restaurants/detail?id=19438153','3500~11900'),
('내가찜한닭',     'R016','T001','https://m.store.naver.com/restaurants/detail?id=33471257','17000~39000'),
('맛구단',         'R017','T001','https://m.search.naver.com/search.naver?where=m&sm=mtb_jum','2000~22000'),
('찌개백반',       'R018','T001','https://m.store.naver.com/restaurants/detail?id=18226632','5000~8000'),
('서울곱창',       'R019','T001','https://m.store.naver.com/restaurants/detail?id=18227763','17000~50000'),
('전설의치킨',     'R020','T001','https://m.store.naver.com/restaurants/detail?id=37811564','11000~1400'),
('반값소',         'R021','T001','https://m.store.naver.com/restaurants/detail?id=37592424','3000~39000'),
('푸드테라피',    'R022','T001','https://m.store.naver.com/restaurants/detail?id=33133453','5000~7000'),
('만고쿠',         'R023','T002','https://m.store.naver.com/restaurants/detail?id=37342139','4000~8000'),
('우만동족발집',    'R024','T001','https://m.store.naver.com/restaurants/detail?id=36424455','3000~36000'),
('소고',    'R025','T002','https://m.store.naver.com/restaurants/detail?id=35657866','9500~13000'),
('멘야고코로',    'R026','T002','https://m.store.naver.com/restaurants/detail?id=38346358','5900~7500'),
('키와마루아지',    'R027','T002','https://m.store.naver.com/restaurants/detail?id=37162932','9900~14000'),
('도꼬돈카츠',    'R028','T002','https://m.store.naver.com/restaurants/detail?id=33875226','6000~9000'),
('동떡이',    'R029','T001','https://m.store.naver.com/restaurants/detail?id=18242833','1500~6000'),
('시골집',    'R030','T001','https://m.store.naver.com/restaurants/detail?id=13560446','6000~8000'),
('광교반점',   'R031','T003','https://m.store.naver.com/restaurants/detail?id=37269538','5000~15000'),
('현경',     'R032','T003','https://m.store.naver.com/places/detail?id=437262373','8000~22000'),
('카페드로잉',   'R033','T004','https://m.store.naver.com/restaurants/detail?id=36561330','10000~20000'),
('바나나테이블',   'R034','T006','https://m.store.naver.com/restaurants/detail?id=36943345','13000~26000'),

('슈퍼스테이크',    'R035','T004','https://m.store.naver.com/restaurants/detail?id=37341816','6000~18000'),
('소마바이네이쳐',   'R036','T004','https://m.store.naver.com/restaurants/detail?id=36674562','16000~39000'),
('시카고피자',    'R037','T004','https://m.store.naver.com/restaurants/detail?id=37259982','12000~18000'),
('토끼정',    'R038','T001','https://m.store.naver.com/restaurants/detail?id=533097088','9000~14000'),
('갈릭 앤 모어',    'R039','T004','https://m.store.naver.com/restaurants/detail?id=968321089','9000~18000'),
('아날로그치킨',    'R040','T004','https://m.store.naver.com/restaurants/detail?id=37111515','15000~55000'),

('미스터시래기',    'R041','T001','https://m.store.naver.com/restaurants/detail?id=36561053','8000~19000'),
('더플레이스',    'R042','T004','https://m.store.naver.com/restaurants/detail?id=36900565','13000~43000'),
('오이탈리안',    'R043','T004','https://m.store.naver.com/restaurants/detail?id=38641900','7700~8800'),
('생어거스틴',    'R044','T004','https://m.store.naver.com/restaurants/detail?id=36624270','13000~19000'),
('매란방',    'R045','T003','https://m.store.naver.com/restaurants/detail?id=164938685','3000~19000'),
('풍원장',    'R046','T001','https://m.store.naver.com/restaurants/detail?id=37492092','15000~34000')



#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),

]
#data insert----------------------------------------------------------------------------------------------
for name, insert_form in INSERT_TABLES.iteritems():
    try:
        print("Inserting tuples to TABLE({})\n".format(name), end='')
        for data in DATA_TABLES[name]: 
            try:
                cursor.execute(insert_form,data)
            except mysql.connector.Error as err:
                print("{}({})".format(err.msg,name))
    except mysql.connector.Error as err:
        if(err):
            print(err.msg)
        else:
            print("OK")

cursor.execute(enable_foreign) #foreign key constraint check
cnx.commit()


#query----------------------------------------------------------------------------------------------------



#print form----------------------------------------------------------------------------------------------

   
#operation-----------------------------------------------------------------------------------------------

    
#main-----------------------------------------------------------------------------------------------------


cursor.close()
cnx.close()
30e44c387456fc3fd0bdd82dba9d093b7955ffcd
<mask token>

<mask token>
print('DB loading...\n\n')
try:
    cnx = mysql.connector.connect(host=
        'dbdbdeep.co7zvonejcs7.ap-northeast-2.rds.amazonaws.com', user=
        'blcocas', password='201221027', charset='utf8mb4')
    cursor = cnx.cursor()
    print('success to connect')
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print('Something is wrong with your user name or password')
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print('Database does not exist')
    else:
        print(err)


def create_database(cursor):
    try:
        cursor.execute("CREATE DATABASE {} DEFAULT CHARACTER SET 'utf8'".
            format(DB_NAME))
        print('success to creat DB')
    except mysql.connector.Error as err:
        print('Failed creating database: {}'.format(err))
        exit(1)


try:
    cnx.database = DB_NAME
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_BAD_DB_ERROR:
        create_database(cursor)
        cnx.database = DB_NAME
    else:
        print(err)
        exit(1)
<mask token>
cursor.execute(disable_foreign)
for name, ddl in TABLES.iteritems():
    try:
        print('Creating table {}: '.format(name), end='')
        cursor.execute(ddl)
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
            print('already exists.')
        else:
            print(err.msg)
    else:
        print('OK')
<mask token>
for name, insert_form in INSERT_TABLES.iteritems():
    try:
        print('Inserting tuples to TABLE({})\n'.format(name), end='')
        for data in DATA_TABLES[name]:
            try:
                cursor.execute(insert_form, data)
            except mysql.connector.Error as err:
                print('{}({})'.format(err.msg, name))
    except mysql.connector.Error as err:
        if err:
            print(err.msg)
        else:
            print('OK')
cursor.execute(enable_foreign)
cnx.commit()
cursor.close()
cnx.close()

<mask token>
DB_NAME = 'dbdbdeep'
print('DB loading...\n\n')
try:
    cnx = mysql.connector.connect(host=
        'dbdbdeep.co7zvonejcs7.ap-northeast-2.rds.amazonaws.com', user=
        'blcocas', password='201221027', charset='utf8mb4')
    cursor = cnx.cursor()
    print('success to connect')
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print('Something is wrong with your user name or password')
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print('Database does not exist')
    else:
        print(err)


def create_database(cursor):
    try:
        cursor.execute("CREATE DATABASE {} DEFAULT CHARACTER SET 'utf8'".
            format(DB_NAME))
        print('success to creat DB')
    except mysql.connector.Error as err:
        print('Failed creating database: {}'.format(err))
        exit(1)


try:
    cnx.database = DB_NAME
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_BAD_DB_ERROR:
        create_database(cursor)
        cnx.database = DB_NAME
    else:
        print(err)
        exit(1)
TABLES = {}
TABLES['FOOD'] = (
    'CREATE TABLE  `FOOD`(`Food_Name`        varchar(15)     NOT NULL,`Food_Num`         char(8)         NOT NULL,PRIMARY KEY (`Food_Num`)) ENGINE=InnoDB'
    )
TABLES['FOOD_TYPE'] = (
    'CREATE TABLE  `FOOD_TYPE` (`Type_Name`       varchar(15)       NOT NULL,`Type_Num`        char(8)           NOT NULL,PRIMARY KEY (`Type_Num`))ENGINE=InnoDB'
    )
TABLES['COOKED_BY'] = (
    'CREATE TABLE  `COOKED_BY` (`F_Num`        char(8)     NOT NULL,`R_Num`        char(8)     NOT NULL,PRIMARY KEY(`F_Num`, `R_Num`),FOREIGN KEY (`F_Num`) REFERENCES `FOOD`(`Food_Num`),FOREIGN KEY (`R_Num`) REFERENCES `RESTAURANT`(`Rest_Num`))ENGINE=InnoDB'
    )
TABLES['RESTAURANT'] = (
    'CREATE TABLE  RESTAURANT ( `Rest_Name`       varchar(15)     NOT NULL,`Rest_Num`        char(8)     NOT NULL,`T_Num`           char(8)     NOT NULL,`Map`            varchar(100)     ,`Average_Cost`    varchar(15)         ,PRIMARY KEY (`Rest_Num`),FOREIGN KEY (`T_Num`) REFERENCES FOOD_TYPE(`Type_Num`))ENGINE=InnoDB'
    )
disable_foreign = """ 
    SET FOREIGN_KEY_CHECKS = 0;
"""
enable_foreign = """ 
    SET FOREIGN_KEY_CHECKS = 1;
"""
cursor.execute(disable_foreign)
for name, ddl in TABLES.iteritems():
    try:
        print('Creating table {}: '.format(name), end='')
        cursor.execute(ddl)
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
            print('already exists.')
        else:
            print(err.msg)
    else:
        print('OK')
INSERT_TABLES = {}
INSERT_TABLES['FOOD'] = 'INSERT INTO FOOD (Food_Name, Food_Num)VALUES (%s, %s)'
INSERT_TABLES['FOOD_TYPE'
    ] = 'INSERT INTO FOOD_TYPE (Type_Name,Type_Num)VALUES (%s, %s)'
INSERT_TABLES['COOKED_BY'
    ] = 'INSERT INTO COOKED_BY (F_Num,R_Num)VALUES (%s, %s)'
INSERT_TABLES['RESTAURANT'] = (
    'INSERT INTO RESTAURANT (Rest_Name,Rest_Num,T_Num,Map,Average_Cost)VALUES (%s, %s, %s, %s, %s)'
    )
DATA_TABLES = {}
DATA_TABLES['FOOD'] = [('카레', 'F145'), ('고씨네 돈까스 카레', 'F001'), (
    '고씨네 스페셜 카레', 'F002'), ('고씨네 프리미엄 카레', 'F003'), ('돈까스 카레 우동', 'F004'),
    ('버섯 카레 우동', 'F005'), ('버섯 카레', 'F006'), ('스테이크', 'F146'), ('스테이크삼겹정식',
    'F007'), ('스테이크정식(소)', 'F008'), ('삼겹테이크정식(소)', 'F009'), ('안창불고기스테이크정식',
    'F010'), ('목살스테이크볶음밥', 'F011'), ('모듬스테이크정식', 'F012'), ('우동', 'F147'), (
    '김치돈까스나베', 'F013'), ('할라피뇨연어덮밥', 'F014'), ('수제돈까스', 'F015'), ('해물야끼우동',
    'F016'), ('달인냉우동', 'F017'), ('마약냉우동', 'F018'), ('아주세트', 'F019'), (
    '치즈세트', 'F020'), ('치즈더블세트', 'F021'), ('솥뚜껑 해물파전', 'F022'), ('철판 모듬 스페셜',
    'F023'), ('철판 제육 볶음', 'F024'), ('닭갈비', 'F148'), ('닭갈비철판볶음밥', 'F025'), (
    '매운철판볶음밥', 'F026'), ('모듬철판볶음밥', 'F027'), ('유가네닭갈비', 'F028'), ('미소허니퐁닭',
    'F029'), ('해물철판볶음밥', 'F030'), ('그릴 목살 스테이크', 'F031'), ('살치살 소고기 스테이크',
    'F032'), ('핫치킨 꿀치즈 퀘사디아', 'F033'), ('페퍼로니 토마토 퀘사디아', 'F034'), (
    '소고기 감자 스튜', 'F035'), ('모든치즈크래커', 'F036'), ('라멘', 'F149'), ('돈코츠라멘',
    'F037'), ('소유라멘', 'F038'), ('미소라멘', 'F039'), ('규동', 'F040'), ('부타동',
    'F041'), ('차슈동', 'F042'), ('부리또', 'F150'), ('치킨라이스', 'F043'), ('치킨감자',
    'F044'), ('소고기라이스', 'F045'), ('소세지감자', 'F046'), ('새우감자', 'F047'), (
    '핫도그', 'F048'), ('제육볶음', 'F151'), ('해물뚝배기', 'F049'), ('제육두루치기', 'F050'),
    ('참치김치찌개', 'F051'), ('카레덮밥', 'F052'), ('돈까스덮밥', 'F053'), ('곱창순두부찌개',
    'F054'), ('밥버거', 'F152'), ('봉구스밥버거', 'F055'), ('햄치즈밥버거', 'F056'), (
    '치즈제육밥버거', 'F057'), ('청양불고기밥버거', 'F058'), ('소불고기밥버거', 'F059'), (
    '통살돈까스마요밥버거', 'F060'), ('쌀국수', 'F153'), ('소고기 쌀국수', 'F061'), ('닭 쌀국수',
    'F062'), ('사이공 볶음밥', 'F063'), ('사이공 볶음면', 'F064'), ('새우볼', 'F065'), (
    '사이공 딤섬', 'F066'), ('크리스피', 'F067'), ('양념치킨', 'F068'), ('간장', 'F069'),
    ('스위트갈릭', 'F070'), ('스위트버터', 'F071'), ('반반치킨', 'F072'), ('짜장면', 'F073'),
    ('짱뽕', 'F074'), ('삼선짬뽕', 'F075'), ('찹쌀탕수육', 'F076'), ('양꼬치', 'F077'), (
    '군만두', 'F078'), ('알밥', 'F155'), ('순한알밥', 'F079'), ('매콤알밥', 'F080'), (
    '매콤치즈알밥', 'F081'), ('카레알밥', 'F082'), ('갈릭알밥', 'F083'), ('갈립치즈알밥',
    'F084'), ('삼겹살', 'F156'), ('벌집삼겹살', 'F085'), ('돼지왕구이', 'F086'), ('갈비탕',
    'F087'), ('김치말이국수', 'F088'), ('냉면', 'F089'), ('항정살', 'F090'), ('찜닭',
    'F157'), ('고추장찜닭', 'F091'), ('안동찜닭', 'F092'), ('순살안동장찜닭', 'F093'), (
    '순살고추장찜닭', 'F094'), ('치즈순살찜닭중', 'F095'), ('치즈순살찜닭대', 'F096'), ('김치찌개',
    'F098'), ('주먹밥', 'F099'), ('계란말이', 'F100'), ('라면', 'F101'), ('만두',
    'F102'), ('부대찌개', 'F097'), ('육계장', 'F104'), ('제육볶음', 'F106'), ('순두부찌개',
    'F107'), ('곱창', 'F158'), ('양구이', 'F109'), ('대창구이', 'F110'), ('곱창구이',
    'F111'), ('막창구이', 'F112'), ('천엽', 'F113'), ('곱창전골', 'F114'), ('치킨',
    'F154'), ('전설의치킨', 'F115'), ('칠리새우순살', 'F116'), ('순살파닭', 'F119'), (
    '치킨떡볶이', 'F120'), ('소고기', 'F159'), ('소한마리(생고기)', 'F121'), ('소한마리(주물럭)',
    'F122'), ('소고기국수', 'F124'), ('비빔국수', 'F125'), ('우거지국', 'F126'), ('볶음밥',
    'F160'), ('돌판삼겹살', 'F127'), ('돌판닭갈비', 'F128'), ('돌판제육볶음', 'F129'), (
    '돌판날치알밥', 'F130'), ('돌판힐링볶음밥', 'F131'), ('돌판소불고기', 'F132'), ('덮밥',
    'F161'), ('와규덮밥', 'F133'), ('생연어덮밥', 'F134'), ('가츠동덮밥', 'F137'), (
    '에비동덮밥', 'F138'), ('족발', 'F162'), ('참족발앞다리', 'F139'), ('불족발앞다리', 'F140'
    ), ('석쇠구이족발앞다리', 'F141'), ('반반족발앞다리', 'F142'), ('메밀전병', 'F144'), ('돈까스',
    'F163'), ('김치치즈돈까스', 'F164'), ('간사이 오뎅나베', 'F165'), ('크림 나베', 'F166'),
    ('묵은지 돈까스', 'F167'), ('우동', 'F147'), ('라멘', 'F149'), ('마제멘', 'F168'), (
    '차슈동', 'F042'), ('카라구치라멘', 'F169'), ('미소라멘', 'F170'), ('어개라멘', 'F171'),
    ('부타동', 'F041'), ('라멘', 'F149'), ('돈코치라멘', 'F172'), ('츠케멘', 'F173'), (
    '차슈동', 'F042'), ('특차슈동', 'F174'), ('돈까스', 'F163'), ('히레돈까스', 'F175'), (
    '고구마돈까스', 'F176'), ('가츠동', 'F177'), ('냉모밀', 'F178'), ('에비동', 'F179'), (
    '떡볶이', 'F180'), ('해물떡볶이', 'F181'), ('치즈떡볶이', 'F182'), ('모듬떡볶이', 'F183'),
    ('치즈라면', 'F184'), ('볶음밥', 'F160'), ('김치찌개', 'F098'), ('참치찌개', 'F185'),
    ('알밥', 'F155'), ('제육볶음', 'F106'), ('부대찌개', 'F097'), ('갈비탕', 'F186'), (
    '짜장면', 'F073'), ('짬뽕', 'F074'), ('차돌박이 짬뽕', 'F187'), ('탕수육', 'F188'), (
    '볶음밥', 'F160'), ('꿔바로우', 'F189'), ('짬뽕', 'F074'), ('삼선볶음짬뽕', 'F190'), (
    '탕수육', 'F188'), ('짜장면', 'F073'), ('깐쇼새우', 'F191'), ('팔보채', 'F192'), (
    '프렌치 토스트', 'F193'), ('팬케이크', 'F194'), ('메리 팬케이크', 'F195'), ('타르트',
    'F196'), ('다크 쇼콜라', 'F197'), ('팥빙수', 'F198'), ('푸팟퐁커리', 'F199'), (
    '파타이꿍', 'F200'), ('볶음밥', 'F201'), ('팟씨유꿍', 'F202'), ('파오무삽', 'F203'), (
    '똠양꿍', 'F204'), ('스테이크', 'F146'), ('연어 스테이크', 'F205'), ('등심 스테이크',
    'F206'), ('슈바인골드 스테이크', 'F207'), ('열무소면', 'F208'), ('연어 샐러드', 'F209'),
    ('스테이크', 'F146'), ('리코타 샐러드', 'F210'), ('피자', 'F211'), ('리코타 피자',
    'F212'), ('봉골레파스타', 'F213'), ('리조또', 'F214'), ('시금치 포카치아', 'F215'), (
    '바베큐 포카치아', 'F216'), ('샐러드', 'F217'), ('봉골레파스타', 'F213'), ('연어 샐러드',
    'F209'), ('까르보나라', 'F218'), ('우동', 'F147'), ('도끼정 잔칫상', 'F219'), ('돈데끼',
    'F220'), ('숯불구이 반반', 'F221'), ('스테이크', 'F146'), ('카레나베', 'F222'), (
    '스테이크', 'F146'), ('치킨샐러드', 'F223'), ('라자냐', 'F224'), ('빠네파스타', 'F225'),
    ('해산물 로제 파스타', 'F226'), ('필라프', 'F227'), ('오징어구이밥', 'F228'), ('리조또',
    'F214'), ('봉골레파스타', 'F213'), ('까르보나라', 'F218'), ('소고기미트볼과 감자튀김', 'F229'
    ), ('스테이크', 'F146'), ('불고기', 'F230'), ('시래기 나물밥', 'F231'), ('양념불고기나물밥',
    'F232'), ('된장전골불고기', 'F233'), ('김치찌개', 'F098'), ('볶음밥', 'F160'), (
    '스테이크', 'F146'), ('치킨 스테이크', 'F234'), ('리조또', 'F214'), ('마르게리따', 'F235'
    ), ('루꼴라 샐러드', 'F236'), ('필라프', 'F227'), ('마르게리따', 'F235'), ('리조또',
    'F214'), ('고르곤졸라', 'F237'), ('알리오 올리오', 'F238'), ('까르보나라', 'F218'), (
    '필라프', 'F227'), ('샐러드', 'F217'), ('해산물 샐러드', 'F239'), ('얌운센', 'F240'),
    ('남똑무', 'F241'), ('치킨', 'F154'), ('볶음밥', 'F160'), ('꽃방', 'F242'), (
    '깐풍기', 'F243'), ('찹쌀탕수육', 'F076'), ('유산슬', 'F244'), ('볶음밥', 'F160'), (
    '짜장면', 'F073'), ('불고기', 'F230'), ('보쌈', 'F245'), ('숯불 돼지불고기', 'F246'),
    ('오리고기', 'F247'), ('묵사발 정식', 'F248'), ('정식', 'F249')]
DATA_TABLES['FOOD_TYPE'] = [('한식', 'T001'), ('일식', 'T002'), ('중식', 'T003'),
    ('양식', 'T004'), ('술집', 'T005'), ('기타', 'T006')]
DATA_TABLES['COOKED_BY'] = [('F001', 'R001'), ('F002', 'R001'), ('F003',
    'R001'), ('F004', 'R001'), ('F005', 'R001'), ('F006', 'R001'), ('F007',
    'R002'), ('F008', 'R002'), ('F009', 'R002'), ('F010', 'R002'), ('F011',
    'R002'), ('F012', 'R002'), ('F013', 'R003'), ('F014', 'R003'), ('F015',
    'R003'), ('F016', 'R003'), ('F017', 'R003'), ('F018', 'R003'), ('F019',
    'R004'), ('F020', 'R004'), ('F021', 'R004'), ('F022', 'R004'), ('F023',
    'R004'), ('F024', 'R004'), ('F025', 'R005'), ('F026', 'R005'), ('F027',
    'R005'), ('F028', 'R005'), ('F029', 'R005'), ('F030', 'R005'), ('F031',
    'R006'), ('F032', 'R006'), ('F033', 'R006'), ('F034', 'R006'), ('F035',
    'R006'), ('F036', 'R006'), ('F037', 'R007'), ('F038', 'R007'), ('F039',
    'R007'), ('F040', 'R007'), ('F041', 'R007'), ('F042', 'R007'), ('F043',
    'R008'), ('F044', 'R008'), ('F045', 'R008'), ('F046', 'R008'), ('F047',
    'R008'), ('F048', 'R008'), ('F049', 'R009'), ('F050', 'R009'), ('F051',
    'R009'), ('F052', 'R009'), ('F053', 'R009'), ('F054', 'R009'), ('F055',
    'R010'), ('F056', 'R010'), ('F057', 'R010'), ('F058', 'R010'), ('F059',
    'R010'), ('F060', 'R010'), ('F061', 'R011'), ('F062', 'R011'), ('F063',
    'R011'), ('F064', 'R011'), ('F065', 'R011'), ('F066', 'R011'), ('F067',
    'R012'), ('F068', 'R012'), ('F069', 'R012'), ('F070', 'R012'), ('F071',
    'R012'), ('F072', 'R012'), ('F073', 'R013'), ('F074', 'R013'), ('F075',
    'R013'), ('F076', 'R013'), ('F077', 'R013'), ('F078', 'R013'), ('F079',
    'R014'), ('F080', 'R014'), ('F081', 'R014'), ('F082', 'R014'), ('F083',
    'R014'), ('F084', 'R014'), ('F085', 'R015'), ('F086', 'R015'), ('F087',
    'R015'), ('F088', 'R015'), ('F089', 'R015'), ('F090', 'R015'), ('F091',
    'R016'), ('F092', 'R016'), ('F093', 'R016'), ('F094', 'R016'), ('F095',
    'R016'), ('F096', 'R016'), ('F097', 'R017'), ('F098', 'R017'), ('F099',
    'R017'), ('F100', 'R017'), ('F101', 'R017'), ('F102', 'R017'), ('F098',
    'R018'), ('F104', 'R018'), ('F087', 'R018'), ('F106', 'R018'), ('F107',
    'R018'), ('F097', 'R018'), ('F109', 'R019'), ('F110', 'R019'), ('F111',
    'R019'), ('F112', 'R019'), ('F113', 'R019'), ('F114', 'R019'), ('F115',
    'R020'), ('F116', 'R020'), ('F068', 'R020'), ('F067', 'R020'), ('F119',
    'R020'), ('F120', 'R020'), ('F121', 'R021'), ('F122', 'R021'), ('F088',
    'R021'), ('F124', 'R021'), ('F125', 'R021'), ('F126', 'R021'), ('F127',
    'R022'), ('F128', 'R022'), ('F129', 'R022'), ('F130', 'R022'), ('F131',
    'R022'), ('F132', 'R022'), ('F133', 'R023'), ('F134', 'R023'), ('F042',
    'R023'), ('F041', 'R023'), ('F137', 'R023'), ('F138', 'R023'), ('F139',
    'R024'), ('F140', 'R024'), ('F141', 'R024'), ('F142', 'R024'), ('F099',
    'R024'), ('F144', 'R024'), ('F145', 'R001'), ('F146', 'R002'), ('F146',
    'R006'), ('F147', 'R003'), ('F148', 'R004'), ('F148', 'R005'), ('F149',
    'R007'), ('F150', 'R008'), ('F151', 'R009'), ('F152', 'R010'), ('F153',
    'R011'), ('F154', 'R012'), ('F154', 'R020'), ('F155', 'R014'), ('F156',
    'R015'), ('F157', 'R016'), ('F158', 'R019'), ('F159', 'R021'), ('F160',
    'R022'), ('F161', 'R023'), ('F162', 'R024'), ('F163', 'R025'), ('F164',
    'R025'), ('F165', 'R025'), ('F166', 'R025'), ('F167', 'R025'), ('F147',
    'R025'), ('F149', 'R026'), ('F168', 'R026'), ('F042', 'R026'), ('F169',
    'R026'), ('F170', 'R026'), ('F171', 'R026'), ('F041', 'R027'), ('F149',
    'R027'), ('F172', 'R027'), ('F173', 'R027'), ('F042', 'R027'), ('F174',
    'R027'), ('F163', 'R028'), ('F175', 'R028'), ('F176', 'R028'), ('F177',
    'R028'), ('F178', 'R028'), ('F179', 'R028'), ('F180', 'R029'), ('F181',
    'R029'), ('F182', 'R029'), ('F183', 'R029'), ('F184', 'R029'), ('F160',
    'R029'), ('F098', 'R030'), ('F185', 'R030'), ('F155', 'R030'), ('F106',
    'R030'), ('F097', 'R030'), ('F186', 'R030'), ('F073', 'R031'), ('F074',
    'R031'), ('F187', 'R031'), ('F188', 'R031'), ('F160', 'R031'), ('F189',
    'R031'), ('F074', 'R032'), ('F190', 'R032'), ('F188', 'R032'), ('F073',
    'R032'), ('F191', 'R032'), ('F192', 'R032'), ('F193', 'R033'), ('F194',
    'R033'), ('F195', 'R033'), ('F196', 'R033'), ('F197', 'R033'), ('F198',
    'R033'), ('F199', 'R034'), ('F200', 'R034'), ('F201', 'R034'), ('F202',
    'R034'), ('F203', 'R034'), ('F204', 'R034'), ('F146', 'R035'), ('F205',
    'R035'), ('F206', 'R035'), ('F207', 'R035'), ('F208', 'R035'), ('F209',
    'R035'), ('F146', 'R036'), ('F210', 'R036'), ('F211', 'R036'), ('F212',
    'R036'), ('F213', 'R036'), ('F214', 'R036'), ('F215', 'R037'), ('F216',
    'R037'), ('F217', 'R037'), ('F213', 'R037'), ('F209', 'R037'), ('F218',
    'R037'), ('F147', 'R038'), ('F219', 'R038'), ('F220', 'R038'), ('F221',
    'R038'), ('F146', 'R038'), ('F222', 'R038'), ('F146', 'R039'), ('F223',
    'R039'), ('F224', 'R039'), ('F225', 'R039'), ('F226', 'R039'), ('F227',
    'R039'), ('F228', 'R040'), ('F214', 'R040'), ('F213', 'R040'), ('F218',
    'R040'), ('F229', 'R040'), ('F146', 'R040'), ('F230', 'R041'), ('F231',
    'R041'), ('F232', 'R041'), ('F233', 'R041'), ('F098', 'R041'), ('F160',
    'R041'), ('F146', 'R042'), ('F234', 'R042'), ('F214', 'R042'), ('F235',
    'R042'), ('F236', 'R042'), ('F227', 'R042'), ('F235', 'R043'), ('F214',
    'R043'), ('F237', 'R043'), ('F238', 'R043'), ('F218', 'R043'), ('F227',
    'R043'), ('F217', 'R044'), ('F239', 'R044'), ('F240', 'R044'), ('F241',
    'R044'), ('F154', 'R044'), ('F160', 'R044'), ('F242', 'R045'), ('F243',
    'R045'), ('F076', 'R045'), ('F244', 'R045'), ('F160', 'R045'), ('F073',
    'R045'), ('F230', 'R046'), ('F245', 'R046'), ('F246', 'R046'), ('F247',
    'R046'), ('F248', 'R046'), ('F249', 'R046')]
DATA_TABLES['RESTAURANT'] = [('고씨네', 'R001', 'T002',
    'https://store.naver.com/restaurants/detail?id=37269016', '6000~9500'),
    ('모모스테이크', 'R002', 'T004',
    'https://store.naver.com/restaurants/detail?id=36412392', '8500~16000'),
    ('천애부', 'R003', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=33875226', '2000~9500'
    ), ('일미닭갈비', 'R004', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=38485469',
    '6900~14000'), ('유가네닭갈비', 'R005', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=21102801',
    '4500~28000'), ('Mr.Chef Pocha', 'R006', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=21278958',
    '9500~50000'), ('멘야고이치', 'R007', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=20322446', '6500~7500'
    ), ('밀플랜비', 'R008', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=38009073', '3000~6000'
    ), ('Mr.chef', 'R009', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=30811729', '5500~8000'
    ), ('봉구스밥버거', 'R010', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=31077787', '1800~3500'
    ), ('미스사이공', 'R011', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=38762477', '3900~4900'
    ), ('도담도담치킨', 'R012', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=36655478&entry=plt',
    '15000~16000'), ('뽕스토리', 'R013', 'T003',
    'https://m.store.naver.com/restaurants/detail?id=342201261',
    '4500~35000'), ('알촌', 'R014', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=32848717', '3500~4800'
    ), ('벌집삼겹살', 'R015', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=19438153',
    '3500~11900'), ('내가찜한닭', 'R016', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=33471257',
    '17000~39000'), ('맛구단', 'R017', 'T001',
    'https://m.search.naver.com/search.naver?where=m&sm=mtb_jum',
    '2000~22000'), ('찌개백반', 'R018', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=18226632', '5000~8000'
    ), ('서울곱창', 'R019', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=18227763',
    '17000~50000'), ('전설의치킨', 'R020', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=37811564',
    '11000~1400'), ('반값소', 'R021', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=37592424',
    '3000~39000'), ('푸드테라피', 'R022', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=33133453', '5000~7000'
    ), ('만고쿠', 'R023', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=37342139', '4000~8000'
    ), ('우만동족발집', 'R024', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=36424455',
    '3000~36000'), ('소고', 'R025', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=35657866',
    '9500~13000'), ('멘야고코로', 'R026', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=38346358', '5900~7500'
    ), ('키와마루아지', 'R027', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=37162932',
    '9900~14000'), ('도꼬돈카츠', 'R028', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=33875226', '6000~9000'
    ), ('동떡이', 'R029', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=18242833', '1500~6000'
    ), ('시골집', 'R030', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=13560446', '6000~8000'
    ), ('광교반점', 'R031', 'T003',
    'https://m.store.naver.com/restaurants/detail?id=37269538',
    '5000~15000'), ('현경', 'R032', 'T003',
    'https://m.store.naver.com/places/detail?id=437262373', '8000~22000'),
    ('카페드로잉', 'R033', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36561330',
    '10000~20000'), ('바나나테이블', 'R034', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=36943345',
    '13000~26000'), ('슈퍼스테이크', 'R035', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=37341816',
    '6000~18000'), ('소마바이네이쳐', 'R036', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36674562',
    '16000~39000'), ('시카고피자', 'R037', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=37259982',
    '12000~18000'), ('토끼정', 'R038', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=533097088',
    '9000~14000'), ('갈릭 앤 모어', 'R039', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=968321089',
    '9000~18000'), ('아날로그치킨', 'R040', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=37111515',
    '15000~55000'), ('미스터시래기', 'R041', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=36561053',
    '8000~19000'), ('더플레이스', 'R042', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36900565',
    '13000~43000'), ('오이탈리안', 'R043', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=38641900', '7700~8800'
    ), ('생어거스틴', 'R044', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36624270',
    '13000~19000'), ('매란방', 'R045', 'T003',
    'https://m.store.naver.com/restaurants/detail?id=164938685',
    '3000~19000'), ('풍원장', 'R046', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=37492092', '15000~34000')]
for name, insert_form in INSERT_TABLES.iteritems():
    try:
        print('Inserting tuples to TABLE({})\n'.format(name), end='')
        for data in DATA_TABLES[name]:
            try:
                cursor.execute(insert_form, data)
            except mysql.connector.Error as err:
                print('{}({})'.format(err.msg, name))
    except mysql.connector.Error as err:
        if err:
            print(err.msg)
        else:
            print('OK')
cursor.execute(enable_foreign)
cnx.commit()
cursor.close()
cnx.close()

from __future__ import print_function
from datetime import date, datetime, timedelta
import mysql.connector
import os
from mysql.connector import errorcode
DB_NAME = 'dbdbdeep'
print('DB loading...\n\n')
try:
    cnx = mysql.connector.connect(host=
        'dbdbdeep.co7zvonejcs7.ap-northeast-2.rds.amazonaws.com', user=
        'blcocas', password='201221027', charset='utf8mb4')
    cursor = cnx.cursor()
    print('success to connect')
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print('Something is wrong with your user name or password')
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print('Database does not exist')
    else:
        print(err)


def create_database(cursor):
    try:
        cursor.execute("CREATE DATABASE {} DEFAULT CHARACTER SET 'utf8'".
            format(DB_NAME))
        print('success to creat DB')
    except mysql.connector.Error as err:
        print('Failed creating database: {}'.format(err))
        exit(1)


try:
    cnx.database = DB_NAME
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_BAD_DB_ERROR:
        create_database(cursor)
        cnx.database = DB_NAME
    else:
        print(err)
        exit(1)
TABLES = {}
TABLES['FOOD'] = (
    'CREATE TABLE  `FOOD`(`Food_Name`        varchar(15)     NOT NULL,`Food_Num`         char(8)         NOT NULL,PRIMARY KEY (`Food_Num`)) ENGINE=InnoDB'
    )
TABLES['FOOD_TYPE'] = (
    'CREATE TABLE  `FOOD_TYPE` (`Type_Name`       varchar(15)       NOT NULL,`Type_Num`        char(8)           NOT NULL,PRIMARY KEY (`Type_Num`))ENGINE=InnoDB'
    )
TABLES['COOKED_BY'] = (
    'CREATE TABLE  `COOKED_BY` (`F_Num`        char(8)     NOT NULL,`R_Num`        char(8)     NOT NULL,PRIMARY KEY(`F_Num`, `R_Num`),FOREIGN KEY (`F_Num`) REFERENCES `FOOD`(`Food_Num`),FOREIGN KEY (`R_Num`) REFERENCES `RESTAURANT`(`Rest_Num`))ENGINE=InnoDB'
    )
TABLES['RESTAURANT'] = (
    'CREATE TABLE  RESTAURANT ( `Rest_Name`       varchar(15)     NOT NULL,`Rest_Num`        char(8)     NOT NULL,`T_Num`           char(8)     NOT NULL,`Map`            varchar(100)     ,`Average_Cost`    varchar(15)         ,PRIMARY KEY (`Rest_Num`),FOREIGN KEY (`T_Num`) REFERENCES FOOD_TYPE(`Type_Num`))ENGINE=InnoDB'
    )
disable_foreign = """ 
    SET FOREIGN_KEY_CHECKS = 0;
"""
enable_foreign = """ 
    SET FOREIGN_KEY_CHECKS = 1;
"""
cursor.execute(disable_foreign)
for name, ddl in TABLES.iteritems():
    try:
        print('Creating table {}: '.format(name), end='')
        cursor.execute(ddl)
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
            print('already exists.')
        else:
            print(err.msg)
    else:
        print('OK')
INSERT_TABLES = {}
INSERT_TABLES['FOOD'] = 'INSERT INTO FOOD (Food_Name, Food_Num)VALUES (%s, %s)'
INSERT_TABLES['FOOD_TYPE'
    ] = 'INSERT INTO FOOD_TYPE (Type_Name,Type_Num)VALUES (%s, %s)'
INSERT_TABLES['COOKED_BY'
    ] = 'INSERT INTO COOKED_BY (F_Num,R_Num)VALUES (%s, %s)'
INSERT_TABLES['RESTAURANT'] = (
    'INSERT INTO RESTAURANT (Rest_Name,Rest_Num,T_Num,Map,Average_Cost)VALUES (%s, %s, %s, %s, %s)'
    )
DATA_TABLES = {}
DATA_TABLES['FOOD'] = [('카레', 'F145'), ('고씨네 돈까스 카레', 'F001'), (
    '고씨네 스페셜 카레', 'F002'), ('고씨네 프리미엄 카레', 'F003'), ('돈까스 카레 우동', 'F004'),
    ('버섯 카레 우동', 'F005'), ('버섯 카레', 'F006'), ('스테이크', 'F146'), ('스테이크삼겹정식',
    'F007'), ('스테이크정식(소)', 'F008'), ('삼겹테이크정식(소)', 'F009'), ('안창불고기스테이크정식',
    'F010'), ('목살스테이크볶음밥', 'F011'), ('모듬스테이크정식', 'F012'), ('우동', 'F147'), (
    '김치돈까스나베', 'F013'), ('할라피뇨연어덮밥', 'F014'), ('수제돈까스', 'F015'), ('해물야끼우동',
    'F016'), ('달인냉우동', 'F017'), ('마약냉우동', 'F018'), ('아주세트', 'F019'), (
    '치즈세트', 'F020'), ('치즈더블세트', 'F021'), ('솥뚜껑 해물파전', 'F022'), ('철판 모듬 스페셜',
    'F023'), ('철판 제육 볶음', 'F024'), ('닭갈비', 'F148'), ('닭갈비철판볶음밥', 'F025'), (
    '매운철판볶음밥', 'F026'), ('모듬철판볶음밥', 'F027'), ('유가네닭갈비', 'F028'), ('미소허니퐁닭',
    'F029'), ('해물철판볶음밥', 'F030'), ('그릴 목살 스테이크', 'F031'), ('살치살 소고기 스테이크',
    'F032'), ('핫치킨 꿀치즈 퀘사디아', 'F033'), ('페퍼로니 토마토 퀘사디아', 'F034'), (
    '소고기 감자 스튜', 'F035'), ('모든치즈크래커', 'F036'), ('라멘', 'F149'), ('돈코츠라멘',
    'F037'), ('소유라멘', 'F038'), ('미소라멘', 'F039'), ('규동', 'F040'), ('부타동',
    'F041'), ('차슈동', 'F042'), ('부리또', 'F150'), ('치킨라이스', 'F043'), ('치킨감자',
    'F044'), ('소고기라이스', 'F045'), ('소세지감자', 'F046'), ('새우감자', 'F047'), (
    '핫도그', 'F048'), ('제육볶음', 'F151'), ('해물뚝배기', 'F049'), ('제육두루치기', 'F050'),
    ('참치김치찌개', 'F051'), ('카레덮밥', 'F052'), ('돈까스덮밥', 'F053'), ('곱창순두부찌개',
    'F054'), ('밥버거', 'F152'), ('봉구스밥버거', 'F055'), ('햄치즈밥버거', 'F056'), (
    '치즈제육밥버거', 'F057'), ('청양불고기밥버거', 'F058'), ('소불고기밥버거', 'F059'), (
    '통살돈까스마요밥버거', 'F060'), ('쌀국수', 'F153'), ('소고기 쌀국수', 'F061'), ('닭 쌀국수',
    'F062'), ('사이공 볶음밥', 'F063'), ('사이공 볶음면', 'F064'), ('새우볼', 'F065'), (
    '사이공 딤섬', 'F066'), ('크리스피', 'F067'), ('양념치킨', 'F068'), ('간장', 'F069'),
    ('스위트갈릭', 'F070'), ('스위트버터', 'F071'), ('반반치킨', 'F072'), ('짜장면', 'F073'),
    ('짱뽕', 'F074'), ('삼선짬뽕', 'F075'), ('찹쌀탕수육', 'F076'), ('양꼬치', 'F077'), (
    '군만두', 'F078'), ('알밥', 'F155'), ('순한알밥', 'F079'), ('매콤알밥', 'F080'), (
    '매콤치즈알밥', 'F081'), ('카레알밥', 'F082'), ('갈릭알밥', 'F083'), ('갈립치즈알밥',
    'F084'), ('삼겹살', 'F156'), ('벌집삼겹살', 'F085'), ('돼지왕구이', 'F086'), ('갈비탕',
    'F087'), ('김치말이국수', 'F088'), ('냉면', 'F089'), ('항정살', 'F090'), ('찜닭',
    'F157'), ('고추장찜닭', 'F091'), ('안동찜닭', 'F092'), ('순살안동장찜닭', 'F093'), (
    '순살고추장찜닭', 'F094'), ('치즈순살찜닭중', 'F095'), ('치즈순살찜닭대', 'F096'), ('김치찌개',
    'F098'), ('주먹밥', 'F099'), ('계란말이', 'F100'), ('라면', 'F101'), ('만두',
    'F102'), ('부대찌개', 'F097'), ('육계장', 'F104'), ('제육볶음', 'F106'), ('순두부찌개',
    'F107'), ('곱창', 'F158'), ('양구이', 'F109'), ('대창구이', 'F110'), ('곱창구이',
    'F111'), ('막창구이', 'F112'), ('천엽', 'F113'), ('곱창전골', 'F114'), ('치킨',
    'F154'), ('전설의치킨', 'F115'), ('칠리새우순살', 'F116'), ('순살파닭', 'F119'), (
    '치킨떡볶이', 'F120'), ('소고기', 'F159'), ('소한마리(생고기)', 'F121'), ('소한마리(주물럭)',
    'F122'), ('소고기국수', 'F124'), ('비빔국수', 'F125'), ('우거지국', 'F126'), ('볶음밥',
    'F160'), ('돌판삼겹살', 'F127'), ('돌판닭갈비', 'F128'), ('돌판제육볶음', 'F129'), (
    '돌판날치알밥', 'F130'), ('돌판힐링볶음밥', 'F131'), ('돌판소불고기', 'F132'), ('덮밥',
    'F161'), ('와규덮밥', 'F133'), ('생연어덮밥', 'F134'), ('가츠동덮밥', 'F137'), (
    '에비동덮밥', 'F138'), ('족발', 'F162'), ('참족발앞다리', 'F139'), ('불족발앞다리', 'F140'
    ), ('석쇠구이족발앞다리', 'F141'), ('반반족발앞다리', 'F142'), ('메밀전병', 'F144'), ('돈까스',
    'F163'), ('김치치즈돈까스', 'F164'), ('간사이 오뎅나베', 'F165'), ('크림 나베', 'F166'),
    ('묵은지 돈까스', 'F167'), ('우동', 'F147'), ('라멘', 'F149'), ('마제멘', 'F168'), (
    '차슈동', 'F042'), ('카라구치라멘', 'F169'), ('미소라멘', 'F170'), ('어개라멘', 'F171'),
    ('부타동', 'F041'), ('라멘', 'F149'), ('돈코치라멘', 'F172'), ('츠케멘', 'F173'), (
    '차슈동', 'F042'), ('특차슈동', 'F174'), ('돈까스', 'F163'), ('히레돈까스', 'F175'), (
    '고구마돈까스', 'F176'), ('가츠동', 'F177'), ('냉모밀', 'F178'), ('에비동', 'F179'), (
    '떡볶이', 'F180'), ('해물떡볶이', 'F181'), ('치즈떡볶이', 'F182'), ('모듬떡볶이', 'F183'),
    ('치즈라면', 'F184'), ('볶음밥', 'F160'), ('김치찌개', 'F098'), ('참치찌개', 'F185'),
    ('알밥', 'F155'), ('제육볶음', 'F106'), ('부대찌개', 'F097'), ('갈비탕', 'F186'), (
    '짜장면', 'F073'), ('짬뽕', 'F074'), ('차돌박이 짬뽕', 'F187'), ('탕수육', 'F188'), (
    '볶음밥', 'F160'), ('꿔바로우', 'F189'), ('짬뽕', 'F074'), ('삼선볶음짬뽕', 'F190'), (
    '탕수육', 'F188'), ('짜장면', 'F073'), ('깐쇼새우', 'F191'), ('팔보채', 'F192'), (
    '프렌치 토스트', 'F193'), ('팬케이크', 'F194'), ('메리 팬케이크', 'F195'), ('타르트',
    'F196'), ('다크 쇼콜라', 'F197'), ('팥빙수', 'F198'), ('푸팟퐁커리', 'F199'), (
    '파타이꿍', 'F200'), ('볶음밥', 'F201'), ('팟씨유꿍', 'F202'), ('파오무삽', 'F203'), (
    '똠양꿍', 'F204'), ('스테이크', 'F146'), ('연어 스테이크', 'F205'), ('등심 스테이크',
    'F206'), ('슈바인골드 스테이크', 'F207'), ('열무소면', 'F208'), ('연어 샐러드', 'F209'),
    ('스테이크', 'F146'), ('리코타 샐러드', 'F210'), ('피자', 'F211'), ('리코타 피자',
    'F212'), ('봉골레파스타', 'F213'), ('리조또', 'F214'), ('시금치 포카치아', 'F215'), (
    '바베큐 포카치아', 'F216'), ('샐러드', 'F217'), ('봉골레파스타', 'F213'), ('연어 샐러드',
    'F209'), ('까르보나라', 'F218'), ('우동', 'F147'), ('도끼정 잔칫상', 'F219'), ('돈데끼',
    'F220'), ('숯불구이 반반', 'F221'), ('스테이크', 'F146'), ('카레나베', 'F222'), (
    '스테이크', 'F146'), ('치킨샐러드', 'F223'), ('라자냐', 'F224'), ('빠네파스타', 'F225'),
    ('해산물 로제 파스타', 'F226'), ('필라프', 'F227'), ('오징어구이밥', 'F228'), ('리조또',
    'F214'), ('봉골레파스타', 'F213'), ('까르보나라', 'F218'), ('소고기미트볼과 감자튀김', 'F229'
    ), ('스테이크', 'F146'), ('불고기', 'F230'), ('시래기 나물밥', 'F231'), ('양념불고기나물밥',
    'F232'), ('된장전골불고기', 'F233'), ('김치찌개', 'F098'), ('볶음밥', 'F160'), (
    '스테이크', 'F146'), ('치킨 스테이크', 'F234'), ('리조또', 'F214'), ('마르게리따', 'F235'
    ), ('루꼴라 샐러드', 'F236'), ('필라프', 'F227'), ('마르게리따', 'F235'), ('리조또',
    'F214'), ('고르곤졸라', 'F237'), ('알리오 올리오', 'F238'), ('까르보나라', 'F218'), (
    '필라프', 'F227'), ('샐러드', 'F217'), ('해산물 샐러드', 'F239'), ('얌운센', 'F240'),
    ('남똑무', 'F241'), ('치킨', 'F154'), ('볶음밥', 'F160'), ('꽃방', 'F242'), (
    '깐풍기', 'F243'), ('찹쌀탕수육', 'F076'), ('유산슬', 'F244'), ('볶음밥', 'F160'), (
    '짜장면', 'F073'), ('불고기', 'F230'), ('보쌈', 'F245'), ('숯불 돼지불고기', 'F246'),
    ('오리고기', 'F247'), ('묵사발 정식', 'F248'), ('정식', 'F249')]
DATA_TABLES['FOOD_TYPE'] = [('한식', 'T001'), ('일식', 'T002'), ('중식', 'T003'),
    ('양식', 'T004'), ('술집', 'T005'), ('기타', 'T006')]
DATA_TABLES['COOKED_BY'] = [('F001', 'R001'), ('F002', 'R001'), ('F003',
    'R001'), ('F004', 'R001'), ('F005', 'R001'), ('F006', 'R001'), ('F007',
    'R002'), ('F008', 'R002'), ('F009', 'R002'), ('F010', 'R002'), ('F011',
    'R002'), ('F012', 'R002'), ('F013', 'R003'), ('F014', 'R003'), ('F015',
    'R003'), ('F016', 'R003'), ('F017', 'R003'), ('F018', 'R003'), ('F019',
    'R004'), ('F020', 'R004'), ('F021', 'R004'), ('F022', 'R004'), ('F023',
    'R004'), ('F024', 'R004'), ('F025', 'R005'), ('F026', 'R005'), ('F027',
    'R005'), ('F028', 'R005'), ('F029', 'R005'), ('F030', 'R005'), ('F031',
    'R006'), ('F032', 'R006'), ('F033', 'R006'), ('F034', 'R006'), ('F035',
    'R006'), ('F036', 'R006'), ('F037', 'R007'), ('F038', 'R007'), ('F039',
    'R007'), ('F040', 'R007'), ('F041', 'R007'), ('F042', 'R007'), ('F043',
    'R008'), ('F044', 'R008'), ('F045', 'R008'), ('F046', 'R008'), ('F047',
    'R008'), ('F048', 'R008'), ('F049', 'R009'), ('F050', 'R009'), ('F051',
    'R009'), ('F052', 'R009'), ('F053', 'R009'), ('F054', 'R009'), ('F055',
    'R010'), ('F056', 'R010'), ('F057', 'R010'), ('F058', 'R010'), ('F059',
    'R010'), ('F060', 'R010'), ('F061', 'R011'), ('F062', 'R011'), ('F063',
    'R011'), ('F064', 'R011'), ('F065', 'R011'), ('F066', 'R011'), ('F067',
    'R012'), ('F068', 'R012'), ('F069', 'R012'), ('F070', 'R012'), ('F071',
    'R012'), ('F072', 'R012'), ('F073', 'R013'), ('F074', 'R013'), ('F075',
    'R013'), ('F076', 'R013'), ('F077', 'R013'), ('F078', 'R013'), ('F079',
    'R014'), ('F080', 'R014'), ('F081', 'R014'), ('F082', 'R014'), ('F083',
    'R014'), ('F084', 'R014'), ('F085', 'R015'), ('F086', 'R015'), ('F087',
    'R015'), ('F088', 'R015'), ('F089', 'R015'), ('F090', 'R015'), ('F091',
    'R016'), ('F092', 'R016'), ('F093', 'R016'), ('F094', 'R016'), ('F095',
    'R016'), ('F096', 'R016'), ('F097', 'R017'), ('F098', 'R017'), ('F099',
    'R017'), ('F100', 'R017'), ('F101', 'R017'), ('F102', 'R017'), ('F098',
    'R018'), ('F104', 'R018'), ('F087', 'R018'), ('F106', 'R018'), ('F107',
    'R018'), ('F097', 'R018'), ('F109', 'R019'), ('F110', 'R019'), ('F111',
    'R019'), ('F112', 'R019'), ('F113', 'R019'), ('F114', 'R019'), ('F115',
    'R020'), ('F116', 'R020'), ('F068', 'R020'), ('F067', 'R020'), ('F119',
    'R020'), ('F120', 'R020'), ('F121', 'R021'), ('F122', 'R021'), ('F088',
    'R021'), ('F124', 'R021'), ('F125', 'R021'), ('F126', 'R021'), ('F127',
    'R022'), ('F128', 'R022'), ('F129', 'R022'), ('F130', 'R022'), ('F131',
    'R022'), ('F132', 'R022'), ('F133', 'R023'), ('F134', 'R023'), ('F042',
    'R023'), ('F041', 'R023'), ('F137', 'R023'), ('F138', 'R023'), ('F139',
    'R024'), ('F140', 'R024'), ('F141', 'R024'), ('F142', 'R024'), ('F099',
    'R024'), ('F144', 'R024'), ('F145', 'R001'), ('F146', 'R002'), ('F146',
    'R006'), ('F147', 'R003'), ('F148', 'R004'), ('F148', 'R005'), ('F149',
    'R007'), ('F150', 'R008'), ('F151', 'R009'), ('F152', 'R010'), ('F153',
    'R011'), ('F154', 'R012'), ('F154', 'R020'), ('F155', 'R014'), ('F156',
    'R015'), ('F157', 'R016'), ('F158', 'R019'), ('F159', 'R021'), ('F160',
    'R022'), ('F161', 'R023'), ('F162', 'R024'), ('F163', 'R025'), ('F164',
    'R025'), ('F165', 'R025'), ('F166', 'R025'), ('F167', 'R025'), ('F147',
    'R025'), ('F149', 'R026'), ('F168', 'R026'), ('F042', 'R026'), ('F169',
    'R026'), ('F170', 'R026'), ('F171', 'R026'), ('F041', 'R027'), ('F149',
    'R027'), ('F172', 'R027'), ('F173', 'R027'), ('F042', 'R027'), ('F174',
    'R027'), ('F163', 'R028'), ('F175', 'R028'), ('F176', 'R028'), ('F177',
    'R028'), ('F178', 'R028'), ('F179', 'R028'), ('F180', 'R029'), ('F181',
    'R029'), ('F182', 'R029'), ('F183', 'R029'), ('F184', 'R029'), ('F160',
    'R029'), ('F098', 'R030'), ('F185', 'R030'), ('F155', 'R030'), ('F106',
    'R030'), ('F097', 'R030'), ('F186', 'R030'), ('F073', 'R031'), ('F074',
    'R031'), ('F187', 'R031'), ('F188', 'R031'), ('F160', 'R031'), ('F189',
    'R031'), ('F074', 'R032'), ('F190', 'R032'), ('F188', 'R032'), ('F073',
    'R032'), ('F191', 'R032'), ('F192', 'R032'), ('F193', 'R033'), ('F194',
    'R033'), ('F195', 'R033'), ('F196', 'R033'), ('F197', 'R033'), ('F198',
    'R033'), ('F199', 'R034'), ('F200', 'R034'), ('F201', 'R034'), ('F202',
    'R034'), ('F203', 'R034'), ('F204', 'R034'), ('F146', 'R035'), ('F205',
    'R035'), ('F206', 'R035'), ('F207', 'R035'), ('F208', 'R035'), ('F209',
    'R035'), ('F146', 'R036'), ('F210', 'R036'), ('F211', 'R036'), ('F212',
    'R036'), ('F213', 'R036'), ('F214', 'R036'), ('F215', 'R037'), ('F216',
    'R037'), ('F217', 'R037'), ('F213', 'R037'), ('F209', 'R037'), ('F218',
    'R037'), ('F147', 'R038'), ('F219', 'R038'), ('F220', 'R038'), ('F221',
    'R038'), ('F146', 'R038'), ('F222', 'R038'), ('F146', 'R039'), ('F223',
    'R039'), ('F224', 'R039'), ('F225', 'R039'), ('F226', 'R039'), ('F227',
    'R039'), ('F228', 'R040'), ('F214', 'R040'), ('F213', 'R040'), ('F218',
    'R040'), ('F229', 'R040'), ('F146', 'R040'), ('F230', 'R041'), ('F231',
    'R041'), ('F232', 'R041'), ('F233', 'R041'), ('F098', 'R041'), ('F160',
    'R041'), ('F146', 'R042'), ('F234', 'R042'), ('F214', 'R042'), ('F235',
    'R042'), ('F236', 'R042'), ('F227', 'R042'), ('F235', 'R043'), ('F214',
    'R043'), ('F237', 'R043'), ('F238', 'R043'), ('F218', 'R043'), ('F227',
    'R043'), ('F217', 'R044'), ('F239', 'R044'), ('F240', 'R044'), ('F241',
    'R044'), ('F154', 'R044'), ('F160', 'R044'), ('F242', 'R045'), ('F243',
    'R045'), ('F076', 'R045'), ('F244', 'R045'), ('F160', 'R045'), ('F073',
    'R045'), ('F230', 'R046'), ('F245', 'R046'), ('F246', 'R046'), ('F247',
    'R046'), ('F248', 'R046'), ('F249', 'R046')]
DATA_TABLES['RESTAURANT'] = [('고씨네', 'R001', 'T002',
    'https://store.naver.com/restaurants/detail?id=37269016', '6000~9500'),
    ('모모스테이크', 'R002', 'T004',
    'https://store.naver.com/restaurants/detail?id=36412392', '8500~16000'),
    ('천애부', 'R003', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=33875226', '2000~9500'
    ), ('일미닭갈비', 'R004', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=38485469',
    '6900~14000'), ('유가네닭갈비', 'R005', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=21102801',
    '4500~28000'), ('Mr.Chef Pocha', 'R006', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=21278958',
    '9500~50000'), ('멘야고이치', 'R007', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=20322446', '6500~7500'
    ), ('밀플랜비', 'R008', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=38009073', '3000~6000'
    ), ('Mr.chef', 'R009', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=30811729', '5500~8000'
    ), ('봉구스밥버거', 'R010', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=31077787', '1800~3500'
    ), ('미스사이공', 'R011', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=38762477', '3900~4900'
    ), ('도담도담치킨', 'R012', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=36655478&entry=plt',
    '15000~16000'), ('뽕스토리', 'R013', 'T003',
    'https://m.store.naver.com/restaurants/detail?id=342201261',
    '4500~35000'), ('알촌', 'R014', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=32848717', '3500~4800'
    ), ('벌집삼겹살', 'R015', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=19438153',
    '3500~11900'), ('내가찜한닭', 'R016', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=33471257',
    '17000~39000'), ('맛구단', 'R017', 'T001',
    'https://m.search.naver.com/search.naver?where=m&sm=mtb_jum',
    '2000~22000'), ('찌개백반', 'R018', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=18226632', '5000~8000'
    ), ('서울곱창', 'R019', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=18227763',
    '17000~50000'), ('전설의치킨', 'R020', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=37811564',
    '11000~1400'), ('반값소', 'R021', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=37592424',
    '3000~39000'), ('푸드테라피', 'R022', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=33133453', '5000~7000'
    ), ('만고쿠', 'R023', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=37342139', '4000~8000'
    ), ('우만동족발집', 'R024', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=36424455',
    '3000~36000'), ('소고', 'R025', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=35657866',
    '9500~13000'), ('멘야고코로', 'R026', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=38346358', '5900~7500'
    ), ('키와마루아지', 'R027', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=37162932',
    '9900~14000'), ('도꼬돈카츠', 'R028', 'T002',
    'https://m.store.naver.com/restaurants/detail?id=33875226', '6000~9000'
    ), ('동떡이', 'R029', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=18242833', '1500~6000'
    ), ('시골집', 'R030', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=13560446', '6000~8000'
    ), ('광교반점', 'R031', 'T003',
    'https://m.store.naver.com/restaurants/detail?id=37269538',
    '5000~15000'), ('현경', 'R032', 'T003',
    'https://m.store.naver.com/places/detail?id=437262373', '8000~22000'),
    ('카페드로잉', 'R033', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36561330',
    '10000~20000'), ('바나나테이블', 'R034', 'T006',
    'https://m.store.naver.com/restaurants/detail?id=36943345',
    '13000~26000'), ('슈퍼스테이크', 'R035', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=37341816',
    '6000~18000'), ('소마바이네이쳐', 'R036', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36674562',
    '16000~39000'), ('시카고피자', 'R037', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=37259982',
    '12000~18000'), ('토끼정', 'R038', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=533097088',
    '9000~14000'), ('갈릭 앤 모어', 'R039', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=968321089',
    '9000~18000'), ('아날로그치킨', 'R040', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=37111515',
    '15000~55000'), ('미스터시래기', 'R041', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=36561053',
    '8000~19000'), ('더플레이스', 'R042', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36900565',
    '13000~43000'), ('오이탈리안', 'R043', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=38641900', '7700~8800'
    ), ('생어거스틴', 'R044', 'T004',
    'https://m.store.naver.com/restaurants/detail?id=36624270',
    '13000~19000'), ('매란방', 'R045', 'T003',
    'https://m.store.naver.com/restaurants/detail?id=164938685',
    '3000~19000'), ('풍원장', 'R046', 'T001',
    'https://m.store.naver.com/restaurants/detail?id=37492092', '15000~34000')]
for name, insert_form in INSERT_TABLES.iteritems():
    try:
        print('Inserting tuples to TABLE({})\n'.format(name), end='')
        for data in DATA_TABLES[name]:
            try:
                cursor.execute(insert_form, data)
            except mysql.connector.Error as err:
                print('{}({})'.format(err.msg, name))
    except mysql.connector.Error as err:
        if err:
            print(err.msg)
        else:
            print('OK')
cursor.execute(enable_foreign)
cnx.commit()
cursor.close()
cnx.close()

#-*-coding: utf-8 -*-


from __future__ import print_function
from datetime import date, datetime, timedelta
import mysql.connector
import os
from mysql.connector import errorcode

DB_NAME = 'dbdbdeep'
print("DB loading...\n\n")
#login(connect to mysql)---------------------------------------------------------------------------------
try:
  cnx = mysql.connector.connect(host= 'dbdbdeep.co7zvonejcs7.ap-northeast-2.rds.amazonaws.com',
                                user='blcocas',
                                password = '201221027',
                                charset='utf8mb4')
  cursor = cnx.cursor()
  print("success to connect")

except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exist")
  else:
    print(err)

#create database-----------------------------------------------------------------------------------------
def create_database(cursor):
    try:
        cursor.execute(
            "CREATE DATABASE {} DEFAULT CHARACTER SET 'utf8'".format(DB_NAME))
        print("success to creat DB")
    except mysql.connector.Error as err:
        print("Failed creating database: {}".format(err))
        exit(1)

try:
    cnx.database = DB_NAME  
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_BAD_DB_ERROR:
        create_database(cursor)
        cnx.database = DB_NAME
    else:
        print(err)
        exit(1)

#Relation-----------------------------------------------------------------------------------------------

TABLES = {}

TABLES['FOOD'] = (
"CREATE TABLE  `FOOD`(" 
"`Food_Name`        varchar(15)     NOT NULL,"
"`Food_Num`         char(8)         NOT NULL,"
"PRIMARY KEY (`Food_Num`)"
") ENGINE=InnoDB")


TABLES['FOOD_TYPE'] = (
"CREATE TABLE  `FOOD_TYPE` ("
"`Type_Name`       varchar(15)       NOT NULL,"
"`Type_Num`        char(8)           NOT NULL,"
"PRIMARY KEY (`Type_Num`)"
")ENGINE=InnoDB")

TABLES['COOKED_BY'] = (
"CREATE TABLE  `COOKED_BY` ("   
"`F_Num`        char(8)     NOT NULL,"
"`R_Num`        char(8)     NOT NULL,"
"PRIMARY KEY(`F_Num`, `R_Num`),"
"FOREIGN KEY (`F_Num`) REFERENCES `FOOD`(`Food_Num`),"
"FOREIGN KEY (`R_Num`) REFERENCES `RESTAURANT`(`Rest_Num`)"
")ENGINE=InnoDB")

    
TABLES['RESTAURANT'] = (
"CREATE TABLE  RESTAURANT ( "
"`Rest_Name`       varchar(15)     NOT NULL,"
"`Rest_Num`        char(8)     NOT NULL,"
"`T_Num`           char(8)     NOT NULL,"
"`Map`            varchar(100)     ,"
"`Average_Cost`    varchar(15)         ,"
"PRIMARY KEY (`Rest_Num`),"
"FOREIGN KEY (`T_Num`) REFERENCES FOOD_TYPE(`Type_Num`)"
")ENGINE=InnoDB")



 #foreign key constraints unlock argument-----------------------------------------------------------------               

disable_foreign = ''' 
    SET FOREIGN_KEY_CHECKS = 0;
'''
enable_foreign = ''' 
    SET FOREIGN_KEY_CHECKS = 1;
'''

#create tables------------------------------------------------------------------------------------------
cursor.execute(disable_foreign) #foreign key constraint no check

for name, ddl in TABLES.iteritems():
    try:
        print("Creating table {}: ".format(name), end='')
        cursor.execute(ddl)
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
            print("already exists.")
        else:
            print(err.msg)
    else:
        print("OK")
#insert data form---------------------------------------------------------------------------------------
INSERT_TABLES = {}
INSERT_TABLES['FOOD'] = ("INSERT INTO FOOD "
            "(Food_Name, Food_Num)"
            "VALUES (%s, %s)")

INSERT_TABLES['FOOD_TYPE'] = ("INSERT INTO FOOD_TYPE "
            "(Type_Name,Type_Num)"
            "VALUES (%s, %s)")

INSERT_TABLES['COOKED_BY'] = ("INSERT INTO COOKED_BY "
            "(F_Num,R_Num)"
            "VALUES (%s, %s)")

INSERT_TABLES['RESTAURANT'] = ("INSERT INTO RESTAURANT "
            "(Rest_Name,Rest_Num,T_Num,Map,Average_Cost)"
            "VALUES (%s, %s, %s, %s, %s)")

#tuples-------------------------------------------------------------------------------------------------
DATA_TABLES = {}
DATA_TABLES['FOOD'] = [ #40ea
('카레','F145'),
('고씨네 돈까스 카레','F001'),
('고씨네 스페셜 카레','F002'),
('고씨네 프리미엄 카레','F003'),
('돈까스 카레 우동','F004'),
('버섯 카레 우동','F005'),
('버섯 카레','F006'),

('스테이크','F146'),
('스테이크삼겹정식','F007'),
('스테이크정식(소)','F008'),
('삼겹테이크정식(소)','F009'),
('안창불고기스테이크정식','F010'),
('목살스테이크볶음밥','F011'),
('모듬스테이크정식','F012'),

('우동','F147'),
('김치돈까스나베','F013'),
('할라피뇨연어덮밥','F014'),
('수제돈까스','F015'),
('해물야끼우동','F016'),
('달인냉우동','F017'),
('마약냉우동','F018'),

('아주세트','F019'),
('치즈세트','F020'),
('치즈더블세트','F021'),
('솥뚜껑 해물파전','F022'),
('철판 모듬 스페셜','F023'),
('철판 제육 볶음','F024'),

('닭갈비','F148'),
('닭갈비철판볶음밥','F025'),
('매운철판볶음밥','F026'),
('모듬철판볶음밥','F027'),
('유가네닭갈비','F028'),
('미소허니퐁닭','F029'),
('해물철판볶음밥','F030'),

('그릴 목살 스테이크','F031'),
('살치살 소고기 스테이크','F032'),
('핫치킨 꿀치즈 퀘사디아','F033'),
('페퍼로니 토마토 퀘사디아','F034'),
('소고기 감자 스튜','F035'),
('모든치즈크래커','F036'),

('라멘','F149'),
('돈코츠라멘','F037'),
('소유라멘','F038'),
('미소라멘','F039'),
('규동','F040'),
('부타동','F041'),
('차슈동','F042'),

('부리또','F150'),
('치킨라이스','F043'),
('치킨감자','F044'),
('소고기라이스','F045'),
('소세지감자','F046'),
('새우감자','F047'),
('핫도그','F048'),

('제육볶음','F151'),
('해물뚝배기','F049'),
('제육두루치기','F050'),
('참치김치찌개','F051'),
('카레덮밥','F052'),
('돈까스덮밥','F053'),
('곱창순두부찌개','F054'),

('밥버거','F152'),
('봉구스밥버거','F055'),
('햄치즈밥버거','F056'),
('치즈제육밥버거','F057'),
('청양불고기밥버거','F058'),
('소불고기밥버거','F059'),
('통살돈까스마요밥버거','F060'),

('쌀국수','F153'),
('소고기 쌀국수','F061'),
('닭 쌀국수','F062'),
('사이공 볶음밥','F063'),
('사이공 볶음면','F064'),
('새우볼','F065'),
('사이공 딤섬','F066'),

('크리스피','F067'),
('양념치킨','F068'),
('간장','F069'),
('스위트갈릭','F070'),
('스위트버터','F071'),
('반반치킨','F072'),

('짜장면','F073'),
('짱뽕','F074'),
('삼선짬뽕','F075'),
('찹쌀탕수육','F076'),
('양꼬치','F077'),
('군만두','F078'),

('알밥','F155'),
('순한알밥','F079'),
('매콤알밥','F080'),
('매콤치즈알밥','F081'),
('카레알밥','F082'),
('갈릭알밥','F083'),
('갈립치즈알밥','F084'),

('삼겹살','F156'),
('벌집삼겹살','F085'),
('돼지왕구이','F086'),
('갈비탕','F087'),
('김치말이국수','F088'),
('냉면','F089'),
('항정살','F090'),

('찜닭','F157'),
('고추장찜닭','F091'),
('안동찜닭','F092'),
('순살안동장찜닭','F093'),
('순살고추장찜닭','F094'),
('치즈순살찜닭중','F095'),
('치즈순살찜닭대','F096'),

('김치찌개','F098'),
('주먹밥','F099'),
('계란말이','F100'),
('라면','F101'),
('만두','F102'),

('부대찌개','F097'),
#('부대찌개','F103'), F098
('육계장','F104'),
#('갈비탕','F105'), F087
('제육볶음','F106'),
('순두부찌개','F107'),
#('김치찌개','F108'), F097

('곱창','F158'),
('양구이','F109'),
('대창구이','F110'),
('곱창구이','F111'),
('막창구이','F112'),
('천엽','F113'),
('곱창전골','F114'),

('치킨','F154'),
('전설의치킨','F115'),
('칠리새우순살','F116'),
#('양념치킨','F117'), F068
#('크리스피','F118'), F067
('순살파닭','F119'),
('치킨떡볶이','F120'),

('소고기','F159'),
('소한마리(생고기)','F121'),
('소한마리(주물럭)','F122'),
#('김치말이국수','F123'), F088
('소고기국수','F124'),
('비빔국수','F125'),
('우거지국','F126'),

('볶음밥','F160'),
('돌판삼겹살','F127'),
('돌판닭갈비','F128'),
('돌판제육볶음','F129'),
('돌판날치알밥','F130'),
('돌판힐링볶음밥','F131'),
('돌판소불고기','F132'),

('덮밥','F161'),
('와규덮밥','F133'),
('생연어덮밥','F134'),
#('차슈덮밥','F135'),F042
#('부타동덮밥','F136'), F041
('가츠동덮밥','F137'),
('에비동덮밥','F138'),

('족발','F162'),
('참족발앞다리','F139'),
('불족발앞다리','F140'),
('석쇠구이족발앞다리','F141'),
('반반족발앞다리','F142'),
#('주먹밥','F143'), F099
('메밀전병','F144'),

('돈까스', 'F163'),
('김치치즈돈까스', 'F164'),
('간사이 오뎅나베', 'F165'),
('크림 나베', 'F166'),
('묵은지 돈까스', 'F167'),
('우동', 'F147'),

('라멘', 'F149'),
('마제멘', 'F168'),
('차슈동', 'F042'),
('카라구치라멘', 'F169'),
('미소라멘', 'F170'),
('어개라멘', 'F171'),

('부타동', 'F041'),
('라멘', 'F149'),
('돈코치라멘', 'F172'),
('츠케멘', 'F173'),
('차슈동', 'F042'),
('특차슈동', 'F174'),

('돈까스', 'F163'),
('히레돈까스', 'F175'),
('고구마돈까스', 'F176'),
('가츠동', 'F177'),
('냉모밀', 'F178'),
('에비동', 'F179'),

('떡볶이', 'F180'),
('해물떡볶이', 'F181'),
('치즈떡볶이', 'F182'),
('모듬떡볶이', 'F183'),
('치즈라면', 'F184'),
('볶음밥', 'F160'),


('김치찌개', 'F098'),
('참치찌개', 'F185'),
('알밥', 'F155'),
('제육볶음', 'F106'),
('부대찌개', 'F097'),
('갈비탕', 'F186'),

('짜장면', 'F073'),
('짬뽕', 'F074'),
('차돌박이 짬뽕', 'F187'),
('탕수육', 'F188'),
('볶음밥', 'F160'),
('꿔바로우', 'F189'),


('짬뽕', 'F074'),
('삼선볶음짬뽕', 'F190'),
('탕수육', 'F188'),
('짜장면', 'F073'),
('깐쇼새우', 'F191'),
('팔보채', 'F192'),



('프렌치 토스트', 'F193'),
('팬케이크', 'F194'),
('메리 팬케이크', 'F195'),
('타르트', 'F196'),
('다크 쇼콜라', 'F197'),
('팥빙수', 'F198'),


('푸팟퐁커리', 'F199'),
('파타이꿍', 'F200'),
('볶음밥', 'F201'),
('팟씨유꿍', 'F202'),
('파오무삽', 'F203'),
('똠양꿍', 'F204'),


('스테이크', 'F146'),
('연어 스테이크', 'F205'),
('등심 스테이크', 'F206'),
('슈바인골드 스테이크', 'F207'),
('열무소면', 'F208'),
('연어 샐러드', 'F209'),


('스테이크', 'F146'),
('리코타 샐러드', 'F210'),
('피자', 'F211'),
('리코타 피자', 'F212'),
('봉골레파스타', 'F213'),
('리조또', 'F214'),

('시금치 포카치아', 'F215'),
('바베큐 포카치아', 'F216'),
('샐러드', 'F217'),
('봉골레파스타', 'F213'),
('연어 샐러드', 'F209'),
('까르보나라', 'F218'),



('우동', 'F147'),
('도끼정 잔칫상', 'F219'),
('돈데끼', 'F220'),
('숯불구이 반반', 'F221'),
('스테이크', 'F146'),
('카레나베', 'F222'),


('스테이크', 'F146'),
('치킨샐러드', 'F223'),
('라자냐', 'F224'),
('빠네파스타', 'F225'),
('해산물 로제 파스타', 'F226'),
('필라프', 'F227'),

('오징어구이밥', 'F228'),
('리조또', 'F214'),
('봉골레파스타', 'F213'),
('까르보나라', 'F218'),
('소고기미트볼과 감자튀김', 'F229'),
('스테이크', 'F146'),

('불고기', 'F230'),
('시래기 나물밥', 'F231'),
('양념불고기나물밥', 'F232'),
('된장전골불고기', 'F233'),
('김치찌개', 'F098'),
('볶음밥', 'F160'),


('스테이크', 'F146'),
('치킨 스테이크', 'F234'),
('리조또', 'F214'),
('마르게리따', 'F235'),
('루꼴라 샐러드', 'F236'),
('필라프', 'F227'),

('마르게리따', 'F235'),
('리조또', 'F214'),
('고르곤졸라', 'F237'),
('알리오 올리오', 'F238'),
('까르보나라', 'F218'),
('필라프', 'F227'),

('샐러드', 'F217'),
('해산물 샐러드', 'F239'),
('얌운센', 'F240'),
('남똑무', 'F241'),
('치킨', 'F154'),
('볶음밥', 'F160'),

('꽃방', 'F242'),
('깐풍기', 'F243'),
('찹쌀탕수육', 'F076'),
('유산슬', 'F244'),
('볶음밥', 'F160'),
('짜장면', 'F073'),

('불고기', 'F230'),
('보쌈', 'F245'),
('숯불 돼지불고기', 'F246'),
('오리고기', 'F247'),
('묵사발 정식', 'F248'),
('정식', 'F249')



#('돌판힐링볶음밥','F145'),
#('돌판힐링볶음밥','F146'),
#('돌판힐링볶음밥','F147'),
#('돌판힐링볶음밥','F148'),
#('돌판힐링볶음밥','F149'),
#('돌판힐링볶음밥','F150')

]

DATA_TABLES['FOOD_TYPE'] = [ 
('한식',        'T001'),
('일식',        'T002'),
('중식',        'T003'),
('양식',        'T004'),
('술집',        'T005'),
('기타',        'T006')
]

DATA_TABLES['COOKED_BY'] = [ 
('F001',        'R001'),
('F002',        'R001'),
('F003',        'R001'),
('F004',        'R001'),
('F005',        'R001'),
('F006',        'R001'),

('F007',        'R002'),
('F008',        'R002'),
('F009',        'R002'),
('F010',        'R002'),
('F011',        'R002'),
('F012',        'R002'),

('F013',        'R003'),
('F014',        'R003'),
('F015',        'R003'),
('F016',        'R003'),
('F017',        'R003'),
('F018',        'R003'),

('F019',        'R004'),
('F020',        'R004'),
('F021',        'R004'),
('F022',        'R004'),
('F023',        'R004'),
('F024',        'R004'),

('F025',        'R005'),
('F026',        'R005'),
('F027',        'R005'),
('F028',        'R005'),
('F029',        'R005'),
('F030',        'R005'),

('F031',        'R006'),
('F032',        'R006'),
('F033',        'R006'),
('F034',        'R006'),
('F035',        'R006'),
('F036',        'R006'),

('F037',        'R007'),
('F038',        'R007'),
('F039',        'R007'),
('F040',        'R007'),
('F041',        'R007'),
('F042',        'R007'),

('F043',        'R008'),
('F044',        'R008'),
('F045',        'R008'),
('F046',        'R008'),
('F047',        'R008'),
('F048',        'R008'),

('F049',        'R009'),
('F050',        'R009'),
('F051',        'R009'),
('F052',        'R009'),
('F053',        'R009'),
('F054',        'R009'),

('F055',        'R010'),
('F056',        'R010'),
('F057',        'R010'),
('F058',        'R010'),
('F059',        'R010'),
('F060',        'R010'),

('F061',        'R011'),
('F062',        'R011'),
('F063',        'R011'),
('F064',        'R011'),
('F065',        'R011'),
('F066',        'R011'),

('F067',        'R012'),
('F068',        'R012'),
('F069',        'R012'),
('F070',        'R012'),
('F071',        'R012'),
('F072',        'R012'),

('F073',        'R013'),
('F074',        'R013'),
('F075',        'R013'),
('F076',        'R013'),
('F077',        'R013'),
('F078',        'R013'),

('F079',        'R014'),
('F080',        'R014'),
('F081',        'R014'),
('F082',        'R014'),
('F083',        'R014'),
('F084',        'R014'),

('F085',        'R015'),
('F086',        'R015'),
('F087',        'R015'),
('F088',        'R015'),
('F089',        'R015'),
('F090',        'R015'),

('F091',        'R016'),
('F092',        'R016'),
('F093',        'R016'),
('F094',        'R016'),
('F095',        'R016'),
('F096',        'R016'),

('F097',        'R017'),
('F098',        'R017'),
('F099',        'R017'),
('F100',        'R017'),
('F101',        'R017'),
('F102',        'R017'),

('F098',        'R018'),
('F104',        'R018'),
('F087',        'R018'),
('F106',        'R018'),
('F107',        'R018'),
('F097',        'R018'),

('F109',        'R019'),
('F110',        'R019'),
('F111',        'R019'),
('F112',        'R019'),
('F113',        'R019'),
('F114',        'R019'),

('F115',        'R020'),
('F116',        'R020'),
('F068',        'R020'),
('F067',        'R020'),
('F119',        'R020'),
('F120',        'R020'),

('F121',        'R021'),
('F122',        'R021'),
('F088',        'R021'),
('F124',        'R021'),
('F125',        'R021'),
('F126',        'R021'),

('F127',        'R022'),
('F128',        'R022'),
('F129',        'R022'),
('F130',        'R022'),
('F131',        'R022'),
('F132',        'R022'),

('F133',        'R023'),
('F134',        'R023'),
('F042',        'R023'),
('F041',        'R023'),
('F137',        'R023'),
('F138',        'R023'),

('F139',        'R024'),
('F140',        'R024'),
('F141',        'R024'),
('F142',        'R024'),
('F099',        'R024'),
('F144',        'R024'),

('F145',        'R001'),
('F146',        'R002'),
('F146',        'R006'),
('F147',        'R003'),

('F148',        'R004'),
('F148',        'R005'),

('F149',        'R007'),
('F150',        'R008'),
('F151',        'R009'),

('F152',        'R010'),
('F153',        'R011'),
('F154',        'R012'),
('F154',        'R020'),

('F155',        'R014'),
('F156',        'R015'),
('F157',        'R016'),
('F158',        'R019'),
('F159',        'R021'),
('F160',        'R022'),
('F161',        'R023'),
('F162',        'R024'),

('F163',        'R025'),
('F164',      'R025'),
('F165',      'R025'),
('F166',      'R025'),
('F167',      'R025'),
('F147',      'R025'),


('F149',      'R026'),
('F168',      'R026'),
('F042',      'R026'),
('F169',      'R026'),
('F170',      'R026'),
('F171',      'R026'),


('F041',      'R027'),
('F149',      'R027'),
('F172',      'R027'),
('F173',      'R027'),
('F042',      'R027'),
('F174',      'R027'),


('F163',      'R028'),
('F175',      'R028'),
('F176',      'R028'),
('F177',      'R028'),
('F178',      'R028'),
('F179',      'R028'),


('F180',      'R029'),
('F181',      'R029'),
('F182',      'R029'),
('F183',      'R029'),
('F184',      'R029'),
('F160',      'R029'),


('F098',      'R030'),
('F185',      'R030'),
('F155',      'R030'),
('F106',      'R030'),
('F097',      'R030'),
('F186',      'R030'),


('F073',      'R031'),
('F074',      'R031'),
('F187',      'R031'),
('F188',      'R031'),
('F160',      'R031'),
('F189',      'R031'),


('F074',      'R032'),
('F190',      'R032'),
('F188',      'R032'),
('F073',      'R032'),
('F191',      'R032'),
('F192',      'R032'),

('F193',      'R033'),
('F194',      'R033'),
('F195',      'R033'),
('F196',      'R033'),
('F197',      'R033'),
('F198',      'R033'),

('F199',      'R034'),
('F200',      'R034'),
('F201',      'R034'),
('F202',      'R034'),
('F203',      'R034'),
('F204',      'R034'),

('F146',      'R035'),
('F205',      'R035'),
('F206',      'R035'),
('F207',      'R035'),
('F208',      'R035'),
('F209',      'R035'),

('F146',      'R036'),
('F210',      'R036'),
('F211',      'R036'),
('F212',      'R036'),
('F213',      'R036'),
('F214',      'R036'),

('F215',      'R037'),
('F216',      'R037'),
('F217',      'R037'),
('F213',      'R037'),
('F209',      'R037'),
('F218',      'R037'),


('F147',      'R038'),
('F219',      'R038'),
('F220',      'R038'),
('F221',      'R038'),
('F146',      'R038'),
('F222',      'R038'),


('F146',      'R039'),
('F223',      'R039'),
('F224',      'R039'),
('F225',      'R039'),
('F226',      'R039'),
('F227',      'R039'),

('F228',      'R040'),
('F214',      'R040'),
('F213',      'R040'),
('F218',      'R040'),
('F229',      'R040'),
('F146',      'R040'),

('F230',      'R041'),
('F231',      'R041'),
('F232',      'R041'),
('F233',      'R041'),
('F098',      'R041'),
('F160',      'R041'),

('F146',      'R042'),
('F234',      'R042'),
('F214',      'R042'),
('F235',      'R042'),
('F236',      'R042'),
('F227',      'R042'),

('F235',      'R043'),
('F214',      'R043'),
('F237',      'R043'),
('F238',      'R043'),
('F218',      'R043'),
('F227',      'R043'),

('F217',      'R044'),
('F239',      'R044'),
('F240',      'R044'),
('F241',      'R044'),
('F154',      'R044'),
('F160',      'R044'),

('F242',      'R045'),
('F243',      'R045'),
('F076',      'R045'),
('F244',      'R045'),
('F160',      'R045'),
('F073',      'R045'),

('F230',      'R046'),
('F245',      'R046'),
('F246',      'R046'),
('F247',      'R046'),
('F248',      'R046'),
('F249',      'R046')



]

#한식:T001 일식:T002  중식:T003  양식:T004  술집:T005  기타:T006
DATA_TABLES['RESTAURANT'] = [ #20ea
('고씨네',       'R001','T002','https://store.naver.com/restaurants/detail?id=37269016','6000~9500'),
('모모스테이크',  'R002','T004','https://store.naver.com/restaurants/detail?id=36412392','8500~16000'),
('천애부',       'R003','T002','https://m.store.naver.com/restaurants/detail?id=33875226','2000~9500'),
('일미닭갈비',    'R004','T001','https://m.store.naver.com/restaurants/detail?id=38485469','6900~14000'),
('유가네닭갈비',  'R005','T001','https://m.store.naver.com/restaurants/detail?id=21102801','4500~28000'),
('Mr.Chef Pocha','R006','T004','https://m.store.naver.com/restaurants/detail?id=21278958','9500~50000'),
('멘야고이치',    'R007','T002','https://m.store.naver.com/restaurants/detail?id=20322446','6500~7500'),
('밀플랜비',      'R008','T006','https://m.store.naver.com/restaurants/detail?id=38009073','3000~6000'),
('Mr.chef',      'R009','T001','https://m.store.naver.com/restaurants/detail?id=30811729','5500~8000'),
('봉구스밥버거',  'R010','T001','https://m.store.naver.com/restaurants/detail?id=31077787','1800~3500'),
('미스사이공',    'R011','T006','https://m.store.naver.com/restaurants/detail?id=38762477','3900~4900'),
('도담도담치킨',  'R012','T006','https://m.store.naver.com/restaurants/detail?id=36655478&entry=plt','15000~16000'),
('뽕스토리',      'R013','T003','https://m.store.naver.com/restaurants/detail?id=342201261','4500~35000'),
('알촌',          'R014','T001','https://m.store.naver.com/restaurants/detail?id=32848717','3500~4800'),
('벌집삼겹살',     'R015','T001','https://m.store.naver.com/restaurants/detail?id=19438153','3500~11900'),
('내가찜한닭',     'R016','T001','https://m.store.naver.com/restaurants/detail?id=33471257','17000~39000'),
('맛구단',         'R017','T001','https://m.search.naver.com/search.naver?where=m&sm=mtb_jum','2000~22000'),
('찌개백반',       'R018','T001','https://m.store.naver.com/restaurants/detail?id=18226632','5000~8000'),
('서울곱창',       'R019','T001','https://m.store.naver.com/restaurants/detail?id=18227763','17000~50000'),
('전설의치킨',     'R020','T001','https://m.store.naver.com/restaurants/detail?id=37811564','11000~1400'),
('반값소',         'R021','T001','https://m.store.naver.com/restaurants/detail?id=37592424','3000~39000'),
('푸드테라피',    'R022','T001','https://m.store.naver.com/restaurants/detail?id=33133453','5000~7000'),
('만고쿠',         'R023','T002','https://m.store.naver.com/restaurants/detail?id=37342139','4000~8000'),
('우만동족발집',    'R024','T001','https://m.store.naver.com/restaurants/detail?id=36424455','3000~36000'),
('소고',    'R025','T002','https://m.store.naver.com/restaurants/detail?id=35657866','9500~13000'),
('멘야고코로',    'R026','T002','https://m.store.naver.com/restaurants/detail?id=38346358','5900~7500'),
('키와마루아지',    'R027','T002','https://m.store.naver.com/restaurants/detail?id=37162932','9900~14000'),
('도꼬돈카츠',    'R028','T002','https://m.store.naver.com/restaurants/detail?id=33875226','6000~9000'),
('동떡이',    'R029','T001','https://m.store.naver.com/restaurants/detail?id=18242833','1500~6000'),
('시골집',    'R030','T001','https://m.store.naver.com/restaurants/detail?id=13560446','6000~8000'),
('광교반점',   'R031','T003','https://m.store.naver.com/restaurants/detail?id=37269538','5000~15000'),
('현경',     'R032','T003','https://m.store.naver.com/places/detail?id=437262373','8000~22000'),
('카페드로잉',   'R033','T004','https://m.store.naver.com/restaurants/detail?id=36561330','10000~20000'),
('바나나테이블',   'R034','T006','https://m.store.naver.com/restaurants/detail?id=36943345','13000~26000'),

('슈퍼스테이크',    'R035','T004','https://m.store.naver.com/restaurants/detail?id=37341816','6000~18000'),
('소마바이네이쳐',   'R036','T004','https://m.store.naver.com/restaurants/detail?id=36674562','16000~39000'),
('시카고피자',    'R037','T004','https://m.store.naver.com/restaurants/detail?id=37259982','12000~18000'),
('토끼정',    'R038','T001','https://m.store.naver.com/restaurants/detail?id=533097088','9000~14000'),
('갈릭 앤 모어',    'R039','T004','https://m.store.naver.com/restaurants/detail?id=968321089','9000~18000'),
('아날로그치킨',    'R040','T004','https://m.store.naver.com/restaurants/detail?id=37111515','15000~55000'),

('미스터시래기',    'R041','T001','https://m.store.naver.com/restaurants/detail?id=36561053','8000~19000'),
('더플레이스',    'R042','T004','https://m.store.naver.com/restaurants/detail?id=36900565','13000~43000'),
('오이탈리안',    'R043','T004','https://m.store.naver.com/restaurants/detail?id=38641900','7700~8800'),
('생어거스틴',    'R044','T004','https://m.store.naver.com/restaurants/detail?id=36624270','13000~19000'),
('매란방',    'R045','T003','https://m.store.naver.com/restaurants/detail?id=164938685','3000~19000'),
('풍원장',    'R046','T001','https://m.store.naver.com/restaurants/detail?id=37492092','15000~34000')



#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),
#('푸드테라피',    'R022','T001','https','5000~7000'),

]
#data insert----------------------------------------------------------------------------------------------
for name, insert_form in INSERT_TABLES.iteritems():
    try:
        print("Inserting tuples to TABLE({})\n".format(name), end='')
        for data in DATA_TABLES[name]: 
            try:
                cursor.execute(insert_form,data)
            except mysql.connector.Error as err:
                print("{}({})".format(err.msg,name))
    except mysql.connector.Error as err:
        if(err):
            print(err.msg)
        else:
            print("OK")

cursor.execute(enable_foreign) #foreign key constraint check
cnx.commit()


#query----------------------------------------------------------------------------------------------------



#print form----------------------------------------------------------------------------------------------

   
#operation-----------------------------------------------------------------------------------------------

    
#main-----------------------------------------------------------------------------------------------------


cursor.close()
cnx.close()