Skip to content

Instantly share code, notes, and snippets.

@csnardi
Created January 3, 2019 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csnardi/518cf39c0d0e909132f8ddec6f3817e9 to your computer and use it in GitHub Desktop.
Save csnardi/518cf39c0d0e909132f8ddec6f3817e9 to your computer and use it in GitHub Desktop.
import glob
import os
from utils import load_yaml, dump_obj
from collections import OrderedDict
import retire
new_people = {}
previous_people = {}
abbr = "tn"
incoming_dir = 'people\\incoming\\' + abbr
data_dir = 'people\\data\\' + abbr
for fname in glob.glob(os.path.join(data_dir, 'people/*.yml')):
with open(fname) as f:
person = load_yaml(f)
previous_people[person["name"]] = fname
for fname in glob.glob(os.path.join(incoming_dir, 'people/*.yml')):
with open(fname) as f:
person = load_yaml(f)
new_people[person["name"]] = fname
overlapping_people = list(set(new_people) & set(previous_people))
first_time_people = list(set(new_people) - set(previous_people))
retiring_people = list(set(previous_people) - set(new_people))
for person in overlapping_people:
changed = False
new_file = new_people[person]
previous_file = previous_people[person]
with open(new_file) as f:
new_person = load_yaml(f)
with open(previous_file) as f:
previous_person = load_yaml(f)
for item in list(previous_person):
if item == "id":
continue
if item in new_person:
new_item = new_person[item]
if new_item != previous_person[item]:
if item == "roles":
previous_person["roles"][-1]["end_date"] = "2018-11-05"
previous_person["roles"].append(new_person[item][0])
previous_person["roles"][-1]["start_date"] = "2018-11-06"
else:
previous_person[item] = new_person[item]
changed = True
if changed:
dump_obj(previous_person, filename=previous_file)
os.remove(new_file)
for person in first_time_people:
filename = new_people[person]
with open(filename) as f:
person = load_yaml(f)
person["roles"][0]["start_date"] = "2018-11-06"
dump_obj(person, filename=filename.replace('incoming', 'data'))
os.remove(filename)
for person in retiring_people:
retire.retire("2018-11-05", previous_people[person], None, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment