input changes updated
This commit is contained in:
@@ -1 +1 @@
|
||||
VITE_API_URL="https://monacoapi.thearnab.tech"
|
||||
VITE_API_URL="http://localhost:8080"
|
||||
@@ -60,6 +60,11 @@ const EditorArea = ({
|
||||
const [terminalOutput, setTerminalOutput] = useState([]);
|
||||
const [activeRunningFile, setActiveRunningFile] = useState(null);
|
||||
|
||||
// Add a new state for user input
|
||||
const [userInput, setUserInput] = useState("");
|
||||
// Add a new state for waiting for input
|
||||
const [waitingForInput, setWaitingForInput] = useState(false);
|
||||
|
||||
// Focus the input when new file modal opens
|
||||
useEffect(() => {
|
||||
if (isNewFileModalOpen && newFileInputRef.current) {
|
||||
@@ -502,7 +507,7 @@ Happy coding!`;
|
||||
width: `calc(100% - ${sidebarVisible ? sidebarWidth : 0}px)`
|
||||
};
|
||||
|
||||
// Update the run code function to work with backend
|
||||
// Modify the handleRunCode function to prompt for input first
|
||||
const handleRunCode = async () => {
|
||||
if (!activeFile) return;
|
||||
|
||||
@@ -512,8 +517,8 @@ Happy coding!`;
|
||||
setPanelVisible(true);
|
||||
}
|
||||
|
||||
// Set running state
|
||||
setIsRunning(true);
|
||||
// Set state to waiting for input
|
||||
setWaitingForInput(true);
|
||||
setActiveRunningFile(activeFile.id);
|
||||
|
||||
// Clear previous output and add new command
|
||||
@@ -521,23 +526,40 @@ Happy coding!`;
|
||||
const language = getLanguageFromExtension(fileExtension);
|
||||
|
||||
const newOutput = [
|
||||
{ type: 'command', content: `$ run ${activeFile.id}` }
|
||||
{ type: 'command', content: `$ run ${activeFile.id}` },
|
||||
{ type: 'output', content: 'Waiting for input (press Enter if no input is needed)...' }
|
||||
];
|
||||
setTerminalOutput(newOutput);
|
||||
};
|
||||
|
||||
// Add a new function to handle input submission
|
||||
const handleInputSubmit = async () => {
|
||||
if (!activeFile || !waitingForInput) return;
|
||||
|
||||
// Set running state
|
||||
setIsRunning(true);
|
||||
setWaitingForInput(false);
|
||||
|
||||
// Add message that we're running with the input
|
||||
setTerminalOutput(prev => [
|
||||
...prev,
|
||||
{ type: 'output', content: userInput ? `Using input: "${userInput}"` : 'Running without input...' }
|
||||
]);
|
||||
|
||||
// Use API URL from environment variable
|
||||
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8080';
|
||||
|
||||
try {
|
||||
// Step 1: Submit code to backend
|
||||
// Now make the API call with the input that was entered
|
||||
const submitResponse = await fetch(`${apiUrl}/submit`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
language: language,
|
||||
code: activeFile.content
|
||||
language: getLanguageFromExtension(activeFile.id.split('.').pop().toLowerCase()),
|
||||
code: activeFile.content,
|
||||
input: userInput
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -785,9 +807,13 @@ Happy coding!`;
|
||||
height={panelHeight}
|
||||
terminalOutput={terminalOutput}
|
||||
isRunning={isRunning}
|
||||
waitingForInput={waitingForInput}
|
||||
activeRunningFile={activeRunningFile}
|
||||
initialTab="terminal"
|
||||
onClose={togglePanel} // Use the new function
|
||||
onClose={togglePanel}
|
||||
userInput={userInput}
|
||||
onUserInputChange={setUserInput}
|
||||
onInputSubmit={handleInputSubmit}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -6,9 +6,13 @@ const Panel = ({
|
||||
height,
|
||||
terminalOutput = [],
|
||||
isRunning = false,
|
||||
waitingForInput = false,
|
||||
activeRunningFile = null,
|
||||
initialTab = "terminal",
|
||||
onClose
|
||||
onClose,
|
||||
userInput = "",
|
||||
onUserInputChange,
|
||||
onInputSubmit
|
||||
}) => {
|
||||
const [activeTab, setActiveTab] = useState(initialTab);
|
||||
|
||||
@@ -28,9 +32,22 @@ const Panel = ({
|
||||
{line.type === 'command' ? <span className="terminal-prompt">$</span> : ''} {line.content}
|
||||
</div>
|
||||
))}
|
||||
{isRunning && (
|
||||
{waitingForInput && (
|
||||
<div className="terminal-line">
|
||||
<span className="terminal-cursor"></span>
|
||||
<span className="terminal-prompt">Input:</span>
|
||||
<input
|
||||
type="text"
|
||||
className="terminal-input"
|
||||
value={userInput}
|
||||
onChange={(e) => onUserInputChange && onUserInputChange(e.target.value)}
|
||||
placeholder="Enter input for your program here..."
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && onInputSubmit) {
|
||||
onInputSubmit();
|
||||
}
|
||||
}}
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -924,6 +924,21 @@ body {
|
||||
color: #569cd6;
|
||||
}
|
||||
|
||||
.terminal-input {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
color: inherit;
|
||||
font-family: monospace;
|
||||
font-size: inherit;
|
||||
margin-left: 8px;
|
||||
outline: none;
|
||||
width: calc(100% - 60px);
|
||||
}
|
||||
|
||||
.terminal-input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.terminal-line.info {
|
||||
color: #75beff;
|
||||
}
|
||||
|
||||
56
backend/data.py
Normal file
56
backend/data.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import aiohttp
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# Base URL template
|
||||
BASE_URL = "https://bhuvan-app3.nrsc.gov.in/isroeodatadownloadutility/tiledownloadnew_cfr_new.php?f=nices_ssm2_{}_{}.zip&se=NICES&u=arnabafk"
|
||||
|
||||
# Directory to save files
|
||||
SAVE_DIR = "data"
|
||||
os.makedirs(SAVE_DIR, exist_ok=True)
|
||||
|
||||
async def download_file(session, file_url, file_path):
|
||||
"""Download a file asynchronously."""
|
||||
print(f"Downloading {file_url}...")
|
||||
try:
|
||||
async with session.get(file_url) as response:
|
||||
if response.status == 200:
|
||||
with open(file_path, 'wb') as file:
|
||||
while chunk := await response.content.read(1024):
|
||||
file.write(chunk)
|
||||
print(f"Downloaded: {file_path}")
|
||||
else:
|
||||
print(f"Failed to download: {file_path}, Status Code: {response.status}")
|
||||
except Exception as e:
|
||||
print(f"Error downloading {file_url}: {e}")
|
||||
|
||||
async def fetch_data_for_year(session, year):
|
||||
"""Fetch and download data for a given year."""
|
||||
year_dir = os.path.join(SAVE_DIR, str(year))
|
||||
os.makedirs(year_dir, exist_ok=True)
|
||||
|
||||
start_date = datetime(year, 1, 1)
|
||||
end_date = datetime(year, 12, 31)
|
||||
delta = timedelta(days=2)
|
||||
tasks = []
|
||||
|
||||
date = start_date
|
||||
while date <= end_date:
|
||||
date_str = date.strftime("%Y%m%d")
|
||||
file_url = BASE_URL.format(date_str, "NICES")
|
||||
file_name = f"nices_ssm2_{date_str}.zip"
|
||||
file_path = os.path.join(year_dir, file_name)
|
||||
|
||||
tasks.append(download_file(session, file_url, file_path))
|
||||
date += delta
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
async def main():
|
||||
"""Main function to download data for multiple years."""
|
||||
async with aiohttp.ClientSession() as session:
|
||||
await asyncio.gather(*(fetch_data_for_year(session, year) for year in range(2002, 2025)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
BIN
backend/tmp/main.exe
Normal file
BIN
backend/tmp/main.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user