Skip to content

Commit

Permalink
Display: added all the features from 3 files (#119)
Browse files Browse the repository at this point in the history
* Merged the feature of display in one file

* Merged the feature of display in one file

* Merged the feature of display in one file

* fixed 3 files and password format

* fixed display

* worked on display

* worked on display

* Update package/clip.py

Co-authored-by: Priyanshu Jindal <[email protected]>

* Update package/show.py

type casting

* Update package/write.py

type casting

---------

Co-authored-by: Yashwanth Rathkrishnan <[email protected]>
Co-authored-by: Priyanshu Jindal <[email protected]>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent dcd7d9e commit 5942f2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 62 deletions.
5 changes: 1 addition & 4 deletions package/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
from datetime import datetime
import glob
def display(snippet_name, password):
# 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:
if int(password) != int(current_time):
raise ValueError("Invalid password")

# Proceed to copy code to clipboard if the password matches
base_dir = os.path.dirname(__file__)
snippets_dir = os.path.join(base_dir, "stash")
pattern = os.path.join(snippets_dir, f"{snippet_name}.*")
Expand Down
63 changes: 7 additions & 56 deletions package/display.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,9 @@
import os
import subprocess
import sys
import shutil
from package.show import display
from package.write import plot

def models(snippet_name):
snippet_path = os.path.join(
os.path.dirname(__file__), "code_snippets", f"{snippet_name}.py"
)
def write(snippet_name, password):
return plot(snippet_name, password)


with open(snippet_path, "r") as file:
source_code = file.read()
print(source_code)


def graph(snippet_name):
snippet_path = os.path.join(
os.path.dirname(__file__), "code_snippets", f"{snippet_name}.py"
)

with open(snippet_path, "r") as file:
source_code = file.read()

# Function to copy text to clipboard based on platform
if "linux" in sys.platform:
subprocess.run(
["/usr/bin/xclip", "-selection", "clipboard"],
input=source_code.strip().encode(),
check=True,
)

elif "win32" in sys.platform:
subprocess.run(
["C:\\Windows\\System32\\clip.exe"],
input=source_code.strip().encode(),
check=True,
)

elif "darwin" in sys.platform: # macOS support
subprocess.run(
["pbcopy"],
input=source_code.strip().encode(),
check=True,
)

else:
raise OSError("Unsupported operating system")


def plot(snippet_name):
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")

shutil.copyfile(snippet_path, output_path)
except Exception as e:
print(f"Error: {e}")
def show(snippet_name, password, clipboard=None):
return display(snippet_name, password, clipboard=None)
3 changes: 2 additions & 1 deletion package/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import subprocess
import sys
from datetime import datetime
import glob

def display(snippet_name, password, clipboard=None):
current_time = datetime.now().strftime("%H%M")
if str(password) != current_time:
if int(password) != int(current_time):
raise ValueError("syntax error: incorrect password")
try:
base_dir = os.path.dirname(__file__)
Expand Down
2 changes: 1 addition & 1 deletion package/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

try:
Expand Down

0 comments on commit 5942f2f

Please sign in to comment.