| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import os
- import sys
- import time
- import django
- import json
- local_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- print(local_path)
- if local_path not in sys.path:
- sys.path.append(local_path)
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kedong.settings")
- django.setup()
- from django.conf import settings
- from smartfarming.models.device import MongoDeviceType
- from smartfarming.models.user import UserPurview
- from smartfarming.models.pests_bank import MongoPestBank
- with open(os.path.join(local_path, "scripts/test/sa_device_type.json") , 'r', encoding='utf-8') as f:
- sa_device_type = json.load(f)
- for row in sa_device_type.get("rows"):
- device_type, is_created = MongoDeviceType.objects.get_or_create(
- id=row.get("id"),
- defaults=row
- )
- print(device_type.id, is_created)
- with open(os.path.join(local_path, "scripts/test/sa_user_purview.json") , 'r', encoding='utf-8') as f:
- sa_user_purview = json.load(f)
- for row in sa_user_purview.get("rows"):
- sa_user_purview, is_created = UserPurview.objects.get_or_create(
- id=row.get("id"),
- defaults=row
- )
- print(sa_user_purview.id, is_created)
- with open(os.path.join(local_path, "scripts/test/sa_pest_bank.json") , 'r', encoding='utf-8') as f:
- sa_pest_bank = json.load(f)
- for row in sa_pest_bank.get("rows"):
- sa_pest_bank, is_created = UserPurview.objects.get_or_create(
- id=row.get("id"),
- defaults=row
- )
- print(sa_pest_bank.id, is_created)
|