@@ -8,6 +8,13 @@ import { PerspectiveClientService } from '@iverify/perspective-client/src/lib/pe
88import { MlServiceType } from '@iverify/iverify-common' ;
99import { TranslateService } from './TranslateService/TranslateService' ;
1010
11+ const RadioFilterConvert = {
12+ "Désinfo - Politique" : "POLITIQUE" ,
13+ "Désinfo - Sécurité" : "SÉCURITÉ" ,
14+ "Désinfo - Genre et Société" :"GENRE ET SOCIÉTÉ" ,
15+ "Désinfo - Environment et Santé" :"ENVIRONNEMENT ET SANTÉ" ,
16+ }
17+
1118@Injectable ( )
1219export class AppService {
1320 private readonly logger = new Logger ( 'TriageAppService' ) ;
@@ -23,7 +30,7 @@ export class AppService {
2330 private translate : TranslateService
2431 ) { }
2532
26- async pullRadioMessages ( ) : Promise < number > {
33+ async pullRadioMessages ( ) : Promise < any > {
2734 if ( this . config . enableRadioMessages != 'true' ) {
2835 this . logger . log ( 'Radio messages feature disabled' )
2936 return
@@ -51,23 +58,47 @@ export class AppService {
5158 const pageIndex = pageCount - 1 ;
5259 let createdItems = [ ] ;
5360 let createdPosts = [ ] ;
54- for ( let page = pageIndex ; page >= 0 ; page -- ) {
55- const list = await this . unitedwaveClient . getPosts ( page , startTime ) . toPromise ( ) ;
56- for ( let i = list . length - 1 ; i >= 0 ; i -- ) {
57- const post = list [ i ] ;
58- const title = [ 'radio' , post ?. keywords , post ?. date_reported ]
59- . filter ( Boolean )
60- . join ( ' - ' ) ;
61+ for ( let page = pageIndex ; page >= 0 ; page -- ) {
62+ const list = await this . unitedwaveClient
63+ . getPosts ( page , startTime )
64+ . toPromise ( ) ;
65+ for ( let i = list . length - 1 ; i >= 0 ; i -- ) {
66+ const post = list [ i ] ;
67+ const title = [ 'radio' , post ?. keywords , post ?. date_reported ]
68+ . filter ( Boolean )
69+ . join ( ' - ' ) ;
70+ const arr = post . filters . split ( ',' ) ;
71+
72+ const realValue = arr . find ( ( item ) => RadioFilterConvert [ item ] ) || '' ;
73+ const category :string = RadioFilterConvert [ realValue ] || '' ;
74+
75+ console . log ( 'posts-category' , category , title ) ;
6176 // check duplication
62- const isDuplicate = this . isDuplicatePost ( post , createdPosts ) ;
63- if ( ! isDuplicate ) {
64- const item = await this . checkClient . createItemFromRadio ( post ?. clip_url , title , post ?. source_text , post ?. date_reported ) . toPromise ( ) ;
65- if ( ! item . error ) {
77+ const isDuplicate = this . isDuplicatePost ( post , createdPosts ) ;
78+ if ( ! isDuplicate ) {
79+ try {
80+ const item = await this . checkClient . createItemFromRadio (
81+ post ?. clip_url ,
82+ title ,
83+ post ?. source_text ,
84+ post ?. date_reported
85+ ) . toPromise ( ) ;
86+
87+ if ( item && ! item . error ) {
6688 createdItems = [ ...createdItems , item ] ;
6789 createdPosts = [ ...createdPosts , post ] ;
90+
91+ if ( category ) {
92+ const annotationList = item . data . createProjectMedia . project_media . tasks . edges ;
93+
94+ await this . checkClient . UpdateRadioCategory ( category , annotationList ) . toPromise ( ) ;
95+ }
6896 }
97+ } catch ( error ) {
98+ console . error ( 'Error while creating item:' , error ) ;
6999 }
70100 }
101+ }
71102 }
72103 this . logger . log ( `Created ${ createdItems . length } items.` )
73104 return createdItems . length ;
0 commit comments