Skip to content

Commit

Permalink
Move to different repos model
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Sep 19, 2022
1 parent b100e2d commit 2e046dd
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions write-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

client = boto3.client("codecommit", region_name="eu-west-2")

folders = client.get_folder(folderPath="/", repositoryName="CouncillorsRepo")[
"subFolders"
]
repos = [result["repositoryName"] for result in client.list_repositories()["repositories"]]

LAST_N_DAYS = []
for i in range(20, 0, -1):
LAST_N_DAYS.append(datetime.now().date() - timedelta(days=i))
# LAST_N_RUNS = []
# for i in range(60, 0, -7):
# LAST_N_RUNS.append(datetime.now().date() - timedelta(days=i))


@dataclass
Expand All @@ -30,15 +28,9 @@ def from_codecommit(cls, council_id, log_file):
if missing:
return log_book
content = json.loads(log_file["fileContent"])
log_books_by_date = {}
for run in content["runs"]:
for run in content["runs"][:20]:
log_run = LogRun.from_code_commit(run)
log_books_by_date[log_run.run_date] = log_run
for date in LAST_N_DAYS:
if date in log_books_by_date:
log_book.log_runs.append(log_books_by_date[date])
else:
log_book.log_runs.append(None)
log_book.log_runs.append(log_run)
return log_book

def as_dict(self):
Expand Down Expand Up @@ -84,16 +76,17 @@ def from_code_commit(cls: "LogRun", json_data):
logs: List[LogBook] = []


for folder in folders:
for repo in repos:
try:
print(repo)
log_file = client.get_file(
filePath=f"{folder['absolutePath']}/logbook.json",
repositoryName="CouncillorsRepo",
filePath="Councillors/logbook.json",
repositoryName=repo,
)
except client.exceptions.FileDoesNotExistException:
except (client.exceptions.FileDoesNotExistException, client.exceptions.CommitDoesNotExistException):
log_file = {}

log_data = LogBook.from_codecommit(folder["absolutePath"], log_file)
log_data = LogBook.from_codecommit(repo, log_file)
if log_data.log_runs:
logs.append(log_data)

Expand Down

0 comments on commit 2e046dd

Please sign in to comment.