ducky-python-module 0.1.2__tar.gz → 0.1.3__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.4
2
2
  Name: ducky-python-module
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Ducky Python module
5
5
  Author: Tom
6
6
  License: Creative Commons Attribution-NonCommercial 4.0 International Public
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ducky-python-module"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "Ducky Python module"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -27,3 +27,4 @@ where = ["src"]
27
27
  [project.urls]
28
28
  Repository = "https://github.com/ScubaKINGduck/Ducky-Python-Module"
29
29
  Issues = "https://github.com/ScubaKINGduck/Ducky-Python-Module/issues"
30
+
@@ -1,10 +1,11 @@
1
- import random, time, os, nltk, tkinter as TK, types, math, inspect, sys, requests, json, numpy
1
+ import random, time, os, nltk, tkinter as TK, types, math, inspect, sys, requests, json, numpy, ast, logging
2
2
  from os.path import isfile, split, join
3
3
  from copy import deepcopy
4
4
  from tkinter import simpledialog
5
5
  from turtle import Turtle
6
6
  from nltk.tokenize import word_tokenize
7
7
  from nltk.stem import LancasterStemmer
8
+ logging.basicConfig(level=logging.INFO)
8
9
 
9
10
  #matrix functions
10
11
 
@@ -17,21 +18,21 @@ def draw(mat,x,y,val=1,errors=True): #draws a certain value to all specified pos
17
18
  try:
18
19
  for i,x_pos in enumerate(x):
19
20
  mat[y[i]][x_pos] = val
20
- except Exception as e:
21
+ except (ValueError,IndexError) as e:
21
22
  if errors:
22
23
  print(e)
23
24
  else:
24
- print(f"Mat:\t{mat}\nX:\t{x}\nY:\t{y}")
25
+ print(f"Lengths aren't equal: Mat Rows: {len(mat)}, X: {len(x)}, Y: {len(y)}")
25
26
  return mat
26
27
 
27
28
  def scan(mat,condition=1): #returns all locations that meet a certain condition
28
29
  x = []
29
30
  y = []
30
- for yindex,Y in enumerate(mat):
31
- for xindex,X in enumerate(mat[yindex]):
31
+ for y_index,Y in enumerate(mat):
32
+ for x_index,X in enumerate(mat[y_index]):
32
33
  if X == condition:
33
- x.append(xindex)
34
- y.append(yindex)
34
+ x.append(x_index)
35
+ y.append(y_index)
35
36
  return x,y
36
37
 
37
38
  def shift(mat,x,y,x_shift,y_shift=0):
@@ -72,8 +73,8 @@ def render(mat):
72
73
 
73
74
  #my functions
74
75
 
75
- def duckint(min,max):
76
- return random.randint(min,max)
76
+ def rand_int(minimum,maximum):
77
+ return random.randint(minimum,maximum)
77
78
 
78
79
  def choose(list_input):
79
80
  return random.choice(list_input)
@@ -98,55 +99,69 @@ def stem(string):
98
99
  lancaster = LancasterStemmer()
99
100
  return lancaster.stem(string)
100
101
 
101
- def array(list):
102
- return numpy.array(list)
103
-
104
- def add(a,b):
105
- return a + b
106
-
107
- def subtract(a,b):
108
- return a - b
109
-
110
- def multiply(a,b):
111
- return a * b
112
-
113
- def divide(a,b):
114
- return a / b
102
+ def array(lst):
103
+ return numpy.array(lst)
115
104
 
116
105
  def calc(param):
117
106
  try:
118
- return eval(param)
119
- except Exception as e:
107
+ return ast.literal_eval(param)
108
+ except (ValueError,SyntaxError) as e:
109
+ logging.error(f"Error evaluating expression: {e}")
120
110
  return e
121
111
 
122
- def find_total(number): #adds all numbers below it above 0 (including itself) e.g. find_total(5) = 5+4+3+2+1 = 15
112
+ def find_total(number,condition=None): #adds all numbers below it that meet a certain condition
123
113
  if number < 1:
124
114
  return 0
125
- else:
126
- return number + find_total(number - 1)
127
-
128
- def find_sum_of_evens(number): #adds all even numbers below it above 0 (including itself but only if it's even) e.g find_sum_of_evens(5) = 4+2 = 6
129
- if number < 1:
130
- return 0
131
- elif number % 2 == 0:
132
- return number + find_sum_of_evens(number - 2)
133
- else:
134
- return find_sum_of_evens(number - 1)
115
+ total = 0
116
+ for n in range(1, number + 1):
117
+ if condition is None or condition(n):
118
+ total += n
119
+ return total
135
120
 
136
- def ask(url):
121
+ def ask_url(url):
137
122
  return requests.get(url)
138
123
 
139
124
  def ask_json(url):
140
125
  return requests.get(url).json()
141
126
 
142
- def locate():
143
- response = requests.get('https://ipinfo.io')
144
- coords = response.text.strip()
145
- return coords
146
-
147
- def perf_counter():
127
+ def get_coords():
128
+ response = requests.get("https://ipinfo.io/json", timeout=5)
129
+ response.raise_for_status()
130
+ data = response.json()
131
+ loc = data.get("loc") # "lat,lon"
132
+ if loc:
133
+ lat, lon = map(float, loc.split(","))
134
+ return lat, lon
135
+ return None
136
+
137
+ def get_time():
148
138
  return time.perf_counter()
149
139
 
140
+ #my decorators
141
+
142
+ def time_function(func):
143
+ def wrapper(*args, **kwargs):
144
+ start = get_time()
145
+ result = func(*args, **kwargs)
146
+ end = get_time()
147
+ execution_time = end - start
148
+ return result, execution_time
149
+ return wrapper
150
+
151
+ def repeat(times):
152
+ def decorator(func):
153
+ def wrapper(*args, **kwargs):
154
+ results = []
155
+ for _ in range(times):
156
+ result = func(*args, **kwargs)
157
+ results.append(result)
158
+ return results
159
+ return wrapper
160
+ return decorator
161
+
162
+ def modify(func,modifier):
163
+ return modifier(func())
164
+
150
165
  #classes
151
166
 
152
167
  class MatrixManager:
@@ -210,19 +225,30 @@ class Manage:
210
225
  else:
211
226
  print("Error, invalid choice:\n")
212
227
  def write_to_file(self):
213
- with open(self.file,"w") as file:
214
- file.write(input(f"What do you want to write to the file?\n"))
228
+ try:
229
+ with open(self.file,"w") as file:
230
+ file.write(input(f"What do you want to write to the file?\n"))
231
+ except Exception as e:
232
+ logging.error(f"Failed to write to {self.file}: {e}")
215
233
 
216
234
  def append_to_file(self):
217
- with open(self.file,"a") as file:
218
- file.write(input(f"What do you want to append to the file?\n"))
235
+ try:
236
+ with open(self.file,"a") as file:
237
+ file.write(input(f"What do you want to append to the file?\n"))
238
+ except Exception as e:
239
+ logging.error(f"Failed to append to {self.file}: {e}")
240
+ return None
219
241
 
220
242
  def delete_a_file(self):
221
243
  if input("Are you sure ('y') ?:\n") == "y":
222
244
  os.remove(self.file)
223
245
  def read_from_file(self):
224
- with open(self.file,"r") as file:
225
- return file.read()
246
+ try:
247
+ with open(self.file,"r") as file:
248
+ return file.read()
249
+ except Exception as e:
250
+ logging.error(f"Failed to read from {self.file}: {e}")
251
+ return None
226
252
 
227
253
 
228
254
  class TurtleManager:
@@ -315,7 +341,7 @@ class Chatbot:
315
341
  elif score[3] > score[0] and score[3] > score[1] and score[3] > score[2] and score[3] > score[4]:
316
342
  return "How may I assist you?"
317
343
  elif score[4] > score[0] and score[4] > score[1] and score[4] > score[2] and score[4] > score[3]:
318
- return f"Locational data:\n{locate()}"
344
+ return f"Your current coordinates are:\n{get_coords()}"
319
345
  return None
320
346
 
321
347
  def reply_test(self):
@@ -324,9 +350,8 @@ class Chatbot:
324
350
  if self.reply(self.testing_input[test]) != self.testing_output[test]:
325
351
  return 0
326
352
  return 1
353
+ return None
327
354
 
328
- def perf_counter():
329
- return time.perf_counter()
330
355
  #turtlel
331
356
 
332
357
  def dots(turt_name, number, random_colours=True, colours=None, minimum=20, maximum=100):
@@ -334,10 +359,10 @@ def dots(turt_name, number, random_colours=True, colours=None, minimum=20, maxim
334
359
  colours = ["black"]
335
360
  turt_name.penup()
336
361
  for num in range(number):
337
- turt_name.goto(duckint(-250,250),duckint(-250,250))
362
+ turt_name.goto(rand_int(-250,250),rand_int(-250,250))
338
363
  if random_colours == True and colours:
339
364
  turt_name.pencolour(choose(colours))
340
- turt_name.dot(duckint(minimum,maximum))
365
+ turt_name.dot(rand_int(minimum,maximum))
341
366
 
342
367
  def target_board(t_name):
343
368
  t_name.dot(610,"black")
@@ -368,14 +393,14 @@ def splat(t,num):
368
393
  for i in range(num):
369
394
  for ii in range(num):
370
395
  star(t,colour="yellow",size=100,width=50)
371
- t.forward(duckint(30,60))
372
- t.right(360/num+duckint(1,10))
396
+ t.forward(rand_int(30,60))
397
+ t.right(360/num+rand_int(1,10))
373
398
  t.forward(num*i)
374
399
  for iii in range(num):
375
400
  star(t,colour="yellow",size=100,width=50)
376
401
  t.forward(num*10)
377
- t.right(360/num+duckint(1,10))
378
- t.right(3**i*duckint(1,10))
402
+ t.right(360/num+rand_int(1,10))
403
+ t.right(3**i*rand_int(1,10))
379
404
 
380
405
  def pizza(t,x=0,y=0,size=1):
381
406
  t.penup()
@@ -388,9 +413,9 @@ def pizza(t,x=0,y=0,size=1):
388
413
  t.colour("yellow")
389
414
  t.dot(28*size)
390
415
  t.colour("red")
391
- for i in range(duckint(10,15)):
392
- t.goto(duckint(x+-100,x+100),duckint(y+-100,y+100))
393
- t.dot(duckint(25,30))
416
+ for i in range(rand_int(10,15)):
417
+ t.goto(rand_int(x+-100,x+100),rand_int(y+-100,y+100))
418
+ t.dot(rand_int(25,30))
394
419
  t.goto(x,y)
395
420
  t.colour("white")
396
421
  t.pendown()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ducky-python-module
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Ducky Python module
5
5
  Author: Tom
6
6
  License: Creative Commons Attribution-NonCommercial 4.0 International Public