mpri-webdam/profiles/management/commands/import_places.py

28 lines
769 B
Python
Raw Normal View History

2018-02-24 17:21:41 +01:00
""" Small module that import browser fingerprints into the databose,
based on the data listed in https://huit.re/user-agent-json.
"""
import json
from django.core.management.base import BaseCommand
from django.db import models
from profiles.models import Place
def import_file(filename):
with open(filename, mode='r') as file:
data = json.load(file)
for place in data:
import_place(place["place"])
def import_place(_place):
place = Place(
name=_place.get("name", ""),
address=_place.get("address", ""),
lat=float(_place.get("lat", 0)),
lon=float(_place.get("lon", 0))
)
place.save()
class Command(BaseCommand):
def handle(self, *args, **kwargs):
import_file("data/place.json")