Skip to content

Commit

Permalink
fix csv saving in python API script
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinElms committed Nov 26, 2024
1 parent 8416eaf commit 852ff7b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
2 changes: 0 additions & 2 deletions plotting/scriptGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def generateR(url, plot_type: str, script_Type: str) -> BytesIO:
query = query.replace("true", "1")
if "false" in query:
query = query.replace("false", "0")
if "null" in query:
query = query.replace("null", "None")

with open(f"plotting/templates/r_{script_Type}_template.txt", "r") as f:
template = str(f.read())
Expand Down
11 changes: 1 addition & 10 deletions plotting/templates/python_csv_template.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import requests
import os
import shutil
from urllib.request import urlopen
from urllib.parse import urlencode
from contextlib import closing
try:
from PIL import Image
except:
print("If you are on a Windows machine, please install PIL (imaging library) using 'python -m pip install Pillow' in the Anaconda Prompt")
exit()
import json


Expand All @@ -25,13 +17,12 @@ def requestFile():

# Save file and finish
data_file = requests.get(url, stream=True)
dump = data_file.raw
# change this if you want a different save location
location = os.getcwd()
fname = {f} + ".csv"
with open(fname, "wb") as location:
print('Saving File')
shutil.copyfileobj(dump, location)
location.write(data_file.content)
print('Done')


Expand Down
2 changes: 1 addition & 1 deletion plotting/templates/r_plot_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fname <- paste("ONAV_PLOT_", queryObj["dataset"],"_", queryObj["variable"],".png

gsub("[\r\n]", "", query)
base_url <- "https://oceannavigator.ca/api/v2.0/plot/{p}?"
url <- paste(base_url,"&query=",URLencode(query),"&dpi=",toString(dpi), sep="")
url <- paste(base_url,"&query=",URLencode(query),"&save=True&format=png&size=10x7&dpi=",toString(dpi), sep="")
print(url)


Expand Down

0 comments on commit 852ff7b

Please sign in to comment.