mirror of
https://github.com/bellingcat/sugartrail.git
synced 2026-06-07 19:18:30 +03:00
move unserializable_attributes to static attribute
This commit is contained in:
@@ -2,7 +2,7 @@ import requests
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import functools
|
import functools
|
||||||
from ratelimit import limits, RateLimitException, sleep_and_retry
|
from ratelimit import limits, sleep_and_retry
|
||||||
|
|
||||||
access_token = ""
|
access_token = ""
|
||||||
username = ""
|
username = ""
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import sugartrail
|
|||||||
import IPython
|
import IPython
|
||||||
import json
|
import json
|
||||||
import functools
|
import functools
|
||||||
import pandas as pd
|
|
||||||
|
|
||||||
class Network:
|
class Network:
|
||||||
|
_unserialisable_attributes = ['hop', '_file', 'progress']
|
||||||
|
|
||||||
"""Class represents a network of connected companies, officers and
|
"""Class represents a network of connected companies, officers and
|
||||||
addresses. Class contains methods to build network of user defined size from
|
addresses. Class contains methods to build network of user defined size from
|
||||||
a single seed company, officer or address."""
|
a single seed company, officer or address."""
|
||||||
@@ -142,7 +143,7 @@ class Network:
|
|||||||
return company_table
|
return company_table
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def address(self, value):
|
def address(self):
|
||||||
"""address property representing seed address."""
|
"""address property representing seed address."""
|
||||||
return self._address
|
return self._address
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ class Network:
|
|||||||
|
|
||||||
def save(self, filename, location='../assets/networks/'):
|
def save(self, filename, location='../assets/networks/'):
|
||||||
"""Saves network in JSON format to '../assets/networks/'."""
|
"""Saves network in JSON format to '../assets/networks/'."""
|
||||||
network_data = {k: v for k, v in self.__dict__.items() if k not in ['hop', 'file', 'progress']}
|
network_data = {k: v for k, v in self.__dict__.items() if k not in self._unserialisable_attributes}
|
||||||
saved_network = json.dumps(network_data)
|
saved_network = json.dumps(network_data)
|
||||||
f = open(location + f'{filename}', 'w')
|
f = open(location + f'{filename}', 'w')
|
||||||
f.write(saved_network)
|
f.write(saved_network)
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
from ipywidgets import HTML, Widget, Layout, Output, VBox, HBox, Textarea
|
from ipywidgets import HTML, Widget, Layout, Output, VBox, HBox, Textarea
|
||||||
from ipyleaflet import Map, Marker, MarkerCluster, AwesomeIcon, AntPath, Popup
|
from ipyleaflet import Map, Marker, MarkerCluster, AwesomeIcon, AntPath, Popup
|
||||||
from datetime import datetime
|
|
||||||
import functools
|
import functools
|
||||||
import math
|
|
||||||
|
|
||||||
def build_map(network, clear_widget=True):
|
def build_map(network, clear_widget=True):
|
||||||
"""Generates map and table for displaying paths for input network data."""
|
"""Generates map and table for displaying paths for input network data."""
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from sugartrail import api
|
from sugartrail import api
|
||||||
import requests
|
import requests
|
||||||
import pandas as pd
|
|
||||||
import random
|
|
||||||
import urllib
|
import urllib
|
||||||
import regex as re
|
import regex as re
|
||||||
import collections
|
import collections
|
||||||
@@ -171,7 +169,6 @@ def build_address_history(company_id):
|
|||||||
addresses.append(entry)
|
addresses.append(entry)
|
||||||
return addresses
|
return addresses
|
||||||
else:
|
else:
|
||||||
address_history = []
|
|
||||||
entry = {}
|
entry = {}
|
||||||
for k, key in enumerate(["date_of_creation","date_of_cessation","registered_office_address"]):
|
for k, key in enumerate(["date_of_creation","date_of_cessation","registered_office_address"]):
|
||||||
if key in company_info:
|
if key in company_info:
|
||||||
@@ -184,7 +181,6 @@ def build_address_history(company_id):
|
|||||||
entry["lon"] = ""
|
entry["lon"] = ""
|
||||||
return [entry]
|
return [entry]
|
||||||
else:
|
else:
|
||||||
address_history = []
|
|
||||||
entry = {}
|
entry = {}
|
||||||
for k, key in enumerate(["date_of_creation","date_of_cessation","registered_office_address"]):
|
for k, key in enumerate(["date_of_creation","date_of_cessation","registered_office_address"]):
|
||||||
if key in company_info:
|
if key in company_info:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import sugartrail
|
|
||||||
import IPython
|
import IPython
|
||||||
|
|
||||||
class Progress:
|
class Progress:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import sugartrail
|
import sugartrail
|
||||||
import pytest
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# test 1: network initialised without auth and without arguments:
|
# test 1: network initialised without auth and without arguments:
|
||||||
@@ -47,7 +46,7 @@ def test_file_init_without_auth():
|
|||||||
with open('./assets/networks/domain_corp_network.json') as f:
|
with open('./assets/networks/domain_corp_network.json') as f:
|
||||||
network_json = json.load(f)
|
network_json = json.load(f)
|
||||||
for key in network.__dict__.keys():
|
for key in network.__dict__.keys():
|
||||||
if key not in ['hop', '_file', 'progress']:
|
if key not in sugartrail.base.Network._unserialisable_attributes:
|
||||||
assert network.__dict__[key] == network_json[key]
|
assert network.__dict__[key] == network_json[key]
|
||||||
|
|
||||||
# test 5: network loads network from file without auth:
|
# test 5: network loads network from file without auth:
|
||||||
@@ -58,5 +57,5 @@ def test_file_load_without_auth():
|
|||||||
with open('./assets/networks/domain_corp_network.json') as f:
|
with open('./assets/networks/domain_corp_network.json') as f:
|
||||||
network_json = json.load(f)
|
network_json = json.load(f)
|
||||||
for key in network.__dict__.keys():
|
for key in network.__dict__.keys():
|
||||||
if key not in ['hop', '_file', 'progress']:
|
if key not in sugartrail.base.Network._unserialisable_attributes:
|
||||||
assert network.__dict__[key] == network_json[key]
|
assert network.__dict__[key] == network_json[key]
|
||||||
|
|||||||
Reference in New Issue
Block a user