Skip to content

Commit

Permalink
fixed issues in accounts with little info
Browse files Browse the repository at this point in the history
  • Loading branch information
Allexio committed Mar 26, 2021
1 parent 8d6648d commit b0bb22a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/fb_data_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ def main():
# Gets both half the screen width/height and window width/height
positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2 - 300)
positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)

# Positions the window in the center of the page.
root.geometry("+{}+{}".format(positionRight, positionDown))

showinfo("Facebook Data Analyser Startup", welcome_message)
showinfo("Info", "Please select your Facebook zip file...")
update_status("Selecting a Facebook data zip file", status, root)
zip_path = file_picker()

info_text["text"] = "The tool is now running, this can take up to a few minutes, depending on the amount of data and speed of your computer."

update_status("Unzipping Facebook data archive", status, root)
Expand All @@ -101,7 +101,7 @@ def main():
update_status("Validating Data", status, root)
validate_uploaded_data()
update_progress(progress, 5, root)

# Parse data starting here
user_data = {}

Expand Down
9 changes: 6 additions & 3 deletions src/parser_facebook_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
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"]

try:
ad_interactions_list = utils.json_file_converter(ad_interactions_path)["history"]
except FileNotFoundError:
user_data["nbr_of_ads_clicked"] = "0"
return user_data

number_of_ads_clicked = len(ad_interactions_list)

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

return user_data


13 changes: 10 additions & 3 deletions src/parser_friends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ def parse_friends(user_data: dict) -> dict:
removed_friends_path = getcwd() + "/temp/friends/removed_friends.json"

friends_list = utils.json_file_converter(friends_path)
removed_friends_list = utils.json_file_converter(removed_friends_path)


friends_total = len(friends_list["friends"])
removed_friends_total = len(removed_friends_list["deleted_friends"])


user_data["nbr_of_friends"] = utils.number_prettify(friends_total)

try:
removed_friends_list = utils.json_file_converter(removed_friends_path)
except:
user_data["nbr_of_removed_friends"] = "0"
return user_data

removed_friends_total = len(removed_friends_list["deleted_friends"])
user_data["nbr_of_removed_friends"] = utils.number_prettify(removed_friends_total)

return user_data
6 changes: 5 additions & 1 deletion src/parser_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
def parse_location_history(user_data: dict) -> dict:
""" Goes through locations and translates a list of locations into html string """
locations_path = getcwd() + "/temp/location/location_history.json"
location_list = utils.json_file_converter(locations_path)["location_history"]
try:
location_list = utils.json_file_converter(locations_path)["location_history"]
except FileNotFoundError:
user_data["location_pings"] = "nodata"
return user_data

html_start = "L.marker(["
html_mid = "]).addTo(mymap).bindPopup(\""
Expand Down
12 changes: 8 additions & 4 deletions src/parser_profile_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ def parse_user_info(user_data: dict) -> dict:
profile_data = info["profile"]
user_name = profile_data["name"]["full_name"]
join_year = utils.epoch_to_year(profile_data["registration_timestamp"])
relationship_status = profile_data["relationship"]["status"]
if "partner" in profile_data["relationship"]:
relationship_status += " with " + profile_data["relationship"]["partner"]
relationship_timestamp = utils.epoch_to_year(profile_data["relationship"]["timestamp"])
if "relationship" in profile_data:
relationship_status = profile_data["relationship"]["status"]
if "partner" in profile_data["relationship"]:
relationship_status += " with " + profile_data["relationship"]["partner"]
relationship_timestamp = utils.epoch_to_year(profile_data["relationship"]["timestamp"])
else:
relationship_status = "No data"
relationship_timestamp = "No data"

# instantiate a list of years [1996, 1997, 1998, ... , 2021]
current_year = datetime.date.today().year
Expand Down
4 changes: 2 additions & 2 deletions src/parser_profile_picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def profile_picture_mover():
profile_pictures_path = ""
for path in listdir(photos_path):
#print(path)
if "ProfilePictures" in path or "Photosdeprofil" in path:
if "profilepictures" in path.lower() or "photosdeprofil" in path.lower():
profile_pictures_path = path
break

Expand All @@ -21,4 +21,4 @@ def profile_picture_mover():
print("Found user profile picture in " + latest_profile_picture_path)
print("Moving user profile picture to " + generated_profile_picture_path)

copyfile(latest_profile_picture_path, generated_profile_picture_path)
copyfile(latest_profile_picture_path, generated_profile_picture_path)
2 changes: 1 addition & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def json_file_converter(file_path: str) -> dict:
""" Opens a json file and returns a corresponding python list or dictionary object """
with open(file_path, "r") as json_file:
with open(file_path, "r", encoding="utf8") as json_file:
json_str = json_file.read()
python_str = json_str.replace("true", "True").replace("false", "False").replace("null", "None")
python_dict = literal_eval(python_str)
Expand Down

0 comments on commit b0bb22a

Please sign in to comment.