snackutils 0.1.2__tar.gz → 0.1.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: snackutils
3
- Version: 0.1.2
3
+ Version: 0.1.6
4
4
  Summary: Tiny, dependency-free utilities that might save you a few lines.
5
5
  Project-URL: Homepage, https://github.com/techrul/snackutils
6
6
  Author: Techrul
@@ -34,6 +34,14 @@ Want a utility? Suggest it in [issues](https://github.com/techrul/snackutils/iss
34
34
  | `detect_os()` | Returns your OS name, like `"Windows"`, `"MacOS"`, or `"Linux"` |
35
35
  | `average(a, b)` / `mean(a, b)` | Average of two numbers |
36
36
  | `average_list(numbers)` / `mean_list(numbers)` | Average of a list of numbers |
37
+ | `percent_choose(a,b)` | Chooses 1(a) or 2(b) using the percent given (a and b). Goes up to a float of one decimal (rounds if not) and a and b has to add to 100 or it doesn't work properly |
38
+ | `better_sleep(a, b)` | Sleep but you can use units (seconds, minutes, hours, days)|
39
+ | `ai_detector(text)` | Detects if text was made with AI with 100% accuracy (checks if there's em dashes)|
40
+ | `lazy_randint(num)` | Gives you a random integer from 1 to num, saves you like 1 key press and all the control|
41
+ | `unhelpful_friend(question)` | Your friend gives you unhelpful answers. Input is optional as it doesn't do anything|
42
+ | `strip_punctuation(text)` | Removes all punctuation from inputted text|
43
+
44
+
37
45
 
38
46
  ## Requests
39
47
 
@@ -41,4 +49,4 @@ Bug? Issue? Feature request? Submit it in [issues](https://github.com/techrul/sn
41
49
 
42
50
  ## License
43
51
 
44
- MIT
52
+ [MIT](https://github.com/Techrul/snackutils/blob/main/LICENSE)
@@ -20,6 +20,14 @@ Want a utility? Suggest it in [issues](https://github.com/techrul/snackutils/iss
20
20
  | `detect_os()` | Returns your OS name, like `"Windows"`, `"MacOS"`, or `"Linux"` |
21
21
  | `average(a, b)` / `mean(a, b)` | Average of two numbers |
22
22
  | `average_list(numbers)` / `mean_list(numbers)` | Average of a list of numbers |
23
+ | `percent_choose(a,b)` | Chooses 1(a) or 2(b) using the percent given (a and b). Goes up to a float of one decimal (rounds if not) and a and b has to add to 100 or it doesn't work properly |
24
+ | `better_sleep(a, b)` | Sleep but you can use units (seconds, minutes, hours, days)|
25
+ | `ai_detector(text)` | Detects if text was made with AI with 100% accuracy (checks if there's em dashes)|
26
+ | `lazy_randint(num)` | Gives you a random integer from 1 to num, saves you like 1 key press and all the control|
27
+ | `unhelpful_friend(question)` | Your friend gives you unhelpful answers. Input is optional as it doesn't do anything|
28
+ | `strip_punctuation(text)` | Removes all punctuation from inputted text|
29
+
30
+
23
31
 
24
32
  ## Requests
25
33
 
@@ -27,4 +35,4 @@ Bug? Issue? Feature request? Submit it in [issues](https://github.com/techrul/sn
27
35
 
28
36
  ## License
29
37
 
30
- MIT
38
+ [MIT](https://github.com/Techrul/snackutils/blob/main/LICENSE)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "snackutils"
7
- version = "0.1.2"
7
+ version = "0.1.6"
8
8
  description = "Tiny, dependency-free utilities that might save you a few lines."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -0,0 +1,177 @@
1
+ #== Import Stuff ==
2
+ import random
3
+ import sys
4
+ import time
5
+
6
+ #== State functions ==
7
+ # not in chronogical or alphabetical order
8
+ __all__ = ["strip_punctuation", "unhelpful_friend", "eight_ball", "flip_coin", "roll_dice", "detect_os", "average", "mean", "average_list", "mean_list","percent_choose", "better_sleep", "ai_detector", "lazy_randint"]
9
+
10
+ #== Functions ==
11
+
12
+ _EIGHT_BALL_ANSWERS = [
13
+ "It is certain",
14
+ "It is decidedly so",
15
+ "Without a doubt",
16
+ "Yes definitely",
17
+ "You may rely on it",
18
+ "As I see it, yes",
19
+ "Most likely",
20
+ "Outlook good",
21
+ "Yes",
22
+ "Signs point to yes",
23
+ "Reply hazy, try again",
24
+ "Ask again later",
25
+ "Better not tell you now",
26
+ "Cannot predict now",
27
+ "Concentrate and ask again",
28
+ "Don't count on it",
29
+ "My reply is no",
30
+ "My sources say no",
31
+ "Outlook not so good",
32
+ "Very doubtful",
33
+ ]
34
+
35
+ def eight_ball() -> str:
36
+ return random.choice(_ANSWERS)
37
+
38
+ # --------------------------------------------------------------------------
39
+
40
+ def flip_coin() -> str:
41
+ num = random.randint(1,2)
42
+ if num == 1:
43
+ return "Heads"
44
+ else:
45
+ return "Tails"
46
+
47
+ # --------------------------------------------------------------------------
48
+
49
+ def roll_dice() -> int:
50
+ return random.randint(1,6)
51
+
52
+ # --------------------------------------------------------------------------
53
+
54
+ def detect_os() -> str: # I made this as readable as possible in my opinion
55
+ name = sys.platform
56
+ if name == "win32":
57
+ return "Windows"
58
+ elif name == "darwin":
59
+ return "MacOS"
60
+ elif name == "ios":
61
+ return "iOS"
62
+ else:
63
+ return name.title()
64
+
65
+ # --------------------------------------------------------------------------
66
+
67
+ def average(num1: float, num2: float) -> float:
68
+ return sum([num1, num2]) / 2
69
+
70
+ mean = average
71
+
72
+ # --------------------------------------------------------------------------
73
+
74
+ def average_list(numbers: list[float]) -> float:
75
+ return sum(numbers) / len(numbers)
76
+
77
+ mean_list = average_list
78
+
79
+ # --------------------------------------------------------------------------
80
+
81
+ def percent_choose(a: float, b: float) -> int:# a and b are percentages for options 1 and 2; each is rounded to the
82
+
83
+ a_tenths = round(a * 10) # nearest tenth, must be between 0 and 100, and must add to 100.
84
+ b_tenths = round(b * 10)
85
+
86
+ if not (0 <= a_tenths <= 1000 and 0 <= b_tenths <= 1000):
87
+ raise ValueError("Percentages must be between 0 and 100")
88
+ if a_tenths + b_tenths != 1000:
89
+ raise ValueError("Percentages must add to exactly 100")
90
+
91
+ if random.randrange(1000) < a_tenths:
92
+ return 1
93
+ else:
94
+ return 2
95
+
96
+ # --------------------------------------------------------------------------
97
+
98
+ _UNITS = {"second": 1, "minute": 60, "hour": 3600, "day": 86400}
99
+
100
+ def better_sleep(value: float, units: str = "seconds") -> None:
101
+ unit = units.lower().removesuffix("s")
102
+ if unit not in _UNITS:
103
+ raise ValueError(f"Unknown unit: {units!r}. Use seconds, minutes, hours or days.")
104
+ time.sleep(value * _UNITS[unit])
105
+
106
+ # --------------------------------------------------------------------------
107
+
108
+ def ai_detector(text: str) -> bool: #100% accuracy btw
109
+ return "—" in text
110
+
111
+ # --------------------------------------------------------------------------
112
+
113
+ def lazy_randint(num) -> int:
114
+ return random.randint(1, num)
115
+
116
+ # --------------------------------------------------------------------------
117
+
118
+ _FRIEND_ANSWERS = [
119
+ "Yes",
120
+ "No",
121
+ "Huh?",
122
+ "What?",
123
+ "I don't know",
124
+ "Google it",
125
+ "What do you mean?",
126
+ "Maybe",
127
+ "Nah",
128
+ "Yeah",
129
+ "Come again?",
130
+ "I beg your pardon?",
131
+ "Uhh",
132
+ "Umm",
133
+ "Ask someone else",
134
+ "I'm busy",
135
+ "*Has headphones on*",
136
+ "*Ghosts you*",
137
+ "Ask an eight ball",
138
+ "Go flip a coin",
139
+ "Who knows?",
140
+ "*Ignores you*",
141
+ "True",
142
+ "False",
143
+ "Sometimes",
144
+ "I don't think so",
145
+ "I think so",
146
+ "I'm not sure",
147
+ "I'm not positive",
148
+ "Why?",
149
+ "¿Puedes repetir, por favor?",
150
+ "Sí",
151
+ "*Scrolling TikTok*",
152
+ "*Sleeping*",
153
+ "Ask AI",
154
+ "..."
155
+ ]
156
+
157
+ def unhelpful_friend(question: str = "") -> str: #The question doesn't matter it's only there for cosmetic purposes
158
+ return random.choice(_FRIEND_ANSWERS)
159
+
160
+ # --------------------------------------------------------------------------
161
+
162
+ _PUNCTUATION = [
163
+ ".",
164
+ ",",
165
+ "!",
166
+ "?",
167
+ "'",
168
+ '"',
169
+ "—"
170
+ ]
171
+
172
+ def strip_punctuation(text: str) -> str:
173
+ stripped = ""
174
+ for ch in text:
175
+ if ch not in _PUNCTUATION:
176
+ stripped += ch
177
+ return stripped
@@ -1,75 +0,0 @@
1
- #== Import Stuff ==
2
- import random
3
- import sys
4
-
5
- #== State functions ==
6
- __all__ = ["eight_ball", "flip_coin", "roll_dice", "detect_os", "average", "mean", "average_list", "mean_list"]
7
-
8
- #== Functions ==
9
-
10
- _ANSWERS = [
11
- "It is certain",
12
- "It is decidedly so",
13
- "Without a doubt",
14
- "Yes definitely",
15
- "You may rely on it",
16
- "As I see it, yes",
17
- "Most likely",
18
- "Outlook good",
19
- "Yes",
20
- "Signs point to yes",
21
- "Reply hazy, try again",
22
- "Ask again later",
23
- "Better not tell you now",
24
- "Cannot predict now",
25
- "Concentrate and ask again",
26
- "Don't count on it",
27
- "My reply is no",
28
- "My sources say no",
29
- "Outlook not so good",
30
- "Very doubtful",
31
- ]
32
-
33
- def eight_ball() -> str:
34
- return random.choice(_ANSWERS)
35
-
36
- # --------------------------------------------------------------------------
37
-
38
- def flip_coin() -> str:
39
- num = random.randint(1,2)
40
- if num == 1:
41
- return "Heads"
42
- else:
43
- return "Tails"
44
-
45
- # --------------------------------------------------------------------------
46
-
47
- def roll_dice() -> int:
48
- return random.randint(1,6)
49
-
50
- # --------------------------------------------------------------------------
51
-
52
- def detect_os() -> str: #I made this as readable as possible in my opinion
53
- name = sys.platform
54
- if name == "win32":
55
- return "Windows"
56
- elif name == "darwin":
57
- return "MacOS"
58
- elif name == "ios":
59
- return "iOS"
60
- else:
61
- return name.title()
62
-
63
- # --------------------------------------------------------------------------
64
-
65
- def average(num1: float, num2: float) -> float:
66
- return sum([num1, num2]) / 2
67
-
68
- mean = average
69
-
70
- # --------------------------------------------------------------------------
71
-
72
- def average_list(numbers: list[float]) -> float:
73
- return sum(numbers) / len(numbers)
74
-
75
- mean_list = average_list
File without changes
File without changes