···11+import pandas as pd
22+import glob
33+import requests
44+import json
55+import os # Make sure to import os at the top of your file
66+77+def load_parquet_files(folder_path):
88+ # Expand the user's home directory
99+ folder_path = os.path.expanduser(folder_path)
1010+ # Create a pattern to match all parquet files in the folder
1111+ pattern = f"{folder_path}/*.parquet"
1212+ # Use glob to find all files matching the pattern
1313+ parquet_files = glob.glob(pattern)
1414+ # Load and concatenate all parquet files into a single DataFrame
1515+ df = pd.concat([pd.read_parquet(file) for file in parquet_files[0:1]], ignore_index=True)
1616+ return df
1717+1818+def post_text_to_endpoint(df, url):
1919+ # Iterate over each row in the DataFrame
2020+ for index, row in df.iterrows():
2121+ # Extract text from the current row
2222+ text = row['text']
2323+ # Prepare the data for POST request
2424+ data = json.dumps({"text": text})
2525+ headers = {'Content-Type': 'application/json'}
2626+ # Send POST request to the specified URL
2727+ response = requests.post(url, data=data, headers=headers)
2828+ # Check if the request was successful
2929+ if response.status_code == 200:
3030+ print(f"Successfully posted text from row {index}")
3131+ else:
3232+ print(f"Failed to post text from row {index}. Status code: {response.status_code}")
3333+3434+# Define the folder path and URL
3535+folder_path = "~/code/tiny-strange-textbooks"
3636+url = "https://cpfiffer--mongo-hack-handle-request-dev.modal.run/"
3737+3838+# Load parquet files into a DataFrame
3939+df = load_parquet_files(folder_path)
4040+print(df)
4141+4242+# Post text to the specified endpoint
4343+post_text_to_endpoint(df, url)
···11+using HTTP
22+using JSON3
33+using Parquet2, DataFrames
44+# df = DataFrame(read_parquet(path))
55+66+function load_parquet_files(folder_path::String)
77+ # load the parquet files
88+ parquet_files = filter(
99+ x -> endswith(x, ".parquet"),
1010+ readdir(folder_path, join=true)
1111+ )
1212+1313+ # Load and concatenate all parquet files into a single DataFrame
1414+ dfs = DataFrame[]
1515+ for file in parquet_files[1:10]
1616+ ds = Parquet2.Dataset(file)
1717+ df = DataFrame(ds; copycols=false)
1818+ push!(dfs, df)
1919+ end
2020+ return reduce(vcat, dfs)
2121+end
2222+2323+function post_text_to_endpoint(df::DataFrame, url::String)
2424+ # Iterate over each row in the DataFrame
2525+ for row in eachrow(df)
2626+ # Extract text from the current row
2727+ text = row["text"]
2828+ # Prepare the data for POST request
2929+ data = JSON3.write(Dict("text" => text))
3030+ headers = Dict("Content-Type" => "application/json")
3131+ # Send POST request to the specified URL
3232+ response = HTTP.post(url, headers=headers, body=data)
3333+ # Check if the request was successful
3434+ if response.status == 200
3535+ println("Successfully posted text from row")
3636+ else
3737+ println("Failed to post text from row. Status code: $(response.status)")
3838+ end
3939+ end
4040+end
4141+4242+# Define the folder path and URL
4343+folder_path = joinpath(homedir(), "code/tiny-strange-textbooks")
4444+url = "https://cpfiffer--mongo-hack-handle-request-dev.modal.run/"
4545+4646+# Load parquet files into a DataFrame
4747+df = load_parquet_files(folder_path)
4848+4949+# Post text to the specified endpoint
5050+post_text_to_endpoint(df, url)