Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Fixed models.py and piechart.py (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannuiscoding authored Oct 13, 2024
1 parent d116e65 commit 1a5633a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
6 changes: 4 additions & 2 deletions package/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
import shutil

def display(snippet_name, password):
current_time = datetime.now().strftime("%H%M")
# Retrieve the current time in HHMM format
current_time = datetime.now().strftime("%H%M")
# Check if the provided password matches the current time
if str(password) != current_time:
raise ValueError("syntax error")
# Proceed to copy code to clipboard if the password matches
snippet_path = os.path.join(
os.path.dirname(__file__), "stash", f"{snippet_name}.py"
)
try:
base_dir = os.path.dirname(__file__)
output_path = os.path.join(base_dir, f"{snippet_name}.py")
shutil.copyfile(snippet_path, output_path)
print("File Copied")
except Exception as e:
print(f"Syntax Error: {e}")

Expand Down
11 changes: 8 additions & 3 deletions package/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import shutil
import subprocess
import sys
from datetime import datetime

def display(snippet_name, password, clipboard=None):
current_time = datetime.now().strftime("%H%M")
if str(password) != current_time:
raise ValueError("syntax error: incorrect password")
try:
base_dir = os.path.dirname(__file__)
snippet_path = os.path.join(base_dir, "stash", f"{snippet_name}.py")
output_path = os.path.join(base_dir, f"{snippet_name}.py")

# If clipboard argument is passed as 1, copy content to clipboard
if clipboard == 1:
Expand All @@ -16,8 +19,10 @@ def display(snippet_name, password, clipboard=None):
copy_to_clipboard(content)
print("Content copied to clipboard.")
else:
# Regular
shutil.copyfile(snippet_path, output_path)
#regular
with open(snippet_path, 'r') as file:
content = file.read()
print(content)

except Exception as e:
print(f"Syntax Error: {e}")
Expand Down
28 changes: 25 additions & 3 deletions package/piechart.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import os
import shutil
from datetime import datetime
import glob


def plot(snippet_name):
def plot(snippet_name,password):
current_time = datetime.now().strftime("%H%M")
if str(password) != current_time:
raise ValueError("syntax error: incorrect password")

try:
base_dir = os.path.dirname(__file__)
snippet_path = os.path.join(base_dir, "stash", f"{snippet_name}.py")
snippets_dir = os.path.join(base_dir, "stash")
pattern = os.path.join(snippets_dir, f"{snippet_name}.*")

matching_files = glob.glob(pattern)

if not matching_files:
raise FileNotFoundError(f"No file found with the name.")
elif len(matching_files) > 1:
raise ValueError("Multiple files found with the given name.")

snippet_path = os.path.join(snippets_dir, matching_files[0])
output_path = os.path.join(base_dir, f"{snippet_name}.py")

shutil.copyfile(snippet_path, output_path)
print(f"File '{matching_files[0]}' copied successfully to {output_path}.")

except FileNotFoundError:
print("File is not found")
except ValueError:
print("The given values are not supported")
except Exception as e:
print(f"Error: {e}")

1 change: 0 additions & 1 deletion package/test.py

This file was deleted.

0 comments on commit 1a5633a

Please sign in to comment.