Skip to content

Commit

Permalink
first stable version of tracking page
Browse files Browse the repository at this point in the history
  • Loading branch information
Allexio committed Mar 22, 2021
1 parent 374b533 commit 25e2c10
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 16 deletions.
2 changes: 1 addition & 1 deletion report_template/assets/scripts/main.js

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions report_template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,6 @@
</div>
</div>
</div>
<div class="d-xl-none d-lg-block col-md-6 col-xl-4">
<div class="card mb-3 widget-content bg-premium-dark">
<div class="widget-content-wrapper text-white">
<div class="widget-content-left">
<div class="widget-heading">Products Sold</div>
<div class="widget-subheading">Revenue streams</div>
</div>
<div class="widget-content-right">
<div class="widget-numbers text-warning"><span>$14M</span></div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-lg-12">
Expand Down
2 changes: 1 addition & 1 deletion report_template/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -14549,7 +14549,7 @@ legend {
}

.scroll-area-sm {
height: 200px;
height: 400px;
overflow-x: hidden
}

Expand Down
213 changes: 213 additions & 0 deletions report_template/tracking.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Language" content="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FB Data Analysis Report</title>
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
<meta name="description" content="Report containing information downloaded from your facebook account.">
<meta name="msapplication-tap-highlight" content="no">
<!--
=========================================================
* ArchitectUI HTML Theme Dashboard - v1.0.0
=========================================================
* Product Page: https://dashboardpack.com
* Copyright 2019 DashboardPack (https://dashboardpack.com)
* Licensed under MIT (https://github.com/DashboardPack/architectui-html-theme-free/blob/master/LICENSE)
=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-->
<link href="./main.css" rel="stylesheet">
</head>

<body>
<div class="app-container app-theme-white body-tabs-shadow fixed-sidebar fixed-header">
<div class="app-header header-shadow">
<div class="app-header__logo">
<div class="logo-src"></div>
<div class="header__pane ml-auto">
</div>
</div>
<div class="app-header__mobile-menu">
<div>
<button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
</div>
</div>
<div class="app-header__menu">
<span>
<button type="button"
class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
<span class="btn-icon-wrapper">
<i class="fa fa-ellipsis-v fa-w-6"></i>
</span>
</button>
</span>
</div>
<div class="app-header__content">
<div class="app-header-right">
<div class="widget-content-left">
<img width="60" class="rounded-circle" src="assets/images/user.jpg" alt="">
</div>
<div class="widget-content-left ml-3 header-user-info">
<div class="widget-heading">
{user_name}
</div>
<div class="widget-subheading">
Member since {join_year}
</div>
</div>
</div>
</div>
</div>
<div class="app-main">
<div class="app-sidebar sidebar-shadow">
<div class="app-header__logo">
<div class="logo-src"></div>
<div class="header__pane ml-auto">
<div>
<button type="button" class="hamburger close-sidebar-btn hamburger--elastic"
data-class="closed-sidebar">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
</div>
</div>
</div>
<div class="app-header__mobile-menu">
<div>
<button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
</div>
</div>
<div class="app-header__menu">
<span>
<button type="button"
class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
<span class="btn-icon-wrapper">
<i class="fa fa-ellipsis-v fa-w-6"></i>
</span>
</button>
</span>
</div>
<div class="scrollbar-sidebar">
<div class="app-sidebar__inner">
<ul class="vertical-nav-menu">
<li class="app-sidebar__heading">Navigation</li>
<li>
<a href="index.html">
<i class="metismenu-icon pe-7s-user"></i>
Main Dashboard
</a>
<li>
<a href="location.html">
<i class="metismenu-icon pe-7s-world">
</i>Location
</a>
</li>
<li>
<a href="photos.html">
<i class="metismenu-icon pe-7s-camera">
</i>Photos
</a>
</li>
<li>
<a href="tracking.html" class="mm-active">
<i class="metismenu-icon pe-7s-target">
</i>Tracking
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="app-main__outer">
<div class="app-main__inner">
<div class="row">
<div class="col-md-12 col-lg-12">
<div class="main-card mb-3 card">
<div class="card-body">
<h5 class="card-title">Interests</h5>
</div>
<div class="row">
<div class="col-md-8 col-lg-8">
<canvas id="radar-chart"></canvas>
</div>
<div class="col-md-4 col-lg-4">
<h6 class="text-muted text-uppercase font-size-md opacity-5 font-weight-normal">
Interest list</h6>
<div class="scroll-area-sm">
<div class="scrollbar-container">
<ul
class="rm-list-borders rm-list-borders-scroll list-group list-group-flush">
{html_interests}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xl-4">
<div class="card mb-3 widget-content bg-deep-blue">
<div class="widget-content-wrapper text-white">
<div class="widget-content-left">
<div class="widget-heading">Ads clicked</div>
<div class="widget-subheading">Number of ads clicked on Facebook, some more than once.</div>
</div>
<div class="widget-content-right">
<div class="widget-numbers"><span>{nbr_of_ads_clicked}</span></div>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-xl-4">
<div class="card mb-3 widget-content bg-deep-blue">
<div class="widget-content-wrapper text-white">
<div class="widget-content-left">
<div class="widget-heading">Websites selling your data to Facebook</div>
<div class="widget-subheading">Number of websites selling data about you to Facebook</div>
</div>
<div class="widget-content-right">
<div class="widget-numbers"><span>{nbr_of_websites_tracking}</span></div>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-xl-4">
<div class="card mb-3 widget-content bg-deep-blue">
<div class="widget-content-wrapper text-white">
<div class="widget-content-left">
<div class="widget-heading">Applications selling your data to Facebook</div>
<div class="widget-subheading">Number of phone applications selling data about you to Facebook</div>
</div>
<div class="widget-content-right">
<div class="widget-numbers"><span>{nbr_of_applications_tracking}</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="./assets/scripts/main.js"></script>
</body>

</html>
15 changes: 15 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import time
import shutil
import webbrowser
from parser_facebook_ads import parse_ad_interactions
from parser_interests import parse_interests
from parser_off_facebook_tracking import parse_off_facebook_activities
from parser_profile_info import parse_user_info
from parser_friends import parse_friends
from parser_messages import parse_messages
Expand Down Expand Up @@ -82,6 +85,18 @@ def main():
user_data = parse_user_info(user_data)
update_progress(progress, 5, root)

update_status("Parsing Off-Facebook activities", status, root)
user_data = parse_off_facebook_activities(user_data)
update_progress(progress, 5, root)

update_status("Parsing advertisement interactions", status, root)
user_data = parse_ad_interactions(user_data)
update_progress(progress, 5, root)

update_status("Parsing Interests", status, root)
user_data = parse_interests(user_data)
update_progress(progress, 5, root)

update_status("Parsing Messages", status, root)
user_data = parse_messages(user_data)
update_progress(progress, 5, root)
Expand Down
15 changes: 15 additions & 0 deletions src/parser_facebook_ads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import utils
from os import getcwd

def parse_ad_interactions(user_data: dict) -> dict:
""" Goes through your ad interaction data and parses the number of ad clicks """
ad_interactions_path = getcwd() + "/temp/ads_and_businesses/advertisers_you've_interacted_with.json"
ad_interactions_list = utils.json_file_converter(ad_interactions_path)["history"]

number_of_ads_clicked = len(ad_interactions_list)

user_data["nbr_of_ads_clicked"] = utils.number_prettify(number_of_ads_clicked)

return user_data


56 changes: 56 additions & 0 deletions src/parser_interests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import utils
from os import getcwd

def parse_interests(user_data: dict) -> dict:
""" Goes through interests and parses number of interest per category """
interests_path = getcwd() + "/temp/ads_and_businesses/ads_interests.json"
interest_categories_path = getcwd() + "/src/interests.json"

user_interests = utils.json_file_converter(interests_path)["topics"]
interest_categories = utils.json_file_converter(interest_categories_path)

interest_category_count = {}
interest_category_total = {}

category_list = list(interest_categories.keys())

for category in category_list:
interest_category_count[category] = 0
interest_category_total[category] = 0

for category in category_list:
for interest in interest_categories[category]:
interest_category_total[category] += 1
if interest in user_interests:
interest_category_count[category] += 1

# standardise results by dividing by total number of interests per category
for category in category_list:
interest_category_count[category] = int((interest_category_count[category] / interest_category_total[category]) * 100)

# transform to list
interest_count_list = list(interest_category_count.values())

print("interest_category_count: ", interest_category_count)

# build a html interest string for the side list of interests
html_interests = html_interest_list_builder(user_interests, interest_categories)

user_data["interest_categories"] = category_list
user_data["interest_count"] = interest_count_list
user_data["html_interests"] = html_interests

return user_data

def html_interest_list_builder(user_interests: list, interest_categories: dict) -> str:
""" Takes a list of user interests and the interest categories dict, and produces a string in HTML format of user interests """
start_html = """<li class="list-group-item"><div class="widget-content p-0"><div class="widget-content-wrapper"><div class="widget-content-left"><div class="widget-heading">"""
mid_html = """</div><div class="widget-subheading">"""
end_html = """</div></div></div></div></li>"""

html_interests = ""

for interest in user_interests:
html_interests += start_html + interest + mid_html + "other" + end_html

return html_interests
21 changes: 21 additions & 0 deletions src/parser_off_facebook_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import utils
from os import getcwd

def parse_off_facebook_activities(user_data: dict) -> dict:
""" Goes through off_facebook_activities and parses number of websites and applications that hand over your data to Facebook """
off_facebook_activities_path = getcwd() + "/temp/ads_and_businesses/your_off-facebook_activity.json"
off_facebook_activity_list = utils.json_file_converter(off_facebook_activities_path)["off_facebook_activity"]

number_of_websites_tracking_the_user = 0
number_of_applications_tracking_the_user = 0

for tracking_entity in off_facebook_activity_list:
if "." in tracking_entity["name"]: # if there's a full stop, assume it's a website and not an application
number_of_websites_tracking_the_user += 1
else:
number_of_applications_tracking_the_user += 1

user_data["nbr_of_websites_tracking"] = utils.number_prettify(number_of_websites_tracking_the_user)
user_data["nbr_of_applications_tracking"] = utils.number_prettify(number_of_applications_tracking_the_user)

return user_data
2 changes: 1 addition & 1 deletion src/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def generate_report(user_data: dict):
html_str = html_file.read()
# replace keywords with actual values
generated_html = keyword_replacer(user_data, html_str)
with open(generated_dir+"/"+file_path, "w") as html_file:
with open(generated_dir+"/"+file_path, "w", encoding="utf8") as html_file:
html_file.write(generated_html)

# also replace keywords in the script file
Expand Down

0 comments on commit 25e2c10

Please sign in to comment.