def db_updater(self): rc = self.rc name = nameparser.HumanName(rc.name) month = dt.datetime.today().month year = dt.datetime.today().year if name.last == '': key = "{}{}_{}".format( str(year)[-2:], month_to_str_int(month), name.first.casefold().strip(".")) else: key = "{}{}_{}_{}".format( str(year)[-2:], month_to_str_int(month), name.last.casefold(), name.first.casefold().strip(".")) coll = self.gtx[rc.coll] pdocl = list(filter(lambda doc: doc["_id"] == key, coll)) if len(pdocl) > 0: sys.exit("This entry appears to already exist in the collection") else: pdoc = {} pdoc.update({'claimed_found_what': [], 'claimed_why_important': [], 'did_how': [], 'did_what': [], 'due_date': rc.due_date, 'editor_eyes_only': '', 'final_assessment': [], 'freewrite': '', 'journal': rc.journal, 'recommendation': '', 'title': rc.title, 'validity_assessment': [], 'year': year }) if rc.reviewer: pdoc.update({'reviewer': rc.reviewer}) else: try: rc.reviewer = rc.default_user_id pdoc.update({'reviewer': rc.reviewer}) except AttributeError: print( "Please set default_user_id in '~/.config/regolith/user.json', or you need to enter your group id " "in the command line") return if rc.submitted_date: pdoc.update({'submitted_date': rc.submitted_date}) else: pdoc.update({'submitted_date': 'tbd'}) if rc.name: if name.last == '': pdoc.update({'first_author_last_name': name.first}) else: pdoc.update({'first_author_last_name': name.last}) if rc.requester: pdoc.update({'requester': rc.requester}) else: pdoc.update({'requester': ''}) if rc.status: if rc.status not in ALLOWED_STATI: raise ValueError( "status should be one of {}".format(ALLOWED_STATI)) else: pdoc.update({'status': rc.status}) else: pdoc.update({'status': 'accepted'}) pdoc.update({"_id": key}) rc.client.insert_one(rc.database, rc.coll, pdoc) print("{} manuscript has been added/updated in manuscript reviews".format( rc.name)) return
def db_updater(self): rc = self.rc name = nameparser.HumanName(rc.name) month = dt.datetime.today().month year = dt.datetime.today().year key = "{}{}_{}_{}".format( str(year)[-2:], month_to_str_int(month), name.last.casefold(), name.first.casefold().strip(".")) coll = self.gtx[rc.coll] pdocl = list(filter(lambda doc: doc["_id"] == key, coll)) if len(pdocl) > 0: sys.exit("This entry appears to already exist in the collection") else: pdoc = {} pdoc.update({'adequacy_of_resources': [ 'The resources available to the PI seem adequate'], 'agency': rc.type, 'competency_of_team': [], 'doe_appropriateness_of_approach': [], 'doe_reasonableness_of_budget': [], 'doe_relevance_to_program_mission': [], 'does_how': [], 'does_what': '', 'due_date': rc.due_date, 'freewrite': [], 'goals': [], 'importance': [], 'institutions': [], 'month': 'tbd', 'names': name.full_name, 'nsf_broader_impacts': [], 'nsf_create_original_transformative': [], 'nsf_plan_good': [], 'nsf_pot_to_advance_knowledge': [], 'nsf_pot_to_benefit_society': [], 'status': 'accepted', 'summary': '', 'year': 2020 }) if rc.title: pdoc.update({'title': rc.title}) else: pdoc.update({'title': ''}) if rc.requester: pdoc.update({'requester': rc.requester}) else: pdoc.update({'requester': ''}) if rc.reviewer: pdoc.update({'reviewer': rc.reviewer}) else: pdoc.update({'reviewer': 'sbillinge'}) if rc.status: if rc.status not in ALLOWED_STATI: raise ValueError( "status should be one of {}".format(ALLOWED_STATI)) else: pdoc.update({'status': rc.status}) else: pdoc.update({'status': 'accepted'}) pdoc.update({"_id": key}) rc.client.insert_one(rc.database, rc.coll, pdoc) print("{} proposal has been added/updated in proposal reviews".format( rc.name)) return
def test_month_to_str(input, expected): assert month_to_str_int(input) == expected
def main(args): file = Path.cwd().joinpath('..', 'db', "{}.yml".format(OUTCOLLECTION)) name = nameparser.HumanName(args.name) day = dt.datetime.today().day month = dt.datetime.today().month year = dt.datetime.today().year now = dt.datetime.now() key = "{}{}_{}_{}".format( str(year)[-2:], month_to_str_int(month), name.last.casefold(), name.first.casefold().strip(".")) pdoc = { 'adequacy_of_resources': ['The resources available to the PI seem adequate'], 'agency': args.type, 'competency_of_team': [], 'doe_appropriateness_of_approach': [], 'doe_reasonableness_of_budget': [], 'doe_relevance_to_program_mission': [], 'does_how': [], 'does_what': '', 'due_date': args.due_date, 'freewrite': [], 'goals': [], 'importance': [], 'institutions': [], 'month': 'tbd', 'names': name.full_name, 'nsf_broader_impacts': [], 'nsf_create_original_transformative': [], 'nsf_plan_good': [], 'nsf_pot_to_advance_knowledge': [], 'nsf_pot_to_benefit_society': [], 'status': 'accepted', 'summary': '', 'year': 2020 } if args.title: pdoc.update({'title': args.title}) else: pdoc.update({'title': ''}) if args.requester: pdoc.update({'requester': args.requester}) else: pdoc.update({'requester': ''}) if args.reviewer: pdoc.update({'reviewer': args.reviewer}) else: pdoc.update({'reviewer': 'sbillinge'}) if args.status: if args.status not in ALLOWED_STATI: raise ValueError( "status should be one of {}".format(ALLOWED_STATI)) else: pdoc.update({'status': args.status}) else: pdoc.update({'requester': ''}) fullpdoc = {key: pdoc} sync_coll(file, fullpdoc) print("{} proposal has been added/updated in proposal reviews".format( args.name)) return fullpdoc