1010import datetime
1111import os
1212
13+ import deepdiff
14+
1315from . import user_input_checking
1416from . import fileio
1517from . import helper_functions
@@ -35,10 +37,6 @@ def input_reading_and_checking(config_json_filepath, no_ORCID, no_GoogleScholar,
3537 ## read in config file
3638 config_dict = fileio .load_json (config_json_filepath )
3739
38- < << << << Updated upstream :academic_tracker / athr_srch_modularized .py
39- ## Get inputs from config file and check them for errors.
40- user_input_checking .config_file_check (config_dict , no_ORCID , no_GoogleScholar , no_Crossref )
41- == == == =
4240 if not "ORCID_search" in config_dict :
4341 no_ORCID = True
4442
@@ -51,7 +49,6 @@ def input_reading_and_checking(config_json_filepath, no_ORCID, no_GoogleScholar,
5149 ## Get inputs from config file and check them for errors.
5250 user_input_checking .config_file_check (config_dict , no_ORCID , no_GoogleScholar , no_Crossref , no_PubMed )
5351 user_input_checking .config_report_check (config_dict )
54- >> >> >> > Stashed changes :src / academic_tracker / athr_srch_modularized .py
5552
5653 return config_dict
5754
@@ -107,29 +104,23 @@ def build_publication_dict(config_dict, prev_pubs, no_ORCID, no_GoogleScholar, n
107104
108105 ## Get publications from PubMed
109106 helper_functions .vprint ("Finding author's publications. This could take a while." )
110- < << << << Updated upstream :academic_tracker / athr_srch_modularized .py
111- helper_functions .vprint ("Searching PubMed." )
112- PubMed_publication_dict = athr_srch_webio .search_PubMed_for_pubs (prev_pubs , config_dict ["Authors" ], config_dict ["PubMed_search" ]["PubMed_email" ])
113- prev_pubs .update (PubMed_publication_dict )
114- == == == =
115107 current_pubs = {}
116108 if not no_PubMed :
117109 helper_functions .vprint ("Searching PubMed." )
118110 PubMed_publication_dict = athr_srch_webio .search_PubMed_for_pubs (current_pubs , config_dict ["Authors" ], config_dict ["PubMed_search" ]["PubMed_email" ])
119111 current_pubs .update (PubMed_publication_dict )
120- > >> >> >> Stashed changes :src / academic_tracker / athr_srch_modularized .py
121112 if not no_ORCID :
122113 helper_functions .vprint ("Searching ORCID." )
123- ORCID_publication_dict = athr_srch_webio .search_ORCID_for_pubs (prev_pubs , config_dict ["ORCID_search" ]["ORCID_key" ], config_dict ["ORCID_search" ]["ORCID_secret" ], config_dict ["Authors" ])
124- prev_pubs .update (ORCID_publication_dict )
114+ ORCID_publication_dict = athr_srch_webio .search_ORCID_for_pubs (current_pubs , config_dict ["ORCID_search" ]["ORCID_key" ], config_dict ["ORCID_search" ]["ORCID_secret" ], config_dict ["Authors" ])
115+ current_pubs .update (ORCID_publication_dict )
125116 if not no_GoogleScholar :
126117 helper_functions .vprint ("Searching Google Scholar." )
127- Google_Scholar_publication_dict = athr_srch_webio .search_Google_Scholar_for_pubs (prev_pubs , config_dict ["Authors" ], config_dict ["Crossref_search" ]["mailto_email" ])
128- prev_pubs .update (Google_Scholar_publication_dict )
118+ Google_Scholar_publication_dict = athr_srch_webio .search_Google_Scholar_for_pubs (current_pubs , config_dict ["Authors" ], config_dict ["Crossref_search" ]["mailto_email" ])
119+ current_pubs .update (Google_Scholar_publication_dict )
129120 if not no_Crossref :
130121 helper_functions .vprint ("Searching Crossref." )
131- Crossref_publication_dict = athr_srch_webio .search_Crossref_for_pubs (prev_pubs , config_dict ["Authors" ], config_dict ["Crossref_search" ]["mailto_email" ])
132- prev_pubs .update (Crossref_publication_dict )
122+ Crossref_publication_dict = athr_srch_webio .search_Crossref_for_pubs (current_pubs , config_dict ["Authors" ], config_dict ["Crossref_search" ]["mailto_email" ])
123+ current_pubs .update (Crossref_publication_dict )
133124
134125 publication_dict = {}
135126 if not no_PubMed :
@@ -148,13 +139,18 @@ def build_publication_dict(config_dict, prev_pubs, no_ORCID, no_GoogleScholar, n
148139 for key , value in Crossref_publication_dict .items ():
149140 if not key in publication_dict :
150141 publication_dict [key ] = value
142+
143+ ## Compare current pubs with previous and only keep those that are new or updated.
144+ for pub_id , pub_values in prev_pubs .items ():
145+ if pub_id in publication_dict and not deepdiff .DeepDiff (publication_dict [pub_id ], pub_values , ignore_order = True , report_repetition = True ):
146+ del publication_dict [pub_id ]
151147
152148
153149 if len (publication_dict ) == 0 :
154150 helper_functions .vprint ("No new publications found." )
155151 sys .exit ()
156152
157- return publication_dict , prev_pubs
153+ return publication_dict
158154
159155
160156
@@ -174,10 +170,9 @@ def save_and_send_reports_and_emails(authors_by_project_dict, publication_dict,
174170 ## Build the save directory name.
175171 if test :
176172 save_dir_name = "tracker-test-" + re .sub (r"\-| |\:" , "" , str (datetime .datetime .now ())[2 :16 ])
177- os .mkdir (save_dir_name )
178173 else :
179174 save_dir_name = "tracker-" + re .sub (r"\-| |\:" , "" , str (datetime .datetime .now ())[2 :16 ])
180- os .mkdir (save_dir_name )
175+ os .mkdir (save_dir_name )
181176
182177
183178 email_messages = athr_srch_emails_and_reports .create_project_reports_and_emails (authors_by_project_dict , publication_dict , config_dict , save_dir_name )
@@ -222,9 +217,3 @@ def save_and_send_reports_and_emails(authors_by_project_dict, publication_dict,
222217 return save_dir_name
223218
224219
225-
226-
227-
228-
229-
230-
0 commit comments