pythd 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pythd-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythd
3
+ Version: 1.0.0
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythd
3
+ Version: 1.0.0
@@ -0,0 +1,9 @@
1
+ pyproject.toml
2
+ setup.py
3
+ pythd.egg-info/PKG-INFO
4
+ pythd.egg-info/SOURCES.txt
5
+ pythd.egg-info/dependency_links.txt
6
+ pythd.egg-info/entry_points.txt
7
+ pythd.egg-info/top_level.txt
8
+ thd/__init__.py
9
+ thd/cli.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ thd = thd.cli:main
@@ -0,0 +1 @@
1
+ thd
pythd-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
pythd-1.0.0/setup.py ADDED
@@ -0,0 +1,13 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="pythd",
5
+ version="1.0.0",
6
+ packages=find_packages(),
7
+ include_package_data=True,
8
+ entry_points={
9
+ "console_scripts": [
10
+ "thd=thd.cli:main"
11
+ ]
12
+ },
13
+ )
File without changes
pythd-1.0.0/thd/cli.py ADDED
@@ -0,0 +1,132 @@
1
+ import sys
2
+ from pathlib import Path
3
+ import pyperclip
4
+
5
+ # -----------------------------
6
+ # Auto Detect Programs
7
+ # -----------------------------
8
+
9
+ PROGRAMS = {}
10
+
11
+ base_dir = Path(__file__).resolve().parent.parent
12
+ programs_dir = base_dir / "programs"
13
+
14
+ files = sorted(programs_dir.iterdir())
15
+
16
+ index = 1
17
+
18
+ for file in files:
19
+
20
+ if file.suffix in [".cpp", ".java"]:
21
+
22
+ PROGRAMS[str(index)] = file.name
23
+ index += 1
24
+
25
+
26
+ # -----------------------------
27
+ # Get File
28
+ # -----------------------------
29
+
30
+ def get_file(choice):
31
+
32
+ if choice not in PROGRAMS:
33
+ print("Code not found")
34
+ return None
35
+
36
+ file_name = PROGRAMS[choice]
37
+
38
+ file_path = programs_dir / file_name
39
+
40
+ return file_path
41
+
42
+
43
+ # -----------------------------
44
+ # Print Code
45
+ # -----------------------------
46
+
47
+ def print_code(choice):
48
+
49
+ file_path = get_file(choice)
50
+
51
+ if not file_path:
52
+ return
53
+
54
+ print(f"\n========== {file_path.name} ==========\n")
55
+
56
+ with open(file_path, "r", encoding="utf-8") as f:
57
+ print(f.read())
58
+
59
+
60
+ # -----------------------------
61
+ # Copy Code
62
+ # -----------------------------
63
+
64
+ def copy_code(choice):
65
+
66
+ file_path = get_file(choice)
67
+
68
+ if not file_path:
69
+ return
70
+
71
+ with open(file_path, "r", encoding="utf-8") as f:
72
+ code = f.read()
73
+
74
+ pyperclip.copy(code)
75
+
76
+ print(f"\nCopied {file_path.name} to clipboard")
77
+
78
+
79
+ # -----------------------------
80
+ # List Codes
81
+ # -----------------------------
82
+
83
+ def list_codes():
84
+
85
+ print("\nAvailable Codes:\n")
86
+
87
+ for key, value in PROGRAMS.items():
88
+
89
+ print(f"[{key}] {value}")
90
+
91
+ print()
92
+
93
+
94
+ # -----------------------------
95
+ # Main
96
+ # -----------------------------
97
+
98
+ def main():
99
+
100
+ if len(sys.argv) < 2:
101
+
102
+ print("\nUsage:\n")
103
+ print("thd list")
104
+ print("thd 1")
105
+ print("thd copy 1\n")
106
+
107
+ return
108
+
109
+ command = sys.argv[1]
110
+
111
+ # List Programs
112
+ if command == "list":
113
+
114
+ list_codes()
115
+ return
116
+
117
+ # Copy Code
118
+ if command == "copy":
119
+
120
+ if len(sys.argv) < 3:
121
+ print("Provide code number")
122
+ return
123
+
124
+ copy_code(sys.argv[2])
125
+ return
126
+
127
+ # Print Code
128
+ print_code(command)
129
+
130
+
131
+ if __name__ == "__main__":
132
+ main()