Compare commits
2 commits
7739242136
...
17bf5c0564
Author | SHA1 | Date | |
---|---|---|---|
17bf5c0564 | |||
db35263571 |
3 changed files with 22 additions and 6 deletions
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crate::utils::{normalize_str, parse_datetime_american, parse_normalize_phone};
|
use crate::utils::{normalize_str, parse_date_iso, parse_normalize_phone};
|
||||||
use crate::sync_paheko::{GeneralizedAnswer, sync_paheko};
|
use crate::sync_paheko::{GeneralizedAnswer, sync_paheko};
|
||||||
use email_address::EmailAddress;
|
use email_address::EmailAddress;
|
||||||
use chrono::prelude::Datelike;
|
use chrono::prelude::Datelike;
|
||||||
|
@ -42,7 +42,7 @@ pub async fn sync_csv(
|
||||||
// raw row record directly from CSV
|
// raw row record directly from CSV
|
||||||
#[derive(Debug, serde::Deserialize)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
struct AnswerRecord {
|
struct AnswerRecord {
|
||||||
#[serde(rename = "Date (MM/JJ/AAAA)")]
|
#[serde(rename = "Date")]
|
||||||
date: String,
|
date: String,
|
||||||
#[serde(rename = "Email acheteur")]
|
#[serde(rename = "Email acheteur")]
|
||||||
email: String,
|
email: String,
|
||||||
|
@ -122,11 +122,11 @@ pub async fn sync_csv(
|
||||||
country: "fr".to_string(),
|
country: "fr".to_string(),
|
||||||
job: process_csv_value(parsed_record.job),
|
job: process_csv_value(parsed_record.job),
|
||||||
birth_year: process_csv_value(parsed_record.birth_date)
|
birth_year: process_csv_value(parsed_record.birth_date)
|
||||||
.and_then(|raw_date| parse_datetime_american(&raw_date))
|
.and_then(|raw_date| parse_date_iso(&raw_date))
|
||||||
.map(|d| d.year() as u32),
|
.map(|d| d.year() as u32),
|
||||||
inception_time: process_csv_value(parsed_record.date)
|
inception_time: process_csv_value(parsed_record.date)
|
||||||
.map(|s|
|
.map(|s|
|
||||||
parse_datetime_american(&s).expect("Record must have a valid date")
|
parse_date_iso(&s).expect("Record must have a valid date")
|
||||||
)
|
)
|
||||||
.expect("Record must have a date"),
|
.expect("Record must have a date"),
|
||||||
reference: format!("BP/{}", process_csv_value(parsed_record.reference).expect("Row must have reference")), // BP as Bulletin Papier
|
reference: format!("BP/{}", process_csv_value(parsed_record.reference).expect("Row must have reference")), // BP as Bulletin Papier
|
||||||
|
|
16
src/utils.rs
16
src/utils.rs
|
@ -23,6 +23,14 @@ pub fn generate_id() -> Id {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn parse_date_iso(inp: &str) -> Option<DateTime<Utc>> {
|
||||||
|
let date = NaiveDate::parse_from_str(inp, "%Y-%m-%d").ok()?;
|
||||||
|
Some(DateTime::<Utc>::from_naive_utc_and_offset(
|
||||||
|
date.and_hms_opt(0, 0, 0).unwrap(),
|
||||||
|
Utc
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_datetime_american(inp: &str) -> Option<DateTime<Utc>> {
|
pub fn parse_datetime_american(inp: &str) -> Option<DateTime<Utc>> {
|
||||||
let date = NaiveDate::parse_from_str(inp, "%m/%d/%Y").ok()?;
|
let date = NaiveDate::parse_from_str(inp, "%m/%d/%Y").ok()?;
|
||||||
Some(DateTime::<Utc>::from_naive_utc_and_offset(
|
Some(DateTime::<Utc>::from_naive_utc_and_offset(
|
||||||
|
@ -31,6 +39,14 @@ pub fn parse_datetime_american(inp: &str) -> Option<DateTime<Utc>> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_datetime_french(inp: &str) -> Option<DateTime<Utc>> {
|
||||||
|
let date = NaiveDate::parse_from_str(inp, "%d/%m/%Y").ok()?;
|
||||||
|
Some(DateTime::<Utc>::from_naive_utc_and_offset(
|
||||||
|
date.and_hms_opt(0, 0, 0).unwrap(),
|
||||||
|
Utc
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_normalize_phone(inp: String) -> Option<String> {
|
pub fn parse_normalize_phone(inp: String) -> Option<String> {
|
||||||
let parsed = match phonenumber::parse(
|
let parsed = match phonenumber::parse(
|
||||||
Some(phonenumber::country::Id::FR), inp
|
Some(phonenumber::country::Id::FR), inp
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/sh
|
#!/usr/bin/sh
|
||||||
|
|
||||||
xlsx2csv -n "Adhérents PAPIER" /warmd/etoiledebethleem/copyparty/adhesions/wip_matthieu_b.xlsx \
|
xlsx2csv -n "Adhérents PAPIER" /warmd/etoiledebethleem/copyparty/adhesions/nouvelles_adhesions.xlsx \
|
||||||
| sed ':a;N;$!ba;s/\(Champ complémentaire [0-9]\)\n/\1 /g' \
|
| sed ':a;N;$!ba;s/\(Champ complémentaire [0-9]\)\n/\1 /g' \
|
||||||
| sed 's/Champ complémentaire \([0-9]\)/CC \1/g' \
|
| sed 's/Champ complémentaire \([0-9]\)/CC \1/g' \
|
||||||
| cargo run -- --source csv
|
| target/release/paheko_helloasso_adapter_rs --source csv
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue