@@ -314,13 +314,12 @@ def get(self, paper_id=""):
314314 try :
315315 interactions_database = PostInteractions
316316 itnsjoin_database = PostInteractionsSourceMiJoin
317- query = db .select (
318- interactions_database ,
319- itnsjoin_database
320- ).select_from (interactions_database ).join (
321- itnsjoin_database ,
322- interactions_database .interaction_id == itnsjoin_database .interaction_id
323- ).where (itnsjoin_database .source_id == paper_id )
317+ query = (
318+ db .select (interactions_database , itnsjoin_database )
319+ .select_from (interactions_database )
320+ .join (itnsjoin_database , interactions_database .interaction_id == itnsjoin_database .interaction_id )
321+ .where (itnsjoin_database .source_id == paper_id )
322+ )
324323 rows = db .session .execute (query ).all ()
325324 for i , m in rows :
326325 result .append (
@@ -382,9 +381,7 @@ def get(self, tag=""):
382381 # Step 1: Get source_ids that contain the searched tag
383382
384383 matching_source_ids = []
385- query_source = db .select (src_tag_join_database .source_id ).where (
386- src_tag_join_database .tag_name == tag
387- )
384+ query_source = db .select (src_tag_join_database .source_id ).where (src_tag_join_database .tag_name == tag )
388385 rows_source = db .session .execute (query_source ).all ()
389386 matching_source_ids = [row [0 ] for row in rows_source ]
390387
@@ -393,11 +390,7 @@ def get(self, tag=""):
393390
394391 # Step 2: Get all tags for those sources
395392 query = (
396- db .select (
397- ext_src_database ,
398- src_tag_join_database .tag_name ,
399- tag_lkup_database .tag_group
400- )
393+ db .select (ext_src_database , src_tag_join_database .tag_name , tag_lkup_database .tag_group )
401394 .join (src_tag_join_database , ext_src_database .source_id == src_tag_join_database .source_id )
402395 .join (tag_lkup_database , src_tag_join_database .tag_name == tag_lkup_database .tag_name )
403396 .where (ext_src_database .source_id .in_ (matching_source_ids )) # Keep all tags for matched sources
@@ -425,7 +418,7 @@ def get(self, tag=""):
425418 "image_url" : ex .image_url ,
426419 "grn_title" : ex .grn_title ,
427420 "cyjs_layout" : ex .cyjs_layout ,
428- "tag" : "|" .join (src_tag_match [ex .source_id ])
421+ "tag" : "|" .join (src_tag_match [ex .source_id ]),
429422 }
430423 result .append (one_source [source_id ])
431424
@@ -494,7 +487,7 @@ def get(self, number=""):
494487 "url" : row .url ,
495488 "image_url" : row .image_url ,
496489 "grn_title" : row .grn_title ,
497- "cyjs_layout" : row .cyjs_layout
490+ "cyjs_layout" : row .cyjs_layout ,
498491 }
499492 )
500493
@@ -530,7 +523,7 @@ def get(self, stringAGI=""):
530523 es .comments ,
531524 es .cyjs_layout ,
532525 stjt .tag_name ,
533- tlt .tag_group
526+ tlt .tag_group ,
534527 )
535528 .join (i_s_mi_join_table , i_s_mi_join_table .source_id == es .source_id )
536529 .join (i , i .interaction_id == i_s_mi_join_table .interaction_id )
@@ -557,20 +550,14 @@ def get(self, stringAGI=""):
557550 "source_name" : row .source_name ,
558551 "comments" : row .comments ,
559552 "cyjs_layout" : row .cyjs_layout ,
560- "tags" : []
553+ "tags" : [],
561554 }
562555
563556 tag_entry = f"{ row .tag_name } :{ row .tag_group } "
564557 if tag_entry not in result_dict [source_id ]["tags" ]: # DISTINCT
565558 result_dict [source_id ]["tags" ].append (tag_entry )
566559
567- result = [
568- {
569- ** data ,
570- "tags" : "|" .join (data ["tags" ]) # overwrites tags
571- }
572- for data in result_dict .values ()
573- ]
560+ result = [{** data , "tags" : "|" .join (data ["tags" ])} for data in result_dict .values ()] # overwrites tags
574561
575562 if len (result ) == 0 :
576563 return BARUtils .error_exit ("Invalid AGI" ), 400
@@ -603,7 +590,7 @@ def get(self, AGI_1="", AGI_2=""):
603590 es .comments ,
604591 es .cyjs_layout ,
605592 stjt .tag_name ,
606- tlt .tag_group
593+ tlt .tag_group ,
607594 )
608595 .join (i_s_mi_join_table , i_s_mi_join_table .source_id == es .source_id )
609596 .join (i , i .interaction_id == i_s_mi_join_table .interaction_id )
@@ -630,18 +617,14 @@ def get(self, AGI_1="", AGI_2=""):
630617 "source_name" : row .source_name ,
631618 "comments" : row .comments ,
632619 "cyjs_layout" : row .cyjs_layout ,
633- "tags" : set ()
620+ "tags" : set (),
634621 }
635622
636- result_dict [source_id ]["tags" ].add (f"{ row .tag_name } :{ row .tag_group } " ) # ensures uniqueness automatically with `set`
623+ result_dict [source_id ]["tags" ].add (
624+ f"{ row .tag_name } :{ row .tag_group } "
625+ ) # ensures uniqueness automatically with `set`
637626
638- result = [
639- {
640- ** data ,
641- "tags" : "|" .join (sorted (data ["tags" ]))
642- }
643- for data in result_dict .values ()
644- ]
627+ result = [{** data , "tags" : "|" .join (sorted (data ["tags" ]))} for data in result_dict .values ()]
645628
646629 if len (result ) == 0 :
647630 return BARUtils .error_exit ("Both AGI invalid" ), 400
@@ -664,11 +647,7 @@ def get(self):
664647 stjt = SourceTagJoinTable
665648 tlt = TagLookupTable
666649 query = (
667- db .select (
668- es ,
669- stjt .tag_name ,
670- tlt .tag_group
671- )
650+ db .select (es , stjt .tag_name , tlt .tag_group )
672651 .join (stjt , es .source_id == stjt .source_id )
673652 .join (tlt , stjt .tag_name == tlt .tag_name )
674653 )
@@ -695,7 +674,7 @@ def get(self):
695674 "image_url" : ex .image_url ,
696675 "grn_title" : ex .grn_title ,
697676 "cyjs_layout" : ex .cyjs_layout ,
698- "tag" : "|" .join (src_tag_match [ex .source_id ])
677+ "tag" : "|" .join (src_tag_match [ex .source_id ]),
699678 }
700679 result .append (one_source [source_id ])
701680
0 commit comments