Skip to content
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

Snapchat location data gawen #53

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/activities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod facebook;
pub mod google;
pub mod snapchat;

pub use facebook::*;
pub use google::*;
pub use snapchat::*;
3 changes: 3 additions & 0 deletions src/activities/snapchat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod snapchat_areas_visited_history;

pub use snapchat_areas_visited_history::*;
75 changes: 75 additions & 0 deletions src/activities/snapchat/snapchat_areas_visited_history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use rusqlite::{params, Connection};
use serde::Deserialize;
use uuid::Uuid;

#[rustfmt::skip]
#[allow(non_snake_case)]
#[derive(Deserialize, Debug)]
pub struct GeneralStructure {
#[serde(rename = "Areas you may have visited in the last two years")]
pub areas: Vec<SmallerStructure>
}
#[rustfmt::skip]
#[allow(non_snake_case)]
#[derive(Deserialize, Debug)]
pub struct SmallerStructure {
pub Time: String,
pub City: String,
pub Region: String,
#[serde(rename = "Postal Code")]
pub Postal: String

}

#[allow(non_snake_case)]
impl GeneralStructure {
pub fn saveToDb(&self, conn: &Connection) -> Result<(), rusqlite::Error> {
for elem in self.areas.iter() {
let my_uuid = Uuid::new_v4();
conn.execute(
"INSERT INTO snapchat_areas_visited_history (
uuid,
Time,
City,
Region,
Postal_Code
)
VALUES (?1, ?2, ?3, ?4, ?5)",
params![
&my_uuid.to_string(),
&elem.Time,
&elem.City,
&elem.Region,
&elem.Postal
],
)
.map_err(|err| println!("{:?}", err))
.ok();
}
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use rusqlite::Connection;
#[test]
fn test_snapchat_areas_visited_history() -> Result<(), Box<dyn std::error::Error>> {
let conn = Connection::open("ichnion.db")?;
let smaller_test = SmallerStructure {
Time: "2021/02/12 11:51:31 UTC".to_string(),
City: "Paris".to_string(),
Region: "Ile - De - France".to_string(),
Postal: "75000".to_string(),
};
let general_test = GeneralStructure {
areas: vec![smaller_test],
};
let result = GeneralStructure::saveToDb(&general_test, &conn);

assert_eq!(result, Ok(()));

Ok(())
}
}
14 changes: 14 additions & 0 deletions src/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,18 @@ pub fn create_tables(conn: &Connection) {
)
.map_err(|err| println!("{:?}", err))
.ok();

// snapchat_location_history
conn.execute(
"CREATE TABLE IF NOT EXISTS snapchat_areas_visited_history (
uuid TEXT NOT NULL PRIMARY KEY,
Time TEXT,
City TEXT,
Region TEXT,
Postal_Code TEXT
)",
NO_PARAMS,
)
.map_err(|err| println!("{:?}", err))
.ok();
}
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use excavator::activities::facebook::facebook_last_location;
use excavator::activities::facebook::facebook_location_history;
use excavator::activities::google::google_fit_activity;
use excavator::activities::google::{location_history, saved_places, semantic_location_history};
use excavator::activities::snapchat::snapchat_areas_visited_history;
use excavator::activities::{
facebook::{device_location, primary_public_location},
MyActivity, PrimaryLocation,
Expand Down Expand Up @@ -167,6 +168,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let response = result.saveToDb(&conn)?;
println! ("({} records)", &result.location_history_v2.unwrap_or_default().len());
println!("{:?}", response);
// Snapchat
} else if f_name.starts_with("snap_location_history.json") {
println!("processing {}", d_name);

let rawdata = std::fs::read_to_string(&entry.path())?;

let result: snapchat_areas_visited_history::GeneralStructure =
serde_json::from_str(&rawdata)?;
println!("({} records)", &result.areas.len());
let response = result.saveToDb(&conn)?;
println!("{:?}", response);
}
}
Ok(())
Expand Down