PyUp-LifeUp-API 0.1.1__py3-none-any.whl → 1.0.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.
pyup/__init__.py CHANGED
@@ -1,15 +1,15 @@
1
- """
2
- PyUp
3
- =====
4
-
5
- an easy to use python library for integrating LifeUp into your projects.
6
- """
7
- from .general import General
8
- from .task import Task
9
- from .shop import Shop
10
- from .pyup import PyUp
11
- from .atm import ATM
12
- from .pomodoro import Pomodoro
13
-
14
- __all__ = ["Task", "General", "PyUp", "Shop", "ATM", "Pomodoro"]
1
+ """
2
+ PyUp
3
+ =====
4
+
5
+ an easy to use python library for integrating LifeUp into your projects.
6
+ """
7
+ from .general import General
8
+ from .task import Task
9
+ from .shop import Shop
10
+ from .pyup import PyUp
11
+ from .atm import ATM
12
+ from .pomodoro import Pomodoro
13
+
14
+ __all__ = ["Task", "General", "PyUp", "Shop", "ATM", "Pomodoro"]
15
15
  __version__ = "0.1.1"
pyup/__main__.py CHANGED
@@ -1,33 +1,31 @@
1
- from requests import Response, Session
2
- from enum import Enum
3
- import re
4
- from datetime import datetime
5
-
6
- http = Session()
7
- class Type(Enum):
8
- COIN = 'coin'
9
- EXP = 'exp'
10
- ITEM = 'item'
11
-
12
- class CountSetType(Enum):
13
- ABSOLUTE = 'absolute'
14
- RELATIVE = 'relative'
15
-
16
-
17
- def call(call,host,port) -> Response:
18
-
19
- url = 'http://' + host + ':' + port + '/api?' + call
20
- return http.get(url=url)
21
-
22
- def color_check(hex: str):
23
- match = re.seach(r'^#(?:[0-9a-fA-F]{3}){1,2}$', hex)
24
-
25
- if match:
26
- return True
27
- else:
28
- return False
29
-
30
- def time_to_epoch(date:datetime):
31
-
32
- return int(date.timestamp()) * 1000
33
-
1
+ from requests import Response, Session
2
+ from enum import Enum
3
+ import re
4
+ from datetime import datetime
5
+
6
+ http = Session()
7
+ class Type(Enum):
8
+ COIN = 'coin'
9
+ EXP = 'exp'
10
+ ITEM = 'item'
11
+
12
+ class CountSetType(Enum):
13
+ ABSOLUTE = 'absolute'
14
+ RELATIVE = 'relative'
15
+
16
+
17
+ def call(call,host,port) -> Response:
18
+
19
+ url = 'http://' + host + ':' + port + '/api?' + call
20
+ return http.get(url=url)
21
+
22
+ def color_check(hex: str | None) -> bool:
23
+ if hex is None:
24
+ return True
25
+
26
+ return re.fullmatch(r'#(?:[0-9a-fA-F]{3}){1,2}', hex) is not None
27
+
28
+ def time_to_epoch(date:datetime):
29
+
30
+ return int(date.timestamp()) * 1000
31
+
pyup/atm.py CHANGED
@@ -1,58 +1,74 @@
1
- from .pyup import PyUp
2
- from .__main__ import *
3
-
4
- class ATM(PyUp):
5
-
6
- def __init__(self, pyup:PyUp):
7
- '''
8
- Some api calls for communicating with the shop in LifeUp.
9
- '''
10
- super().__init__(pyup.host, pyup.port)
11
- self.host = pyup.host
12
- self.port = pyup.port
13
-
14
- def deposit(self, amount: int):
15
-
16
- params = vars()
17
- try:
18
- params.pop('self')
19
- finally:
20
- pass
21
-
22
- if amount < 1:
23
- raise ValueError('param: amount: value must be greater than 0')
24
-
25
- url = 'url=lifeup://api/deposit?'
26
- for key, value in params.items():
27
- if value is not None:
28
- url = url + key + '=' + str(value) + '%26'
29
- else:
30
- continue
31
- url = url[:-3]
32
-
33
- result = call(call=url,host=self.host,port=self.port)
34
-
35
- return result
36
-
37
- def withdraw(self, amount: int):
38
-
39
- params = vars()
40
- try:
41
- params.pop('self')
42
- finally:
43
- pass
44
-
45
- if amount < 1:
46
- raise ValueError('param: amount: value must be greater than 0')
47
-
48
- url = 'url=lifeup://api/withdraw?'
49
- for key, value in params.items():
50
- if value is not None:
51
- url = url + key + '=' + str(value) + '%26'
52
- else:
53
- continue
54
- url = url[:-3]
55
-
56
- result = call(call=url,host=self.host,port=self.port)
57
-
1
+ from .pyup import PyUp
2
+ from .__main__ import *
3
+
4
+ class ATM(PyUp):
5
+
6
+ def __init__(self, pyup:PyUp):
7
+ '''
8
+ Create ATM API methods using an existing LifeUp connection.
9
+
10
+ :param PyUp pyup: Configured PyUp connection containing the LifeUp host and port.
11
+ '''
12
+ super().__init__(pyup.host, pyup.port)
13
+ self.host = pyup.host
14
+ self.port = pyup.port
15
+
16
+ def deposit(self, amount: int):
17
+ '''
18
+ Deposit coins into the LifeUp bank.
19
+
20
+ :param int amount: Number of coins to deposit (must be greater than 0).
21
+ :return: :class:`Response <Response>` object
22
+ :rtype: requests.Response
23
+ '''
24
+
25
+ params = vars()
26
+ try:
27
+ params.pop('self')
28
+ finally:
29
+ pass
30
+
31
+ if amount < 1:
32
+ raise ValueError('param: amount: value must be greater than 0')
33
+
34
+ url = 'url=lifeup://api/deposit?'
35
+ for key, value in params.items():
36
+ if value is not None:
37
+ url = url + key + '=' + str(value) + '%26'
38
+ else:
39
+ continue
40
+ url = url[:-3]
41
+
42
+ result = call(call=url,host=self.host,port=self.port)
43
+
44
+ return result
45
+
46
+ def withdraw(self, amount: int):
47
+ '''
48
+ Withdraw coins from the LifeUp bank.
49
+
50
+ :param int amount: Number of coins to withdraw (must be greater than 0).
51
+ :return: :class:`Response <Response>` object
52
+ :rtype: requests.Response
53
+ '''
54
+
55
+ params = vars()
56
+ try:
57
+ params.pop('self')
58
+ finally:
59
+ pass
60
+
61
+ if amount < 1:
62
+ raise ValueError('param: amount: value must be greater than 0')
63
+
64
+ url = 'url=lifeup://api/withdraw?'
65
+ for key, value in params.items():
66
+ if value is not None:
67
+ url = url + key + '=' + str(value) + '%26'
68
+ else:
69
+ continue
70
+ url = url[:-3]
71
+
72
+ result = call(call=url,host=self.host,port=self.port)
73
+
58
74
  return result
pyup/general.py CHANGED
@@ -1,114 +1,114 @@
1
- from .pyup import PyUp
2
- from .__main__ import *
3
-
4
- class General(PyUp):
5
-
6
- def __init__(self, pyup: PyUp):
7
- '''
8
- Some general api calls for communication with LifeUp.
9
- '''
10
- super().__init__(pyup.host, pyup.port)
11
- self.host = pyup.host
12
- self.port = pyup.port
13
-
14
- def reward(self, content: str, type: str, number: int, skills: list = None, item_id: int = None, item_name: str = None, silent: bool = None) -> Response:
15
- '''
16
- Provide the reward directly. The reason for the reward can be customized.
17
-
18
- :param str content: text that appears on the reward notification.
19
- :param str type: reward type (must be either 'coin', 'exp' or 'item').
20
- :param int number: amount of reward given.
21
- :param (optional) list skills: array of numbers greater than 0. dicates what skills recieve the exp reward.
22
- :param (optional) int item_id: the numerical id of the item the user recieves as a reward.
23
- :param (optional) str item_name: the name of the item the user recieves as a reward.
24
- :param (optional) bool silent: wether the UI notification appears or not.
25
- :return: :class:`Response <Response>` object
26
- :rtype: requests.Response
27
- '''
28
- if type != 'coin' or 'exp' or 'item':
29
- raise ValueError("param: content: value must be a value of 'coin', 'exp' or 'item'.")
30
- if type == 'item' and item_id == 0 or item_name == '':
31
- raise ValueError("param: type: value 'item' requires item_id and item_name to have values.")
32
-
33
- params = vars()
34
- try:
35
- params.pop('self')
36
- finally:
37
- pass
38
-
39
- url = 'url=lifeup://api/reward?'
40
- for key, value in params.items():
41
- if value is not None:
42
- url = url + key + '=' + str(value) + '%26'
43
- else:
44
- continue
45
- url = url[:-3]
46
- result = call(call=url)
47
- return result
48
-
49
- def toast(self, text: str, type: int = 0, isLong: bool = False) -> Response:
50
- '''
51
- Various styles of messages pop up.
52
-
53
- :param str text: the message that appears on the prompt.
54
- :param (optional) int type: a number from 0-6 defining the text style.
55
- :param (optional) bool isLong: display duration, True = long, False = short.
56
- :return: :class:`Response <Response>` object
57
- :rtype: requests.Response
58
- '''
59
- if type < 0 or type > 6 or not isinstance(type,int):
60
- raise ValueError('param: type: value must be a whole number between 0 and 6')
61
-
62
- params = vars()
63
- try:
64
- params.pop('self')
65
- finally:
66
- pass
67
-
68
- url = 'url=lifeup://api/toast?'
69
- for key, value in params.items():
70
- if value is not None:
71
- url = url + key + '=' + str(value) + '%26'
72
- else:
73
- continue
74
- url = url[:-3]
75
-
76
- result = call(call=url)
77
-
78
- return result
79
-
80
- def penality(self, content: str, type: str, number: int, skills: list = None, item_id:int = None, item_name: str = None, silent: bool = None) -> Response:
81
- '''
82
- Provide a penalty directly. The reason for the penalty can be customized.
83
-
84
- :param str content: text that appears on the reward notification.
85
- :param str type: reward type (must be either 'coin', 'exp' or 'item').
86
- :param int number: amount of reward given.
87
- :param (optional) list skills: array of numbers greater than 0. dicates what skills recieve the exp reward.
88
- :param (optional) int item_id: the numerical id of the item the user recieves as a reward.
89
- :param (optional) str item_name: the name of the item the user recieves as a reward.
90
- :param (optional) bool silent: wether the UI notification appears or not.
91
- :return: :class:`Response <Response>` object
92
- :rtype: requests.Response
93
- '''
94
-
95
- if type == 'item' and item_id == 0 and item_name == '':
96
- raise ValueError("param: type: value 'item' requires item_id and item_name.")
97
-
98
- params = vars()
99
- try:
100
- params.pop('self')
101
- finally:
102
- pass
103
-
104
- url = 'url=lifeup://api/penality?'
105
- for key, value in params.items():
106
- if value is not None:
107
- url = url + key + '=' + str(value) + '%26'
108
- else:
109
- continue
110
- url = url[:-3]
111
-
112
- result = call(call=url)
113
-
1
+ from .pyup import PyUp
2
+ from .__main__ import *
3
+
4
+ class General(PyUp):
5
+
6
+ def __init__(self, pyup: PyUp):
7
+ '''
8
+ Some general api calls for communication with LifeUp.
9
+ '''
10
+ super().__init__(pyup.host, pyup.port)
11
+ self.host = pyup.host
12
+ self.port = pyup.port
13
+
14
+ def reward(self, content: str, type: str, number: int, skills: list = None, item_id: int = None, item_name: str = None, silent: bool = None) -> Response:
15
+ '''
16
+ Provide the reward directly. The reason for the reward can be customized.
17
+
18
+ :param str content: text that appears on the reward notification.
19
+ :param str type: reward type (must be either 'coin', 'exp' or 'item').
20
+ :param int number: amount of reward given.
21
+ :param (optional) list skills: array of numbers greater than 0. dicates what skills recieve the exp reward.
22
+ :param (optional) int item_id: the numerical id of the item the user recieves as a reward.
23
+ :param (optional) str item_name: the name of the item the user recieves as a reward.
24
+ :param (optional) bool silent: wether the UI notification appears or not.
25
+ :return: :class:`Response <Response>` object
26
+ :rtype: requests.Response
27
+ '''
28
+ if type not in ('coin', 'exp', 'item'):
29
+ raise ValueError("param: content: value must be a value of 'coin', 'exp' or 'item'.")
30
+ if type == 'item' and item_id == 0 or item_name == '':
31
+ raise ValueError("param: type: value 'item' requires item_id and item_name to have values.")
32
+
33
+ params = vars()
34
+ try:
35
+ params.pop('self')
36
+ finally:
37
+ pass
38
+
39
+ url = 'url=lifeup://api/reward?'
40
+ for key, value in params.items():
41
+ if value is not None:
42
+ url = url + key + '=' + str(value) + '%26'
43
+ else:
44
+ continue
45
+ url = url[:-3]
46
+ result = call(call=url, host=self.host, port=self.port)
47
+ return result
48
+
49
+ def toast(self, text: str, type: int = 0, isLong: bool = False) -> Response:
50
+ '''
51
+ Various styles of messages pop up.
52
+
53
+ :param str text: the message that appears on the prompt.
54
+ :param (optional) int type: a number from 0-6 defining the text style.
55
+ :param (optional) bool isLong: display duration, True = long, False = short.
56
+ :return: :class:`Response <Response>` object
57
+ :rtype: requests.Response
58
+ '''
59
+ if type < 0 or type > 6 or not isinstance(type,int):
60
+ raise ValueError('param: type: value must be a whole number between 0 and 6')
61
+
62
+ params = vars()
63
+ try:
64
+ params.pop('self')
65
+ finally:
66
+ pass
67
+
68
+ url = 'url=lifeup://api/toast?'
69
+ for key, value in params.items():
70
+ if value is not None:
71
+ url = url + key + '=' + str(value) + '%26'
72
+ else:
73
+ continue
74
+ url = url[:-3]
75
+
76
+ result = call(call=url, host=self.host, port=self.port)
77
+
78
+ return result
79
+
80
+ def penality(self, content: str, type: str, number: int, skills: list = None, item_id:int = None, item_name: str = None, silent: bool = None) -> Response:
81
+ '''
82
+ Provide a penalty directly. The reason for the penalty can be customized.
83
+
84
+ :param str content: text that appears on the reward notification.
85
+ :param str type: reward type (must be either 'coin', 'exp' or 'item').
86
+ :param int number: amount of reward given.
87
+ :param (optional) list skills: array of numbers greater than 0. dicates what skills recieve the exp reward.
88
+ :param (optional) int item_id: the numerical id of the item the user recieves as a reward.
89
+ :param (optional) str item_name: the name of the item the user recieves as a reward.
90
+ :param (optional) bool silent: wether the UI notification appears or not.
91
+ :return: :class:`Response <Response>` object
92
+ :rtype: requests.Response
93
+ '''
94
+
95
+ if type == 'item' and item_id == 0 and item_name == '':
96
+ raise ValueError("param: type: value 'item' requires item_id and item_name.")
97
+
98
+ params = vars()
99
+ try:
100
+ params.pop('self')
101
+ finally:
102
+ pass
103
+
104
+ url = 'url=lifeup://api/penality?'
105
+ for key, value in params.items():
106
+ if value is not None:
107
+ url = url + key + '=' + str(value) + '%26'
108
+ else:
109
+ continue
110
+ url = url[:-3]
111
+
112
+ result = call(call=url, host=self.host, port=self.port)
113
+
114
114
  return result