-
Notifications
You must be signed in to change notification settings - Fork 3
Add modules utils under mix_utils folder to avoid duplication in JSON… #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5466c19
Add modules utils under mix_utils folder to avoid duplication in JSON…
fabrizio-turchi 6a14af9
Fix #22 issue, adding BrowserBookmarkFacet to observable module
fabrizio-turchi f33a8f5
Fix #3 issue, changing uco-tool:creator property as a reference to an…
fabrizio-turchi bb70ee7
Fix #13 issue, replacing EventFacet class with EventRecordFacet class
fabrizio-turchi fc0ac4d
Change .gitignore to ignore the .pyc files nad the __pycache__ folder
fabrizio-turchi 1e33b70
Add type checking to mix_utils/util-py module
fabrizio-turchi 0a491b8
Remove AdjustDate class, useful only for UFED parser, and white spac…
fabrizio-turchi ea81a41
Change structure mix_utils/utils.py module. Add test_duplicate.py for…
fabrizio-turchi 1d97f40
Enable CI on pull requests
ajnelson-nist 6ebfcc7
Apply formatting
ajnelson-nist 169c32b
Fix #12 issue, changing FacetUrlHistory and UrlHistoryEntry classes
fabrizio-turchi df8c25e
Reformatted example.py
fabrizio-turchi e888d6f
Apply formatting
ajnelson-nist 05d7684
Deactivate validation report
ajnelson-nist 26a516f
Fix data typing
ajnelson-nist 2d48c7f
Reformatted line by Flake by CI action
fabrizio-turchi fb64867
Apply Python and JSON-LD type-review for coordinates
ajnelson-nist 947307d
Change argument-list type
ajnelson-nist 3123a35
Type-annotate mix_utils directory
ajnelson-nist e72002e
Link Issue
ajnelson-nist 6aaa572
Regenerate Make-managed file
ajnelson-nist 491c4f8
Integrate mix_utils directory into package
ajnelson-nist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
.venv/ | ||
venv/ | ||
|
||
*wpr | ||
*wpu | ||
# Build Artifacts | ||
build/ | ||
dist/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import re | ||
from datetime import datetime | ||
|
||
class CheckDuplicate(): | ||
"""It aims to avoid duplication in the JSON/CASE file generated by the parsers (UFED, AXIOM etc.) | ||
""" | ||
|
||
def check_value(self, *args, value=None, list_values=None, list_objects=None, observable_generating_f=None): | ||
"""It checks if a specific value has been already generated related to an ObservableObject relying on | ||
the list of its values. This is meant to avoid duplication in the JSON/CASE file generated by the | ||
parsers (UFED, AXIOM etc.). | ||
If the value is not in the list_values, a new ObservableObject is generated by using the function | ||
observable_generating_f that returns, as a result, the new ObservableObject (e.g. uco-observable:ApplicationFacet, | ||
uco-observable:AccountFacet, uco-location:LatLongCoordinatesFacet: drafting:SearchedItemFacet, "uco-observable:URLFacet, | ||
uco-observable:ApplicationAccountFacet, uco-observable:DigitalAccountFacet, uco-observable:PhoneAccountFacet). | ||
|
||
Finally the new ObservableObject is added to the list_objects (any kind of ObservableObject maintains a different list). | ||
If the value is already in the list_values, the ObservableObject list_objects[index] is returned. | ||
|
||
:param value: the value to be checked within the list_values | ||
:param list_values: the current list of values | ||
:param list_objects: the current list of a specific kind of ObservableObject | ||
:param observable_generating_f: the function that will generate the corresponding kind of ObservableObject | ||
:param *args: the actual parameter of the observable_generating_f function | ||
:return: an Observableobject of a specific kind depending by the actual parameters | ||
""" | ||
if value in list_values: | ||
idx = list_values.index(value) | ||
observable_app = list_objects[idx] | ||
else: | ||
observable_app = observable_generating_f(*args) | ||
list_values.append(value) | ||
list_objects.append(observable_app) | ||
|
||
return observable_app | ||
|
||
class AdjustText(): | ||
"""It amends the data to either make it homogeneous or get rid of some dirty chracters extracted from the XML reports. | ||
""" | ||
def adjust_date(self, original_date=''): | ||
""" | ||
Amend the original date to convert it into a uniform format. The xsd:dateTime will have the format | ||
YYYY-MM-DDTHH:MM:SS(+HH:MM). | ||
""" | ||
aMonths = { | ||
'Jan': '01', | ||
'Feb': '02', | ||
'Mar': '03', | ||
'Apr': '04', | ||
'May': '05', | ||
'Jun': '06', | ||
'Jul': '07', | ||
'Aug': '08', | ||
'Sep': '09', | ||
'Oct': '10', | ||
'Nov': '11', | ||
'Dec': '12' | ||
} | ||
|
||
chars_to_replace = { | ||
"/" : "-", | ||
"(" : "-", | ||
")" : "-", | ||
'UTC': '', | ||
'AM': '', | ||
'PM': '' | ||
} | ||
|
||
uniform_date = original_date.strip() | ||
|
||
if uniform_date == '': | ||
return None | ||
|
||
for k,v in aMonths.items(): | ||
if uniform_date.find(k) > -1: | ||
uniform_date = uniform_date.replace(k, v) | ||
break | ||
for k,v in chars_to_replace.items(): | ||
uniform_date = uniform_date.replace(k, v) | ||
|
||
uniform_date = uniform_date.replace(' ', 'T', 1) | ||
|
||
if re.search('^[0-9]{4}', uniform_date): | ||
pass | ||
else: | ||
# when uniform_date is in Italian formato and the Year is placed before 'T' and | ||
# composed of two digits, i.e. Year=YY | ||
uniform_date = re.sub('-([0-9][0-9])T', '-20\g<1>T', uniform_date) | ||
uniform_date = str(uniform_date[6:10]) + uniform_date[2:6] + uniform_date[0:2] + \ | ||
uniform_date[10:] | ||
|
||
#start_tz = uniform_date.find("+") | ||
#if start_tz > -1: | ||
# uniform_date = uniform_date[:start_tz] | ||
|
||
date_chars = uniform_date[:10] # YYYY-MM-DD | ||
date_chars = date_chars.replace(".", "-") | ||
uniform_date = date_chars + uniform_date[10:] | ||
|
||
#if uniform_date[-1] == '-': | ||
# uniform_date = uniform_date[0:-1] | ||
|
||
uniform_date = uniform_date.replace('.000', '').replace('.', ':') | ||
|
||
uniform_date = uniform_date.replace('.', ':') | ||
|
||
if re.search('T\d{2}\.', uniform_date): | ||
uniform_date = uniform_date.replace('.', ':') | ||
|
||
if re.search('(\d{2}:\d{2}:\d{2})$', uniform_date): | ||
pass | ||
else: | ||
uniform_date = re.sub('(\d{2}:\d{2})$', '\g<1>:00', uniform_date) | ||
|
||
if re.search('T(\d):', uniform_date): | ||
uniform_date = re.sub('T(\d):', 'T0\g<1>:', uniform_date) | ||
|
||
if re.search(':(\d)', uniform_date): | ||
uniform_date = re.sub(':(\d):', ':0\g<1>', uniform_date) | ||
|
||
if re.search('T\d{2}:\d{2}:\d{2}(.+)$', uniform_date): | ||
uniform_date = re.sub('(T\d{2}:\d{2}:\d{2})(.+)$', '\g<1>', uniform_date) | ||
|
||
|
||
if uniform_date.find('+') > -1: | ||
uniform_date = datetime.strptime(uniform_date, | ||
'%Y-%m-%dT%H:%M:%S.%f%z') | ||
else: | ||
uniform_date = datetime.strptime(uniform_date, | ||
'%Y-%m-%dT%H:%M:%S') | ||
|
||
return uniform_date | ||
|
||
def adjust_json(self, original_json=''): | ||
""" | ||
It gets rid of some dirty characters not allowd in the JSON values. | ||
""" | ||
chars_to_replace = { | ||
'"' : '', | ||
'\n' : '', | ||
'\r' : '', | ||
'\t': '', | ||
"\\'": '', | ||
'\\': '' | ||
} | ||
conform_json = original_json.strip() | ||
|
||
for k,v in chars_to_replace.items(): | ||
conform_json = conform_json.replace(k, v) | ||
|
||
return conform_json |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.