JBGruber/rwhatsapp

Time conversion

Closed this issue · 4 comments

rwa_read function did not work for iranian (persian) time format.

Can you post a couple of lines from your chat file? I can take a look and maybe fix it.

I found an easy fix for this problem by converting the Persian numbers before running rwa_read. I wrapped some code I found on SO in a function and convert the numbers on the fly. Could you confirm that this does what you expect? I put your text into a txt file called rwatest.txt and use this code:

convert_numbers <- function(x) {
  chartr(
    # persian
    "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9", 
    # arabic
    "\U0030\U0031\U0032\U0033\U0034\U0035\U0036\U0037\U0038\U0039\U0030\U0031\U0032\U0033\U0034\U0035\U0036\U0037\U0038\U0039",
    x)
}

df <- rwhatsapp::rwa_read(x = convert_numbers(readLines("rwatest.txt")))
df
#> # A tibble: 26 × 6
#>    time                author   text                    source  emoji emoji_name
#>    <dttm>              <fct>    <chr>                   <chr>   <lis> <list>    
#>  1 2021-05-30 18:44:57 <NA>     پیام‌ها و تماس‌ها سرتاسر… text i… <NUL… <NULL>    
#>  2 2021-05-30 18:44:57 Sattar-b سلام،خسته نباشید        text i… <NUL… <NULL>    
#>  3 2021-05-30 18:44:57 Sattar-b در مورد اطلاعیه شطرنجت… text i… <NUL… <NULL>    
#>  4 2021-05-30 18:45:57 شطرنج    سلام مچکرم              text i… <NUL… <NULL>    
#>  5 2021-05-30 18:45:57 شطرنج    در خدمتم                text i… <NUL… <NULL>    
#>  6 2021-05-30 18:45:57 Sattar-b مسابقاته یا آموزش شطرن… text i… <NUL… <NULL>    
#>  7 2021-05-30 18:46:57 شطرنج    هم مسابقات داریم هم ام… text i… <NUL… <NULL>    
#>  8 2021-05-30 18:46:57 شطرنج    اموزش یه صورت عمومی و … text i… <NUL… <NULL>    
#>  9 2021-05-30 18:47:57 شطرنج    کلاس نیمه خصوصی از شنب… text i… <NUL… <NULL>    
#> 10 2021-05-30 18:47:57 شطرنج    میتونید شرکت کنید       text i… <NUL… <NULL>    
#> # … with 16 more rows

Created on 2022-02-05 by the reprex package (v2.0.1)