1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
45use relevancy::{
6 url_hash::{hash_url, UrlHash},
7 Interest,
8};
9use std::{collections::HashMap, fs::File, io::Write};
1011// Generate a set of test data and output it to the `test-data` file.
12//
13// This is meant to be a placeholder until we can get this data stored in remote settings.
1415const TEST_INTEREST_DATA: &[(&str, Interest)] = &[
16 ("https://espn.com/", Interest::Sports),
17 ("https://dogs.com/", Interest::Animals),
18 ("https://cars.com/", Interest::Autos),
19 ("https://www.vouge.com/", Interest::Fashion),
20 ("https://slashdot.org/", Interest::Tech),
21 ("https://www.nascar.com/", Interest::Autos),
22 ("https://www.nascar.com/", Interest::Sports),
23];
2425fn main() {
26let mut interest_map: HashMap<Interest, Vec<UrlHash>> =
27 HashMap::from_iter(Interest::all().into_iter().map(|i| (i, vec![])));
28for (url, interest) in TEST_INTEREST_DATA {
29if let Some(hash) = hash_url(url) {
30 interest_map.get_mut(interest).unwrap().push(hash)
31 }
32 }
3334let mut f = File::create("test-data").expect("Error opening file");
35// Loop over all possible interests
36for interest in Interest::all() {
37// Get the list of URL hashes for that interest
38let hashes = interest_map.get(&interest).unwrap();
39// Write the count
40f.write_all(&(hashes.len() as u32).to_le_bytes())
41 .expect("Error writing file");
42// Write the hashes
43for hash in hashes {
44 f.write_all(hash).expect("Error writing file");
45 }
46 }
47}