Skip to content

Commit 815b1d3

Browse files
committed
Bumped to version v2.1.9
1 parent 486795a commit 815b1d3

35 files changed

Lines changed: 729 additions & 682 deletions

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def run(self):
9898
author_email=EMAIL,
9999
python_requires=REQUIRES_PYTHON,
100100
url=URL,
101-
packages=['src', 'src/api', 'src/core', 'src/utils'],
101+
packages=['src', 'src/api', 'src/core',
102+
'src/utils', 'src/config', 'src/core/initor'],
102103
# If your package is a single module, use this instead of 'packages':
103104
# py_modules=['mypackage'],
104105

src/api/__init__.py

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1 @@
11
# -*- coding: utf-8 -*-
2-
import json
3-
from typing import Any
4-
5-
import requests
6-
7-
from src.api.base import Base
8-
from src.utils import UA
9-
10-
from .article import ArticleAPI
11-
from .chat import ChatAPI
12-
from .chatroom import ChatRoomAPI
13-
from .config import GLOBAL_CONFIG
14-
from .user import UserAPI
15-
16-
17-
class UserInfo(object):
18-
19-
def __init__(self, username: str, password: str, api_key: str) -> None:
20-
self.username = username
21-
self.password = password
22-
self.api_key = api_key
23-
self.ws: dict[str, Any] = {}
24-
self.in_chatroom = False
25-
26-
def online(self, *funcs) -> None:
27-
if (len(self.api_key) != 0):
28-
API.set_token(self.api_key)
29-
API.set_current_user(self.username)
30-
else:
31-
API.login(self.username, self.password)
32-
self.api_key = API.api_key
33-
for func in funcs:
34-
func()
35-
self.in_chatroom = True
36-
GLOBAL_CONFIG.auth_config.username = self.username
37-
GLOBAL_CONFIG.auth_config.password = self.password
38-
GLOBAL_CONFIG.auth_config.key = self.api_key
39-
API.user_key_write_to_config_file()
40-
41-
def out_chatroom(self) -> None:
42-
if 'fishpi.cn/chat-room-channel' in self.ws:
43-
self.ws['fishpi.cn/chat-room-channel'].stop()
44-
self.in_chatroom = False
45-
46-
def offline(self) -> None:
47-
keys = list(self.ws.keys())
48-
for key in keys:
49-
self.ws[key].stop()
50-
self.in_chatroom = False
51-
52-
def out_chat(self) -> None:
53-
if 'fishpi.cn/chat-channel' in self.ws:
54-
self.ws['fishpi.cn/chat-channel'].stop()
55-
56-
def chat(self, func) -> None:
57-
self.out_chat()
58-
self.out_chatroom()
59-
func()
60-
61-
62-
class FishPi(Base):
63-
def __init__(self):
64-
self.sockpuppets: dict[str, UserInfo] = {}
65-
self.user = UserAPI()
66-
self.chatroom = ChatRoomAPI()
67-
self.article = ArticleAPI()
68-
self.chat = ChatAPI()
69-
super().__init__(self)
70-
71-
def set_token(self, key):
72-
super().set_token(key)
73-
self.user.set_token(key)
74-
self.chatroom.set_token(key)
75-
self.article.set_token(key)
76-
self.chat.set_token(key)
77-
78-
def get_current_user(self):
79-
return self.sockpuppets[self.current_user]
80-
81-
def get_breezemoons(self, page: int = 1, size: int = 10) -> dict | None:
82-
res = requests.get(
83-
f'{GLOBAL_CONFIG.host}/api/breezemoons?p={page}&size={size}', headers={'User-Agent': UA})
84-
print(res.text)
85-
response = json.loads(res.text)
86-
if 'code' in response and response['code'] == 0:
87-
return response['breezemoons']
88-
else:
89-
print(response['msg'])
90-
return None
91-
92-
93-
API = FishPi()

src/api/article.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
import requests
99
from bs4 import BeautifulSoup
1010

11-
from src.api import Base
11+
from src.api.base import Base
12+
from src.config import GLOBAL_CONFIG
1213
from src.utils import UA
1314

14-
from .config import GLOBAL_CONFIG
15-
1615

1716
class ArticleType(Enum):
1817
RECENT = 'recent'

src/api/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
import requests
99

10+
from src.config import GLOBAL_CONFIG
1011
from src.utils import HELP, UA
1112

12-
from .config import GLOBAL_CONFIG
13-
1413

1514
class Base(object):
1615
def __init__(self, key=''):

src/api/bolo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import requests
33

4-
from src.api.config import GLOBAL_CONFIG
4+
from src.config import GLOBAL_CONFIG
55
from src.utils import UA
66

77

src/api/chat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
import requests
55

6+
from src.api.base import Base
7+
from src.config import GLOBAL_CONFIG
68
from src.utils import UA
79

8-
from .base import Base
9-
from .config import GLOBAL_CONFIG
10-
1110

1211
class ChatAPI(Base):
1312

src/api/chatroom.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
import requests
66

7-
from src.api import Base
7+
from src.api.base import Base
88
from src.api.redpacket import RedPacket, RedPacketType
9+
from src.config import GLOBAL_CONFIG
910
from src.utils import UA
1011
from src.utils.version import __version__
1112

12-
from .config import GLOBAL_CONFIG
13-
1413

1514
class ChatRoomAPI(Base):
1615

src/api/config.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

src/api/user.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
import requests
66

7-
from src.api import Base
7+
from src.api.base import Base
8+
from src.config import GLOBAL_CONFIG
89
from src.utils import UA
910

10-
from .config import GLOBAL_CONFIG
11-
1211

1312
class UserAPI(Base):
1413

src/config/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
import configparser
3+
4+
from src.utils import HOST
5+
6+
from .auth import AuthConfig
7+
from .bolo import BoloConfig
8+
from .chat import ChatConfig
9+
from .redpacket import RedPacketConfig
10+
11+
12+
class Config(object):
13+
def __init__(self, auth: AuthConfig = None, redpacket: RedPacketConfig = None, chat: ChatConfig = None, bolo: BoloConfig = None, cfg_path: str = None, host: str = 'https://fishpi.cn'):
14+
self.auth_config = auth
15+
self.redpacket_config = redpacket
16+
self.chat_config = chat
17+
self.bolo_config = bolo
18+
self.cfg_path = cfg_path
19+
self.host = host
20+
21+
def to_ini_template(self) -> configparser.ConfigParser:
22+
config = configparser.ConfigParser()
23+
config['auth'] = self.auth_config.to_config()
24+
config['redPacket'] = self.redpacket_config.to_config()
25+
config['chat'] = self.chat_config.to_config()
26+
config['bolo'] = self.bolo_config.to_config()
27+
return config
28+
29+
30+
class CliOptions(object):
31+
def __init__(self, username: str = '', password: str = '', code: str = '', file_path: str = None, host: str = None):
32+
self.username = username
33+
self.password = password
34+
self.code = code
35+
self.file_path = file_path
36+
self.host = host
37+
38+
39+
def init_defualt_config() -> Config:
40+
return Config(AuthConfig(), RedPacketConfig(), ChatConfig(), BoloConfig('', '', ''), None, HOST)
41+
42+
43+
GLOBAL_CONFIG = Config()

0 commit comments

Comments
 (0)