Skip to content

Commit

Permalink
Merge pull request #515 from akrherz/excel_save
Browse files Browse the repository at this point in the history
Fix now removed excel API usage
  • Loading branch information
akrherz authored Apr 2, 2024
2 parents 7ab4514 + 8d9a30c commit e9ee66d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.3"
rev: "v0.3.5"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
5 changes: 2 additions & 3 deletions htdocs/admin/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def application(environ, start_response):
),
]
start_response("200 OK", headers)
writer = pd.ExcelWriter("/tmp/ss.xlsx")
df.to_excel(writer, "Data", index=False)
writer.save()
with pd.ExcelWriter("/tmp/ss.xlsx") as writer:
df.to_excel(writer, "Data", index=False)
payload = open("/tmp/ss.xlsx", "rb").read()
os.unlink("/tmp/ss.xlsx")
return [payload]
Expand Down
5 changes: 2 additions & 3 deletions htdocs/cscap/plot_decagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,10 @@ def application(environ, start_response):
),
),
]
writer = pd.ExcelWriter("/tmp/ss.xlsx")
# Prevent timezone troubles
df["timestamp"] = df["timestamp"].dt.strftime("%Y-%m-%d %H:%M")
df.to_excel(writer, "Data", index=False)
writer.save()
with pd.ExcelWriter("/tmp/ss.xlsx") as writer:
df.to_excel(writer, "Data", index=False)
payload = open("/tmp/ss.xlsx", "rb").read()
os.unlink("/tmp/ss.xlsx")
return [payload]
Expand Down
9 changes: 4 additions & 5 deletions htdocs/cscap/plot_tileflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,15 @@ def application(environ, start_response):
),
]
start_response("200 OK", headers)
writer = pd.ExcelWriter("/tmp/ss.xlsx")
# Prevent timezone troubles
if ptype not in [
"2",
]:
df["timestamp"] = df["timestamp"].dt.strftime("%Y-%m-%d %H:%M")
df.to_excel(writer, "Data", index=False)
worksheet = writer.sheets["Data"]
worksheet.freeze_panes(3, 0)
writer.save()
with pd.ExcelWriter("/tmp/ss.xlsx") as writer:
df.to_excel(writer, "Data", index=False)
worksheet = writer.sheets["Data"]
worksheet.freeze_panes(3, 0)
payload = open("/tmp/ss.xlsx", "rb").read()
os.unlink("/tmp/ss.xlsx")
return [payload]
Expand Down
9 changes: 4 additions & 5 deletions htdocs/cscap/plot_waterquality.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ def application(environ, start_response):
),
]
start_response("200 OK", headers)
writer = pd.ExcelWriter("/tmp/ss.xlsx")
df.to_excel(writer, "Data", index=False)
worksheet = writer.sheets["Data"]
worksheet.freeze_panes(3, 0)
writer.save()
with pd.ExcelWriter("/tmp/ss.xlsx") as writer:
df.to_excel(writer, "Data", index=False)
worksheet = writer.sheets["Data"]
worksheet.freeze_panes(3, 0)
payload = open("/tmp/ss.xlsx", "rb").read()
os.unlink("/tmp/ss.xlsx")
return [payload]
Expand Down
9 changes: 4 additions & 5 deletions htdocs/cscap/plot_watertable.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ def application(environ, start_response):
),
]
start_response("200 OK", headers)
writer = pd.ExcelWriter("/tmp/ss.xlsx")
df.to_excel(writer, "Data", index=False)
worksheet = writer.sheets["Data"]
worksheet.freeze_panes(3, 0)
writer.save()
with pd.ExcelWriter("/tmp/ss.xlsx") as writer:
df.to_excel(writer, "Data", index=False)
worksheet = writer.sheets["Data"]
worksheet.freeze_panes(3, 0)
payload = open("/tmp/ss.xlsx", "rb").read()
os.unlink("/tmp/ss.xlsx")
return [payload]
Expand Down
5 changes: 2 additions & 3 deletions scripts/cscap/plotids/check_ghg_plotids.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ def main():
plotdf.at[idx, "ghg"] = "yes"

df = pd.DataFrame(rows)
writer = pd.ExcelWriter("output.xlsx")
df.to_excel(writer, "Sheet1")
writer.save()
with pd.ExcelWriter("output.xlsx") as writer:
df.to_excel(writer, "Sheet1")

res = drive.files().list(q="title contains 'Plot Identifiers'").execute()
for item in res["items"]:
Expand Down
7 changes: 3 additions & 4 deletions scripts/cscap/tileflow/interpolate_serf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
].interpolate(method="time")


writer = pd.ExcelWriter("output.xlsx")
for plotid in df:
df[plotid].to_excel(writer, plotid)
writer.save()
with pd.ExcelWriter("output.xlsx") as writer:
for plotid in df:
df[plotid].to_excel(writer, plotid)

0 comments on commit e9ee66d

Please sign in to comment.