Skip to content

Commit

Permalink
normalize AF models.
Browse files Browse the repository at this point in the history
  • Loading branch information
98jfran committed May 6, 2020
1 parent 44aa440 commit 3f3dcfe
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 307 deletions.
19 changes: 19 additions & 0 deletions modules/report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from package.utils import Utils
from package.models import Timeline, Location, Media

class ModuleParent:
def __init__(self, internal_path, external_path, report_path, app_name, app_id):
Expand Down Expand Up @@ -52,3 +53,21 @@ def set_header(self):

def generate_report(self):
raise NotImplementedError

def add_model(self, model, model_arg=False, my_model=""):

if isinstance(model, Timeline):
self.report["AF_timeline"] = model.get_sorted_timeline(model_arg)
return

if isinstance(model, Media):
self.report["AF_media"] = model.get_media()
return

if isinstance(model, Location):
self.report["AF_location"] = model.get_sorted_locations(model_arg)
return

self.report[my_model] = model


9 changes: 5 additions & 4 deletions modules/report/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from package.database import Database
from package.utils import Utils
from package.models.timeline import Timeline
from package.models.media import Media
from package.models import Timeline, Location, Media
from modules.report import ModuleParent


class ModuleReport(ModuleParent):
def __init__(self, internal_path, external_path, report_path, app_name, app_id):
ModuleParent.__init__(self, internal_path, external_path, report_path, app_name, app_id)
Expand All @@ -27,8 +27,9 @@ def generate_report(self):
self.report["videos"] = self.get_videos()
self.report["published_videos"] = self.get_videos_publish()
self.report["log"] = self.get_last_session()
self.report["timeline"] = self.timeline.get_sorted_timeline()
self.report["media"] = self.media.get_media()

self.add_model(self.timeline)
self.add_model(self.media)

logging.info("Report Generated")

Expand Down
10 changes: 4 additions & 6 deletions modules/report/tinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from package.database import Database
from package.utils import Utils
from modules.report import ModuleParent
from package.models.timeline import Timeline
from package.models.location import Location
from package.models.media import Media
from package.models import Timeline, Location, Media

class ModuleReport(ModuleParent):
def __init__(self, internal_path, external_path, report_path, app_name, app_id):
Expand All @@ -30,9 +28,9 @@ def generate_report(self):
self.report["messages"] = self.get_user_messages()
self.report["credit_cards"] = self.get_credit_cards()
self.report["locations"] = self.get_locations()
self.report["timeline"] = self.timeline.get_sorted_timeline()
self.report["tracking"] = self.locations.get_sorted_locations()
self.report["media"] = self.media.get_media()
self.add_model(self.timeline)
self.add_model(self.locations)
self.add_model(self.media)

logging.info("Report Generated")

Expand Down
61 changes: 61 additions & 0 deletions package/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os

class Location:
def __init__(self):
self.locations = []

def add(self, timestamp=0, latitude=0, longitude=0, altitude=0):
entry = {
"timestamp": timestamp,
"latitude": latitude,
"longitude": longitude,
"altitude" : altitude
}
self.locations.append(entry)

def get_value(self, entry):
try:
return int(entry['timestamp'])
except KeyError:
return 0

def get_sorted_locations(self, reverse=False):
self.locations.sort(key=self.get_value, reverse=reverse)
return self.locations


class Media:
def __init__(self):
self.media = []

def add(self, path, from_web=False):
if not from_web:
path = os.path.join("Contents", path)

self.media.append(path)

def get_media(self):
return self.media

class Timeline:
def __init__(self):
self.timeline = []

def add(self, timestamp, event, obj):
entry = {
"timestamp": timestamp,
"event": str(event),
"value": obj
}
self.timeline.append(entry)

def get_value(self, entry):
try:
return int(entry['timestamp'])
except KeyError:
return 0

def get_sorted_timeline(self, reverse=False):
self.timeline.sort(key=self.get_value, reverse=reverse)
return self.timeline

Empty file removed package/models/__init__.py
Empty file.
25 changes: 0 additions & 25 deletions package/models/location.py

This file was deleted.

15 changes: 0 additions & 15 deletions package/models/media.py

This file was deleted.

24 changes: 0 additions & 24 deletions package/models/timeline.py

This file was deleted.

Loading

0 comments on commit 3f3dcfe

Please sign in to comment.