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

28 lines
837 B
Python
Raw Normal View History

2018-02-24 17:22:52 +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 SearchEngine
def import_file(filename):
with open(filename, mode='r') as file:
data = json.load(file)
for search_engine in data:
import_search_engine(search_engine["searchengine"])
def import_search_engine(engine):
search_engine = SearchEngine(
name=engine.get("name", ""),
url=engine.get("url", ""),
query_pattern=engine.get("query_pattern", "")
)
#print(search_engine)
search_engine.save()
class Command(BaseCommand):
def handle(self, *args, **kwargs):
import_file("data/search_engine.json")