Command to add browser fingerprint data

This commit is contained in:
Rémi Oudin 2018-02-21 16:50:27 +01:00
parent cd4d8a4c3f
commit ad0ad0a783
4 changed files with 6135 additions and 0 deletions

6094
data/user-agent.json Normal file

File diff suppressed because it is too large Load Diff

View File

View File

View File

@ -0,0 +1,41 @@
""" 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 BrowserFingerprint
def import_file(filename):
with open(filename, mode='r') as file:
data = json.load(file)
data = data[0]["list"]
for os_agent in data:
for useragent in os_agent["useragents"]:
import_useragent(useragent)
def import_useragent(useragent):
fingerprint = BrowserFingerprint(
description=useragent.get("description", ""),
useragent=useragent.get("useragent", ""),
appname=useragent.get("appname", ""),
appversion=useragent.get("appversion", ""),
platform=useragent.get("appversion", ""),
vendor=useragent.get("vendor", ""),
vendorsub=useragent.get("vendorsub", ""),
buildID=useragent.get("buildID", ""),
oscpu=useragent.get("oscpu", ""),
accept_encoding=useragent.get("accept_encoding", ""),
accept_default=useragent.get("accept_default", ""),
accept_lang=useragent.get("accept_lang", ""),
pixeldepth=int(useragent.get("pixeldepth", 0)),
colordepth=int(useragent.get("colordepth", 0)),
screens=useragent.get("screen", ""),
)
print(fingerprint)
fingerprint.save()
class Command(BaseCommand):
def handle(self, *args, **kwargs):
import_file("data/user-agent.json")