Skip to content

Commit

Permalink
Merge pull request #59 from reactome/export-records-lineendings
Browse files Browse the repository at this point in the history
export_records.py minor fixes & avoiding CSV CRLF
  • Loading branch information
adamjohnwright authored Dec 20, 2024
2 parents 126df54 + d510c52 commit 1c9e5d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions bin/export_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ def main(records_dir: Path):
cur.execute(query)
records = cur.fetchall()

if len(records) == 0:
print("No new records found.")
return

latest_timestamp: str = max(row[1] for row in records)

record_file = records_dir / f"records_{latest_timestamp}.csv"

with open(record_file, mode="w", newline="") as file:
writer = csv.writer(file)
writer = csv.writer(file, lineterminator="\n")
writer.writerow(["threadId", "createdAt", "name", "type", "output"])
writer.writerows(records)

print("Wrote", record_file)


if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("records_dir", type=Path, default=Path("records"))
parser.add_argument("records_dir", type=Path, nargs="?", default=Path("records"))
args = parser.parse_args()
main(**vars(args))
2 changes: 1 addition & 1 deletion src/csv_generator/reactome_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def generate_csv(
data: Neo4jDict = data_fetch_func(connector)
df: pd.DataFrame = pd.DataFrame(data)
df["url"] = "https://reactome.org/content/detail/" + df["st_id"]
df.to_csv(csv_file_path, index=False)
df.to_csv(csv_file_path, index=False, lineterminator="\n")
return str(csv_file_path)


Expand Down

0 comments on commit 1c9e5d2

Please sign in to comment.