articlib 0.2.3__py3-none-any.whl → 0.2.5__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.

Potentially problematic release.


This version of articlib might be problematic. Click here for more details.

articlib/dateTime.py CHANGED
@@ -1,121 +1,155 @@
1
- from datetime import datetime
2
-
3
- YYYYMMDD = 1
4
- DDMMYYYY = 2
5
- MMDDYYYY = 3
6
-
7
- class createDate:
8
- def __init__(self, mode):
9
- self.mode = mode
10
-
11
- def setToNow(self):
12
- date = datetime.now()
13
- self.year = int(date.year)
14
- self.month = int(date.month)
15
- self.day = int(date.day)
16
- self.hour = int(date.hour)
17
- self.minute = int(date.minute)
18
- self.second = int(date.second)
19
- self.calculateStringDate()
20
- self.calculateStringTime()
21
-
22
- def setTo(self, year, month, day, hour, minute, second):
23
- self.year = year
24
- self.month = month
25
- self.day = day
26
- self.hour = hour
27
- self.minute = minute
28
- self.second = second
29
- self.calculateStringDate()
30
- self.calculateStringTime()
31
-
32
- def setToString(self, string):
33
- string = string.split(" ")
34
- date = string[0]
35
- time = string[1]
36
- self.dateString = date
37
- self.timeString = time
38
- self.calculateDate()
39
- self.calculateTime()
40
-
41
- def calculateDate(self):
42
- if self.mode == YYYYMMDD:
43
- self.year = int(self.dateString[0:4])
44
- self.month = int(self.dateString[5:7])
45
- self.day = int(self.dateString[8:10])
46
- elif self.mode == DDMMYYYY:
47
- self.day = int(self.dateString[0:2])
48
- self.month = int(self.dateString[3:5])
49
- self.year = int(self.dateString[6:10])
50
- elif self.mode == MMDDYYYY:
51
- self.month = int(self.dateString[0:2])
52
- self.day = int(self.dateString[3:5])
53
- self.year = int(self.dateString[6:10])
54
- else:
55
- raise ValueError("Invalid mode")
56
-
57
- def calculateTime(self):
58
- self.hour = int(self.timeString[0:2])
59
- self.minute = int(self.timeString[3:5])
60
- self.second = int(self.timeString[6:8])
61
-
62
- def calculateStringDate(self):
63
- if self.mode == YYYYMMDD:
64
- self.dateString = str(self.year) + "/" + str(self.month).zfill(2) + "/" + str(self.day).zfill(2)
65
- elif self.mode == DDMMYYYY:
66
- self.dateString = str(self.day).zfill(2) + "/" + str(self.month).zfill(2) + "/" + str(self.year)
67
- elif self.mode == MMDDYYYY:
68
- self.dateString = str(self.month).zfill(2) + "/" + str(self.day).zfill(2) + "/" + str(self.year)
69
- else:
70
- raise ValueError("Invalid mode")
71
-
72
- def calculateStringTime(self):
73
- self.timeString = str(self.hour).zfill(2) + ":" + str(self.minute).zfill(2) + ":" + str(self.second).zfill(2)
74
-
75
- def setMode(self, mode):
76
- self.mode = mode
77
- self.calculateStringDate()
78
-
79
- ## Output values
80
- def getDateTimePathFomat(self):
81
- if self.mode == YYYYMMDD:
82
- dateString = str(self.year) + str(self.month).zfill(2) + str(self.day).zfill(2)
83
- elif self.mode == DDMMYYYY:
84
- dateString = str(self.day).zfill(2) + str(self.month).zfill(2) + str(self.year)
85
- elif self.mode == MMDDYYYY:
86
- dateString = str(self.month).zfill(2) + str(self.day).zfill(2) + str(self.year)
87
- else:
88
- raise ValueError("Invalid mode")
89
- timeString = str(self.hour).zfill(2) + str(self.minute).zfill(2) + str(self.second).zfill(2)
90
- return f"{dateString}_{timeString}"
91
-
92
- def getDate(self):
93
- return self.dateString
94
-
95
- def getTime(self):
96
- return self.timeString
97
-
98
- def getDateTime(self):
99
- return self.dateString + " " + self.timeString
100
-
101
- def getYear(self):
102
- return self.year
103
-
104
- def getMonth(self):
105
- return self.month
106
-
107
- def getDay(self):
108
- return self.day
109
-
110
- def getHour(self):
111
- return self.hour
112
-
113
- def getMinute(self):
114
- return self.minute
115
-
116
- def getSecond(self):
117
- return self.second
118
-
119
- def getMode(self):
120
- return self.mode
121
-
1
+ from datetime import datetime
2
+
3
+ YYYYMMDD = 1
4
+ DDMMYYYY = 2
5
+ MMDDYYYY = 3
6
+
7
+
8
+ class createDate:
9
+ def __init__(self, mode):
10
+ self.mode = mode
11
+
12
+ def setToNow(self):
13
+ date = datetime.now()
14
+ self.year = int(date.year)
15
+ self.month = int(date.month)
16
+ self.day = int(date.day)
17
+ self.hour = int(date.hour)
18
+ self.minute = int(date.minute)
19
+ self.second = int(date.second)
20
+ self.calculateStringDate()
21
+ self.calculateStringTime()
22
+
23
+ def setTo(self, year, month, day, hour, minute, second):
24
+ self.year = year
25
+ self.month = month
26
+ self.day = day
27
+ self.hour = hour
28
+ self.minute = minute
29
+ self.second = second
30
+ self.calculateStringDate()
31
+ self.calculateStringTime()
32
+
33
+ def setToString(self, string):
34
+ string = string.split(" ")
35
+ date = string[0]
36
+ time = string[1]
37
+ self.dateString = date
38
+ self.timeString = time
39
+ self.calculateDate()
40
+ self.calculateTime()
41
+
42
+ def calculateDate(self):
43
+ if self.mode == YYYYMMDD:
44
+ self.year = int(self.dateString[0:4])
45
+ self.month = int(self.dateString[5:7])
46
+ self.day = int(self.dateString[8:10])
47
+ elif self.mode == DDMMYYYY:
48
+ self.day = int(self.dateString[0:2])
49
+ self.month = int(self.dateString[3:5])
50
+ self.year = int(self.dateString[6:10])
51
+ elif self.mode == MMDDYYYY:
52
+ self.month = int(self.dateString[0:2])
53
+ self.day = int(self.dateString[3:5])
54
+ self.year = int(self.dateString[6:10])
55
+ else:
56
+ raise ValueError("Invalid mode")
57
+
58
+ def calculateTime(self):
59
+ self.hour = int(self.timeString[0:2])
60
+ self.minute = int(self.timeString[3:5])
61
+ self.second = int(self.timeString[6:8])
62
+
63
+ def calculateStringDate(self):
64
+ if self.mode == YYYYMMDD:
65
+ self.dateString = (
66
+ str(self.year)
67
+ + "/"
68
+ + str(self.month).zfill(2)
69
+ + "/"
70
+ + str(self.day).zfill(2)
71
+ )
72
+ elif self.mode == DDMMYYYY:
73
+ self.dateString = (
74
+ str(self.day).zfill(2)
75
+ + "/"
76
+ + str(self.month).zfill(2)
77
+ + "/"
78
+ + str(self.year)
79
+ )
80
+ elif self.mode == MMDDYYYY:
81
+ self.dateString = (
82
+ str(self.month).zfill(2)
83
+ + "/"
84
+ + str(self.day).zfill(2)
85
+ + "/"
86
+ + str(self.year)
87
+ )
88
+ else:
89
+ raise ValueError("Invalid mode")
90
+
91
+ def calculateStringTime(self):
92
+ self.timeString = (
93
+ str(self.hour).zfill(2)
94
+ + ":"
95
+ + str(self.minute).zfill(2)
96
+ + ":"
97
+ + str(self.second).zfill(2)
98
+ )
99
+
100
+ def setMode(self, mode):
101
+ self.mode = mode
102
+ self.calculateStringDate()
103
+
104
+ ## Output values
105
+ def getDateTimePathFomat(self):
106
+ if self.mode == YYYYMMDD:
107
+ dateString = (
108
+ str(self.year) + str(self.month).zfill(2) + str(self.day).zfill(2)
109
+ )
110
+ elif self.mode == DDMMYYYY:
111
+ dateString = (
112
+ str(self.day).zfill(2) + str(self.month).zfill(2) + str(self.year)
113
+ )
114
+ elif self.mode == MMDDYYYY:
115
+ dateString = (
116
+ str(self.month).zfill(2) + str(self.day).zfill(2) + str(self.year)
117
+ )
118
+ else:
119
+ raise ValueError("Invalid mode")
120
+ timeString = (
121
+ str(self.hour).zfill(2)
122
+ + str(self.minute).zfill(2)
123
+ + str(self.second).zfill(2)
124
+ )
125
+ return f"{dateString}_{timeString}"
126
+
127
+ def getDate(self):
128
+ return self.dateString
129
+
130
+ def getTime(self):
131
+ return self.timeString
132
+
133
+ def getDateTime(self):
134
+ return self.dateString + " " + self.timeString
135
+
136
+ def getYear(self):
137
+ return self.year
138
+
139
+ def getMonth(self):
140
+ return self.month
141
+
142
+ def getDay(self):
143
+ return self.day
144
+
145
+ def getHour(self):
146
+ return self.hour
147
+
148
+ def getMinute(self):
149
+ return self.minute
150
+
151
+ def getSecond(self):
152
+ return self.second
153
+
154
+ def getMode(self):
155
+ return self.mode
articlib/dice.py CHANGED
@@ -1,32 +1,35 @@
1
- import random
2
-
3
- class dice:
4
- def __init__(self, size=6):
5
- self.size = size
6
-
7
- def setSize(self, size):
8
- self.size = size
9
-
10
- def roll(self):
11
- return random.randint(1, self.size)
12
-
13
- class customDice(dice):
14
- def __init__(self, faces):
15
- self.faces = faces
16
- self.size = len(faces)
17
-
18
- def roll(self):
19
- return random.choice(self.faces)
20
-
21
- class dicePool:
22
- def __init__(self, diceList):
23
- self.diceList = diceList
24
-
25
- def roll(self):
26
- return [d.roll() for d in self.diceList]
27
-
28
- def rollSum(self):
29
- return sum(self.roll())
30
-
31
- def rollSuccesses(self, target):
32
- return sum([1 for roll in self.roll() if roll >= target])
1
+ import random
2
+
3
+
4
+ class dice:
5
+ def __init__(self, size: int = 6) -> None:
6
+ self.size = size
7
+
8
+ def setSize(self, size: int) -> None:
9
+ self.size = size
10
+
11
+ def roll(self) -> int:
12
+ return random.randint(1, self.size)
13
+
14
+
15
+ class customDice(dice):
16
+ def __init__(self, faces: list[str]) -> None:
17
+ self.faces = faces
18
+ self.size = len(faces)
19
+
20
+ def roll(self) -> str:
21
+ return random.choice(self.faces)
22
+
23
+
24
+ class dicePool:
25
+ def __init__(self, diceList) -> None:
26
+ self.diceList = diceList
27
+
28
+ def roll(self) -> list[int]:
29
+ return [d.roll() for d in self.diceList]
30
+
31
+ def rollSum(self) -> int:
32
+ return sum(self.roll())
33
+
34
+ def rollSuccesses(self, target: int) -> int:
35
+ return sum([1 for roll in self.roll() if roll >= target])
articlib/sqliteEngine.py CHANGED
@@ -1,66 +1,69 @@
1
- import sqlite3
2
- import articlib.articLogger as Logger
3
- from articlib.articLogger import log
4
-
5
- class sqliteEngine:
6
- def __init__(self, dbPath):
7
- self.con = sqlite3.connect (dbPath)
8
- self.cursor = self.con.cursor()
9
-
10
- def executeCommand (self, command):
11
- log.addEntry(f"Executing command: {command}", Logger.DEBUG_MASK)
12
- self.cursor.execute (command)
13
-
14
- def createTable (self, name, columns):
15
- self.executeCommand (f"CREATE TABLE {name} ({columns});")
16
-
17
- def addColumn (self, table, column):
18
- self.executeCommand (f"ALTER TABLE {table} ADD COLUMN {column};")
19
-
20
- def deleteColumn (self, table, column):
21
- self.executeCommand (f"ALTER TABLE {table} DROP COLUMN {column}")
22
-
23
- def addEntry (self, table, columns, values):
24
- self.executeCommand (f"INSERT INTO {table} ({columns}) VALUES ({values});")
25
-
26
- def updateEntry (self, table, columns, values, condition):
27
- self.executeCommand (f"UPDATE {table} SET {columns} = \"{values}\" WHERE {condition};")
28
-
29
- def deleteEntry (self, table, condition):
30
- self.executeCommand (f"DELETE FROM {table} WHERE {condition};")
31
-
32
- def readEntry (self, table, columns):
33
- self.executeCommand (f"SELECT {columns} FROM {table};")
34
- result = self.cursor.fetchall()
35
- log.addEntry(f"Read entry: {result}", Logger.DEBUG_MASK)
36
- return result
37
-
38
- def readNumberOfEntries (self, table):
39
- self.executeCommand (f"SELECT COUNT(*) FROM {table};")
40
- result = self.cursor.fetchall()
41
- log.addEntry(f"Read number of entries: {result}", Logger.DEBUG_MASK)
42
- return result[0][0]
43
-
44
- def readEntryFiltered (self, table, columns, filter):
45
- self.executeCommand(f"SELECT {columns} FROM {table} WHERE {filter};")
46
- result = self.cursor.fetchall()
47
- log.addEntry(f"Read entry: {result}", Logger.DEBUG_MASK)
48
- return result
49
-
50
- def entryExistsOnTable (self, table, condition):
51
- self.executeCommand (f"SELECT * FROM {table} WHERE {condition};")
52
- entry = self.cursor.fetchall()
53
- if len(entry) != 0:
54
- return True
55
- else:
56
- return False
57
-
58
- def deleteEntryFromTable (self, table, condition):
59
- self.executeCommand (f"DELETE FROM {table} WHERE {condition};")
60
-
61
- def commit(self):
62
- self.con.commit()
63
-
64
- def commitClose(self):
65
- self.commit()
66
- self.con.close()
1
+ import sqlite3
2
+ import articlib.articLogger as Logger
3
+ from articlib.articLogger import log
4
+
5
+
6
+ class sqliteEngine:
7
+ def __init__(self, dbPath):
8
+ self.con = sqlite3.connect(dbPath)
9
+ self.cursor = self.con.cursor()
10
+
11
+ def executeCommand(self, command):
12
+ log.addEntry(f"Executing command: {command}", Logger.DEBUG_MASK)
13
+ self.cursor.execute(command)
14
+
15
+ def createTable(self, name, columns):
16
+ self.executeCommand(f"CREATE TABLE {name} ({columns});")
17
+
18
+ def addColumn(self, table, column):
19
+ self.executeCommand(f"ALTER TABLE {table} ADD COLUMN {column};")
20
+
21
+ def deleteColumn(self, table, column):
22
+ self.executeCommand(f"ALTER TABLE {table} DROP COLUMN {column}")
23
+
24
+ def addEntry(self, table, columns, values):
25
+ self.executeCommand(f"INSERT INTO {table} ({columns}) VALUES ({values});")
26
+
27
+ def updateEntry(self, table, columns, values, condition):
28
+ self.executeCommand(
29
+ f'UPDATE {table} SET {columns} = "{values}" WHERE {condition};'
30
+ )
31
+
32
+ def deleteEntry(self, table, condition):
33
+ self.executeCommand(f"DELETE FROM {table} WHERE {condition};")
34
+
35
+ def readEntry(self, table, columns):
36
+ self.executeCommand(f"SELECT {columns} FROM {table};")
37
+ result = self.cursor.fetchall()
38
+ log.addEntry(f"Read entry: {result}", Logger.DEBUG_MASK)
39
+ return result
40
+
41
+ def readNumberOfEntries(self, table):
42
+ self.executeCommand(f"SELECT COUNT(*) FROM {table};")
43
+ result = self.cursor.fetchall()
44
+ log.addEntry(f"Read number of entries: {result}", Logger.DEBUG_MASK)
45
+ return result[0][0]
46
+
47
+ def readEntryFiltered(self, table, columns, filter):
48
+ self.executeCommand(f"SELECT {columns} FROM {table} WHERE {filter};")
49
+ result = self.cursor.fetchall()
50
+ log.addEntry(f"Read entry: {result}", Logger.DEBUG_MASK)
51
+ return result
52
+
53
+ def entryExistsOnTable(self, table, condition):
54
+ self.executeCommand(f"SELECT * FROM {table} WHERE {condition};")
55
+ entry = self.cursor.fetchall()
56
+ if len(entry) != 0:
57
+ return True
58
+ else:
59
+ return False
60
+
61
+ def deleteEntryFromTable(self, table, condition):
62
+ self.executeCommand(f"DELETE FROM {table} WHERE {condition};")
63
+
64
+ def commit(self):
65
+ self.con.commit()
66
+
67
+ def commitClose(self):
68
+ self.commit()
69
+ self.con.close()
articlib/systemUtils.py CHANGED
@@ -1,34 +1,33 @@
1
- import subprocess
2
- import datetime
3
-
4
- def executeCommand(command):
5
- result = subprocess.run(command)
6
- return result.returncode
7
-
8
- class command:
9
- def __init__(self, command, run=True, capture=True, timeout=-1):
10
- self.command = command
11
- self.capture = capture
12
- self.timeout = timeout
13
- if run:
14
- self.run
15
-
16
- def run(self):
17
- if self.timeout > 0:
18
- self.process = subprocess.run(command, capture_output=self.capture, timeout=self.timeout)
19
- else:
20
- self.runWithoutTimeout
21
-
22
-
23
- def runWithoutTimeout(self):
24
- self.process = subprocess.run(command, capture_output=self.capture)
25
-
26
- def stdout(self):
27
- return self.process.stdout
28
-
29
- def stderr(self):
30
- return self.process.stderr
31
-
32
-
33
-
34
-
1
+ import subprocess
2
+ import datetime
3
+
4
+
5
+ def executeCommand(command):
6
+ result = subprocess.run(command)
7
+ return result.returncode
8
+
9
+
10
+ class command:
11
+ def __init__(self, command, run=True, capture=True, timeout=-1):
12
+ self.command = command
13
+ self.capture = capture
14
+ self.timeout = timeout
15
+ if run:
16
+ self.run
17
+
18
+ def run(self):
19
+ if self.timeout > 0:
20
+ self.process = subprocess.run(
21
+ command, capture_output=self.capture, timeout=self.timeout
22
+ )
23
+ else:
24
+ self.runWithoutTimeout
25
+
26
+ def runWithoutTimeout(self):
27
+ self.process = subprocess.run(command, capture_output=self.capture)
28
+
29
+ def stdout(self):
30
+ return self.process.stdout
31
+
32
+ def stderr(self):
33
+ return self.process.stderr