reykit 1.0.1__py3-none-any.whl → 1.1.1__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.
Files changed (60) hide show
  1. reydb/__init__.py +1 -1
  2. reydb/rbuild.py +44 -44
  3. reydb/rconnection.py +107 -107
  4. reydb/rexecute.py +9 -13
  5. reydb/rfile.py +8 -8
  6. reydb/rinformation.py +13 -25
  7. reydb/rparameter.py +10 -10
  8. reykit/__init__.py +1 -1
  9. reykit/rcomm.py +12 -12
  10. reykit/rdata.py +4 -4
  11. reykit/remail.py +12 -14
  12. reykit/rexception.py +4 -4
  13. reykit/rimage.py +9 -9
  14. reykit/rlog.py +30 -30
  15. reykit/rmonkey.py +4 -5
  16. reykit/rmultitask.py +14 -15
  17. reykit/rnumber.py +2 -2
  18. reykit/ros.py +21 -21
  19. reykit/rrandom.py +11 -11
  20. reykit/rregex.py +10 -13
  21. reykit/rschedule.py +10 -10
  22. reykit/rstdout.py +13 -13
  23. reykit/rsystem.py +224 -30
  24. reykit/rtable.py +31 -31
  25. reykit/rtext.py +3 -3
  26. reykit/rtime.py +11 -31
  27. reykit/rtype.py +2 -2
  28. reykit/rwrap.py +16 -16
  29. reykit/rzip.py +4 -5
  30. {reykit-1.0.1.dist-info → reykit-1.1.1.dist-info}/METADATA +1 -1
  31. reykit-1.1.1.dist-info/RECORD +38 -0
  32. reykit-1.0.1.dist-info/RECORD +0 -64
  33. reyweb/__init__.py +0 -19
  34. reyweb/rall.py +0 -12
  35. reyweb/rbaidu/__init__.py +0 -21
  36. reyweb/rbaidu/rbaidu_base.py +0 -186
  37. reyweb/rbaidu/rbaidu_chat.py +0 -299
  38. reyweb/rbaidu/rbaidu_image.py +0 -183
  39. reyweb/rbaidu/rbaidu_voice.py +0 -256
  40. reywechat/__init__.py +0 -32
  41. reywechat/data/client_api.dll +0 -0
  42. reywechat/rall.py +0 -20
  43. reywechat/rclient.py +0 -912
  44. reywechat/rdatabase.py +0 -1189
  45. reywechat/rexception.py +0 -65
  46. reywechat/rexecute.py +0 -201
  47. reywechat/rlog.py +0 -198
  48. reywechat/rreceive.py +0 -1232
  49. reywechat/rschedule.py +0 -136
  50. reywechat/rsend.py +0 -630
  51. reywechat/rwechat.py +0 -201
  52. reyworm/__init__.py +0 -24
  53. reyworm/rall.py +0 -16
  54. reyworm/rbrowser.py +0 -134
  55. reyworm/rcalendar.py +0 -159
  56. reyworm/rnews.py +0 -126
  57. reyworm/rsecurity.py +0 -239
  58. reyworm/rtranslate.py +0 -75
  59. {reykit-1.0.1.dist-info → reykit-1.1.1.dist-info}/WHEEL +0 -0
  60. {reykit-1.0.1.dist-info → reykit-1.1.1.dist-info}/top_level.txt +0 -0
reywechat/rwechat.py DELETED
@@ -1,201 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2023-10-17 20:27:16
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : WeChat methods.
9
- """
10
-
11
-
12
- from typing import Literal, Optional, Union
13
- from os import getcwd as os_getcwd
14
- from os.path import join as os_join
15
- from reydb.rconnection import RDatabase as RRDatabase
16
- from reykit.ros import create_folder as reytool_create_folder
17
- from reykit.rsystem import block
18
-
19
-
20
- __all__ = (
21
- 'RWeChat',
22
- )
23
-
24
-
25
- class RWeChat(object):
26
- """
27
- Rey's `WeChat` type.
28
-
29
- Will start client API service with port `19088` and message callback service with port '19089'.
30
-
31
- Warnings, only applicable to WeChat clients with version `3.9.5.81`.
32
-
33
- Warnings, must close file automatic download.
34
-
35
- Warnings, the operating system version cannot be lower than `Windows 10 version 1709` or `Windows Server 2016 version 1709`.
36
-
37
- Warnings, need support “Microsoft Visual C++2015”.
38
- """
39
-
40
-
41
- def __init__(
42
- self,
43
- rrdatabase: Optional[Union[RRDatabase, dict[Literal['wechat', 'file'], RRDatabase]]],
44
- max_receiver: int = 2,
45
- bandwidth_downstream: float = 5,
46
- bandwidth_upstream: float = 5,
47
- project_dir: Optional[str] = None
48
- ) -> None:
49
- """
50
- Build `WeChat` attributes.
51
-
52
- Parameters
53
- ----------
54
- rrdatabase : `RDatabase` instance of `reykit` package.
55
- - `RDatabase`, Set all `RDatabase`: instances.
56
- - `dict`, Set each `RDatabase`: instance, all item is required.
57
- `Key 'wechat'`: `RDatabase` instance used in WeChat methods.
58
- `Key 'file'`: `RDatabase` instance used in file methods.
59
- max_receiver : Maximum number of receivers.
60
- bandwidth_downstream : Download bandwidth, impact receive timeout, unit Mpbs.
61
- bandwidth_upstream : Upload bandwidth, impact send interval, unit Mpbs.
62
- project_dir: Project directory, will create sub folders.
63
- - `None`: Use working directory.
64
- - `str`: Use this directory.
65
- """
66
-
67
- # Import.
68
- from .rclient import RClient
69
- from .rdatabase import RDatabase
70
- from .rlog import RLog
71
- from .rreceive import RReceive
72
- from .rschedule import RSchedule
73
- from .rsend import RSend
74
-
75
- # Create folder.
76
- project_dir = project_dir or os_getcwd()
77
- self._create_folder(project_dir)
78
-
79
- # Set attribute.
80
-
81
- ## Instance.
82
- self.rclient = RClient(self)
83
- self.rlog = RLog(self)
84
- self.rreceive = RReceive(self, max_receiver, bandwidth_downstream)
85
- self.rsend = RSend(self, bandwidth_upstream)
86
- self.rdatabase = RDatabase(self, rrdatabase)
87
- self.rschedule = RSchedule(self)
88
-
89
- ## Client.
90
- self.client_version = self.rclient.client_version
91
- self.client_version_int = self.rclient.client_version_int
92
- self.client_version_simulate = self.rclient.client_version_simulate
93
- self.client_version_simulate_int = self.rclient.client_version_simulate_int
94
- self.client_api_port = self.rclient.client_api_port
95
- self.message_callback_port = self.rclient.message_callback_port
96
-
97
- ## Receive.
98
- self.receive_add_handler = self.rreceive.add_handler
99
- self.receive_start = self.rreceive.start
100
- self.receive_stop = self.rreceive.stop
101
-
102
- ## Send.
103
- self.send_add_handler = self.rsend.add_handler
104
- self.send = self.rsend.send
105
- self.send_start = self.rsend.start
106
- self.send_stop = self.rsend.stop
107
- self.wrap_try_send = self.rsend.wrap_try_send
108
-
109
- ## Execute.
110
- self.rexecute = self.rreceive.rexecute
111
- self.execute_add_rule = self.rexecute.add_rule
112
-
113
- ## Schedule.
114
- self.schedule_add = self.rschedule.add
115
- self.schedule_pause = self.rschedule.pause
116
- self.schedule_resume = self.rschedule.resume
117
-
118
-
119
- def _create_folder(
120
- self,
121
- project_dir: str
122
- ) -> None:
123
- """
124
- Create project standard folders.
125
-
126
- Parameters
127
- ----------
128
- project_dir: Project directory, will create sub folders.
129
- """
130
-
131
- # Set parameter.
132
- folders = (
133
- 'Log',
134
- 'File'
135
- )
136
- folder_dict = {
137
- folder: os_join(project_dir, folder)
138
- for folder in folders
139
- }
140
-
141
- # Create.
142
- paths = folder_dict.values()
143
- reytool_create_folder(*paths)
144
-
145
- # Set attribute.
146
- self.dir_log = folder_dict['Log']
147
- self.dir_file = folder_dict['File']
148
-
149
-
150
- def start(self) -> None:
151
- """
152
- Start all methods.
153
- """
154
-
155
- # Start.
156
- self.receive_start()
157
- self.send_start()
158
-
159
-
160
- def keep(self) -> None:
161
- """
162
- Blocking the main thread to keep running.
163
- """
164
-
165
- # Report.
166
- print('Keep runing.')
167
-
168
- # Blocking.
169
- block()
170
-
171
-
172
- @property
173
- def print_colour(self) -> bool:
174
- """
175
- Whether print colour.
176
-
177
- Returns
178
- -------
179
- Result.
180
- """
181
-
182
- # Get parameter.
183
- result = self.rlog.rrlog.print_colour
184
-
185
- return result
186
-
187
-
188
- @print_colour.setter
189
- def print_colour(self, value: bool) -> None:
190
- """
191
- Set whether print colour.
192
-
193
- Parameters
194
- ----------
195
- value : Set value.
196
- """
197
-
198
- # Set.
199
- self.rlog.rrlog.print_colour = value
200
- self.rlog.rrlog_print.print_colour = value
201
- self.rlog.rrlog_file.print_colour = value
reyworm/__init__.py DELETED
@@ -1,24 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2023-02-19 18:59:26
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Rey's worm method set.
9
-
10
- Modules
11
- -------
12
- rall : All methods.
13
- rbrowser : Browser methods.
14
- rcalendar : Calendar methods.
15
- rnews : News methods.
16
- rsecurity : Security methods.
17
- rtranslate : Translate methods.
18
- """
19
-
20
-
21
- from typing import Final
22
-
23
-
24
- __version__: Final[str] = '1.0.0'
reyworm/rall.py DELETED
@@ -1,16 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2022-12-08 13:11:09
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : All methods.
9
- """
10
-
11
-
12
- from .rbrowser import *
13
- from .rcalendar import *
14
- from .rnews import *
15
- from .rsecurity import *
16
- from .rtranslate import *
reyworm/rbrowser.py DELETED
@@ -1,134 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2023-12-29 23:14:18
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Browser methods.
9
- """
10
-
11
-
12
- from typing import Any, Literal, Optional
13
- from selenium.webdriver import Edge, Chrome, EdgeOptions, ChromeOptions
14
- from reykit.rcomm import join_url
15
- from reykit.rtime import sleep
16
-
17
-
18
- __all__ = (
19
- 'RBrowser',
20
- 'get_page'
21
- )
22
-
23
-
24
- class RBrowser(object):
25
- """
26
- Rey's `browser` type.
27
- """
28
-
29
-
30
- def __init__(
31
- self,
32
- driver: Literal['edge', 'chrome'] = 'edge',
33
- headless: bool = False
34
- ) -> None:
35
- """
36
- Build `browser` attributes.
37
-
38
- Parameters
39
- ----------
40
- driver : Browser driver type.
41
- - `Literal['edge']`: Edge browser.
42
- - `Literal['chrome']`: Chrome browser.
43
- headless : Whether use headless mode.
44
- """
45
-
46
- # Get parameter.
47
- match driver:
48
- case 'edge':
49
- driver_type = Edge
50
- driver_option_type = EdgeOptions
51
- case 'chrome':
52
- driver_type = Chrome
53
- driver_option_type = ChromeOptions
54
-
55
- # Option.
56
- options = driver_option_type()
57
-
58
- ## Headless.
59
- if headless:
60
- options.add_argument('--headless')
61
-
62
- # Driver.
63
- self.driver = driver_type(options)
64
-
65
-
66
- def request(
67
- self,
68
- url: str,
69
- params: Optional[dict[str, Any]] = None
70
- ) -> None:
71
- """
72
- Request URL.
73
-
74
- Parameters
75
- ----------
76
- url : URL.
77
- params : URL parameters.
78
- """
79
-
80
- # Get parameter.
81
- if params is None:
82
- params = {}
83
- url = join_url(url, params)
84
-
85
- # Request.
86
- self.driver.get(url)
87
-
88
-
89
- @property
90
- def page(self) -> str:
91
- """
92
- Return page elements document.
93
-
94
- Returns
95
- -------
96
- Page elements document.
97
- """
98
-
99
- # Get parameter.
100
- page_source = self.driver.page_source
101
-
102
- return page_source
103
-
104
-
105
- __call__ = request
106
-
107
-
108
- def get_page(
109
- url: str,
110
- params: Optional[dict[str, Any]] = None
111
- ) -> str:
112
- """
113
- Get page elements document.
114
-
115
- Parameters
116
- ----------
117
- url : URL.
118
- params : URL parameters.
119
-
120
- Returns
121
- -------
122
- Page elements document.
123
- """
124
-
125
- # Get parameter.
126
- browser = RBrowser(headless=True)
127
-
128
- # Request.
129
- browser.request(url, params)
130
-
131
- # Page.
132
- page = browser.page
133
-
134
- return page
reyworm/rcalendar.py DELETED
@@ -1,159 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2024-01-10 21:57:08
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Calendar methods.
9
- """
10
-
11
-
12
- from typing import Optional
13
- from json import loads as json_loads
14
- from reykit.rcomm import request
15
- from reykit.rregex import search
16
- from reykit.rtime import now
17
-
18
-
19
- __all__ = (
20
- 'get_calendar',
21
- 'get_lunar_calendar'
22
- )
23
-
24
-
25
- def get_calendar(
26
- year: Optional[int] = None,
27
- month: Optional[int] = None
28
- ) -> list[dict]:
29
- """
30
- Get calendar table for three months from `baidu` website.
31
-
32
- Parameters
33
- ----------
34
- year : Given year.
35
- - `None`: Now year.
36
- month : Given month.
37
- - `None`: Now month.
38
-
39
- Returns
40
- -------
41
- Calendar table.
42
- """
43
-
44
- # Get parameter.
45
- now_date = now('date')
46
- year = year or now_date.year
47
- month = month or now_date.month
48
- if month == 12:
49
- month = 1
50
- else:
51
- month += 1
52
- url = 'https://opendata.baidu.com/data/inner'
53
- query = '%s年%s月' % (year, month)
54
- params = {
55
- 'tn': 'reserved_all_res_tn',
56
- 'type': 'json',
57
- 'resource_id': '52109',
58
- 'query': query,
59
- 'apiType': 'yearMonthData',
60
- 'cb': 'jsonp_1706670926975_94318'
61
- }
62
-
63
- # Request.
64
- response = request(url, params)
65
-
66
- # Extract.
67
- pattern = '{.+}'
68
- text = search(pattern, response.text)
69
- data: dict = json_loads(text)
70
- table: list[dict] = data['Result'][0]['DisplayData']['resultData']['tplData']['data']['almanac']
71
-
72
- # Convert.
73
- week_dict = {
74
- '一': 0,
75
- '二': 1,
76
- '三': 2,
77
- '四': 3,
78
- '五': 4,
79
- '六': 5,
80
- '日': 6
81
- }
82
- table = [
83
- {
84
- 'year': int(row['year']),
85
- 'month': int(row['month']),
86
- 'day': int(row['day']),
87
- 'week': week_dict[row['cnDay']],
88
- 'work': row.get('status'),
89
- 'festival': [
90
- {
91
- 'name': info['name'],
92
- 'url': info.get('baikeUrl')
93
- }
94
- for info in row.get('festivalInfoList', [])
95
- ],
96
- 'animal': row['animal'],
97
- 'lunar_year': int(row['lunarYear']),
98
- 'lunar_month': int(row['lunarMonth']),
99
- 'lunar_day': int(row['lunarDate']),
100
- 'gz_year': row['gzYear'],
101
- 'gz_month': row['gzMonth'],
102
- 'gz_day': row['gzDate'],
103
- 'suit': row['suit'].split('.'),
104
- 'avoid': row['avoid'].split('.'),
105
- 'url': row['yjJumpUrl']
106
- }
107
- for row in table
108
- ]
109
- for row in table:
110
- week = row['week']
111
- work = row['work']
112
- match work:
113
- case None:
114
- is_work_day = week not in (5, 6)
115
- case '1':
116
- is_work_day = False
117
- case '2':
118
- is_work_day = True
119
- row['work'] = is_work_day
120
-
121
- return table
122
-
123
-
124
- def get_lunar_calendar(
125
- year: Optional[int] = None,
126
- month: Optional[int] = None
127
- ) -> list[dict]:
128
- """
129
- Get lunar calendar table for one month from `rili` website.
130
-
131
- Parameters
132
- ----------
133
- year : Given year.
134
- - `None`: Now year.
135
- month : Given month.
136
- - `None`: Now month.
137
-
138
- Returns
139
- -------
140
- Lunar calendar table.
141
- """
142
-
143
- # Get parameter.
144
- now_date = now('date')
145
- year = year or now_date.year
146
- month = month or now_date.month
147
- url = 'https://www.rili.com.cn/rili/json/pc_wnl/%s/%02d.js' % (year, month)
148
- params = {'_': now('timestamp')}
149
-
150
- # Request.
151
- response = request(url, params)
152
-
153
- # Extract.
154
- pattern = '{.+}'
155
- text = search(pattern, response.text)
156
- data = json_loads(text)
157
- table = data['data']
158
-
159
- return table
reyworm/rnews.py DELETED
@@ -1,126 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2024-01-22 14:06:05
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : News methods.
9
- """
10
-
11
-
12
- from typing import Any, Literal
13
- from reykit.rcomm import request, join_url
14
- from reykit.rtime import to_time, time_to
15
-
16
-
17
- __all__ = (
18
- 'get_weibo_hot_search',
19
- 'get_toutiao_hot_search'
20
- )
21
-
22
-
23
- def get_weibo_hot_search() -> list[dict[Literal['rank', 'time', 'title', 'type', 'hot', 'url'], Any]]:
24
- """
25
- Get hot search table from `weibo` website.
26
-
27
- Returns
28
- -------
29
- Hot search table.
30
- - `Key 'rank'`: Hot search rank.
31
- - `Key 'time'`: Hot search time.
32
- - `Key 'title'`: Hot search title.
33
- - `Key 'type'`: Hot search type.
34
- - `Key 'hot'`: Hot search hot value.
35
- - `Key 'url'`: Hot search URL.
36
- """
37
-
38
- # Request.
39
- url = 'https://weibo.com/ajax/side/hotSearch'
40
- response = request(url, check=True)
41
-
42
- # Extract.
43
- response_json = response.json()
44
- table: list[dict] = response_json['data']['realtime']
45
-
46
- # Convert.
47
- table = [
48
- {
49
- 'title': info['word'],
50
- 'hot': info['num'],
51
- 'url': join_url(
52
- 'https://s.weibo.com/weibo',
53
- {'q': '#%s#' % info['word']}
54
- )
55
- }
56
- for info in table
57
- if 'flag' in info
58
- ]
59
- func_sort = lambda row: (
60
- 0
61
- if row['hot'] is None
62
- else row['hot']
63
- )
64
- table.sort(key=func_sort, reverse=True)
65
- table = [
66
- {
67
- 'rank': index,
68
- **row
69
- }
70
- for index, row in enumerate(table)
71
- ]
72
-
73
- return table
74
-
75
-
76
- def get_toutiao_hot_search() -> list[dict[Literal['title', 'type', 'label', 'hot', 'url', 'image'], Any]]:
77
- """
78
- Get hot search table from `toutiao` website.
79
-
80
- Returns
81
- -------
82
- Hot search table.
83
- - `Key 'title'`: Hot search title.
84
- - `Key 'type'`: Hot search type list.
85
- - `Key 'label'`: Hot search label.
86
- - `Key 'hot'`: Hot search hot value.
87
- - `Key 'url'`: Hot search URL.
88
- - `Key 'image'`: Hot search image URL.
89
- """
90
-
91
- # Request.
92
- url = 'https://www.toutiao.com/hot-event/hot-board/'
93
- params = {'origin': 'toutiao_pc'}
94
- response = request(
95
- url,
96
- params,
97
- check=True
98
- )
99
-
100
- # Extract.
101
- response_json = response.json()
102
- table: list[dict] = response_json['data']
103
-
104
- # Convert.
105
- table = [
106
- {
107
- 'title': info['Title'],
108
- 'type': info.get('InterestCategory'),
109
- 'label': info.get('LabelDesc'),
110
- 'hot': int(info['HotValue']),
111
- 'url': info['Url'],
112
- 'image': info['Image']['url'],
113
- }
114
- for info in table
115
- ]
116
- func_sort = lambda row: row['hot']
117
- table.sort(key=func_sort, reverse=True)
118
- table = [
119
- {
120
- 'rank': index,
121
- **row
122
- }
123
- for index, row in enumerate(table)
124
- ]
125
-
126
- return table