timehd 0.1.0__py3-none-any.whl

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.
timehd/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .clipboard import save, get
timehd/clipboard.py ADDED
@@ -0,0 +1,148 @@
1
+ import os
2
+ import pyperclip
3
+ import requests
4
+
5
+
6
+ SERVER_URL = "https://timehd-server.onrender.com"
7
+ API_KEY = os.getenv("TIMEHD_API_KEY")
8
+
9
+
10
+ def get_headers():
11
+ if not API_KEY:
12
+ raise RuntimeError(
13
+ "TIMEHD_API_KEY is not set. "
14
+ "Set it before using TIMEHD."
15
+ )
16
+
17
+ return {
18
+ "X-API-Key": API_KEY
19
+ }
20
+
21
+
22
+ def save(key):
23
+ """
24
+ Save the current clipboard content using a key.
25
+ """
26
+
27
+ if not isinstance(key, str) or not key.strip():
28
+ raise ValueError("Key must be a non-empty string.")
29
+
30
+ key = key.strip()
31
+
32
+ if len(key) > 100:
33
+ raise ValueError("Key cannot be longer than 100 characters.")
34
+
35
+ code = pyperclip.paste()
36
+
37
+ try:
38
+ response = requests.post(
39
+ f"{SERVER_URL}/save",
40
+ json={
41
+ "key": key,
42
+ "code": code
43
+ },
44
+ headers=get_headers(),
45
+ timeout=30
46
+ )
47
+
48
+ except requests.exceptions.Timeout:
49
+ raise RuntimeError(
50
+ "TIMEHD server took too long to respond."
51
+ )
52
+
53
+ except requests.exceptions.ConnectionError:
54
+ raise RuntimeError(
55
+ "Could not connect to the TIMEHD server."
56
+ )
57
+
58
+ if response.status_code == 401:
59
+ raise RuntimeError(
60
+ "Invalid TIMEHD API key."
61
+ )
62
+
63
+ if response.status_code >= 400:
64
+ try:
65
+ message = response.json().get("detail", response.text)
66
+ except Exception:
67
+ message = response.text
68
+
69
+ raise RuntimeError(
70
+ f"Server error ({response.status_code}): {message}"
71
+ )
72
+
73
+ data = response.json()
74
+
75
+ print(f"Code saved with key: {key}")
76
+ print(f"Expires at: {data.get('expires_at')}")
77
+
78
+ return data
79
+
80
+
81
+ def get(key):
82
+ """
83
+ Retrieve code using a key and copy it
84
+ automatically to the clipboard.
85
+ """
86
+
87
+ if not isinstance(key, str) or not key.strip():
88
+ raise ValueError("Key must be a non-empty string.")
89
+
90
+ key = key.strip()
91
+
92
+ if len(key) > 100:
93
+ raise ValueError("Key cannot be longer than 100 characters.")
94
+
95
+ try:
96
+ response = requests.get(
97
+ f"{SERVER_URL}/get",
98
+ params={
99
+ "key": key
100
+ },
101
+ headers=get_headers(),
102
+ timeout=30
103
+ )
104
+
105
+ except requests.exceptions.Timeout:
106
+ raise RuntimeError(
107
+ "TIMEHD server took too long to respond."
108
+ )
109
+
110
+ except requests.exceptions.ConnectionError:
111
+ raise RuntimeError(
112
+ "Could not connect to the TIMEHD server."
113
+ )
114
+
115
+ if response.status_code == 401:
116
+ raise RuntimeError(
117
+ "Invalid TIMEHD API key."
118
+ )
119
+
120
+ if response.status_code >= 400:
121
+ try:
122
+ message = response.json().get("detail", response.text)
123
+ except Exception:
124
+ message = response.text
125
+
126
+ raise RuntimeError(
127
+ f"Server error ({response.status_code}): {message}"
128
+ )
129
+
130
+ data = response.json()
131
+
132
+ if "code" not in data:
133
+ print(
134
+ data.get(
135
+ "message",
136
+ f"No code found for key: {key}"
137
+ )
138
+ )
139
+ return None
140
+
141
+ code = data["code"]
142
+
143
+ pyperclip.copy(code)
144
+
145
+ print(f"Code retrieved using key: {key}")
146
+ print("Code copied to clipboard.")
147
+
148
+ return code
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: timehd
3
+ Version: 0.1.0
4
+ Summary: Cloud clipboard for code with 24-hour expiration
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: pyperclip
8
+ Requires-Dist: requests
9
+
10
+ # TIMEHD
11
+
12
+ TIMEHD is a cloud clipboard for code.
13
+
14
+ Save code from one device and retrieve it from another device using a simple key.
15
+
16
+ ## Features
17
+
18
+ - Cloud-based code clipboard
19
+ - Works across devices
20
+ - Key-based code retrieval
21
+ - Automatic clipboard copy when retrieving
22
+ - Codes expire after 24 hours
23
+ - HTTPS communication
24
+ - API-key authentication
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install timehd
@@ -0,0 +1,6 @@
1
+ timehd/__init__.py,sha256=3SKZHwVULv2a5VuhwRF-q84qTJSf6ogpM_zrza-sk50,32
2
+ timehd/clipboard.py,sha256=HPwYohChmPJxJQUOpn_706zeQ9M8DwfspQHiNRijhX4,3462
3
+ timehd-0.1.0.dist-info/METADATA,sha256=WQc4-11eBBGAu2JulRI8NpHMVhMlAJ3iJLZ9BhOKfLA,639
4
+ timehd-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
+ timehd-0.1.0.dist-info/top_level.txt,sha256=qbcAZ_aUGbwTlrm5B7UNs5yB9zBkSa5qHh7A11Prp9s,7
6
+ timehd-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ timehd