#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys, django
sys.path.append(".")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
django.setup()
from brand.models import *
import json
class ProductDB():
def __init__(self, model):
self.model = model
def create(self, pid, cat1id, cat2id, cat3id, pname, brand, imgurl):
if self.model == Product:
p = Product(pid=pid, cat1id=cat1id, cat2id=cat2id, cat3id=cat3id, pname=pname, brand=brand, imgurl=imgurl)
p.save()
class DataFile():
def __init__(self, fp):
self.f = open(fp, 'r')
def read(self):
line = self.f.readline().strip()
return line
def json_data(self):
line = self.f.readline().strip()
data = json.loads(line)
return data
def main():
data_dir = "./data/json.txt"
f = DataFile(data_dir)
while(True):
data = f.json_data()
if not data: break
pid = data['id']
cat1id = data['category1Id']
cat2id = data['category2Id']
cat3id = data['category3Id']
pname = data['productName']
brand = data['brand']
imgurl = data['imageUrl']
p = ProductDB(Product)
p.create(pid, cat1id, cat2id, cat3id, pname, brand, imgurl)
####################################################
# main
####################################################
if __name__ == '__main__':
main()
'Programming > Django' 카테고리의 다른 글
[Django CSS] Bootstrap Templates (0) | 2018.09.07 |
---|---|
[Django CSS] Bootstrap Pagination (0) | 2018.09.06 |
[Django CSS] Bootstrap Dropdowns (0) | 2018.09.06 |
[Django CSS] 장고 CSS로 테이블 꾸미기 (0) | 2018.08.31 |
[Django Paginator] 장고 paginator로 페이지 생성 (0) | 2018.07.12 |