Browse code

Capture the most recent favourite while saving data

Julio Biason authored on 27/05/2019 09:07:01
Showing 1 changed files

... ...
@@ -14,6 +14,10 @@ use reqwest;
14 14
 use log;
15 15
 use env_logger;
16 16
 
17
+// struct Config {
18
+//     last_favorite: Option<u>
19
+// }
20
+
17 21
 fn main() {
18 22
     env_logger::init();
19 23
 
... ...
@@ -29,17 +33,29 @@ fn main() {
29 33
         mastodon
30 34
     };
31 35
 
36
+    // let last_favorite = if let Ok(fp) 
37
+
38
+    let top = "";
32 39
     log::info!("Starting up...");
33
-    client
40
+    let most_recent_favourite = client
34 41
         .favourites()
35 42
         .unwrap()
36 43
         .items_iter()
44
+        .take_while(|record| record.id != top)
37 45
         .take(2)
38
-        .for_each(move |record| dump_record(record));
46
+        .map(|record| { dump_record(&record); record })
47
+        .fold(None, {|first, current| {
48
+            match first {
49
+                Some(x) => Some(x),
50
+                None => Some(current.id)
51
+            }
52
+        }});
53
+    log::debug!("First favourite: {:?}", most_recent_favourite);
39 54
 }
40 55
 
41
-fn dump_record(record: Status) -> () {
56
+fn dump_record(record: &Status) -> () {
42 57
     log::debug!("Retriving record {}", record.id);
58
+    log::debug!("Content: {:?}", record);
43 59
     create_structure(&record);
44 60
     save_content(&record);
45 61
     save_attachments(&record);