Skip to content

Commit

Permalink
Bumped to version v2.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gakkiyomi committed Dec 24, 2024
1 parent 486795a commit 815b1d3
Show file tree
Hide file tree
Showing 35 changed files with 729 additions and 682 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def run(self):
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
packages=['src', 'src/api', 'src/core', 'src/utils'],
packages=['src', 'src/api', 'src/core',
'src/utils', 'src/config', 'src/core/initor'],
# If your package is a single module, use this instead of 'packages':
# py_modules=['mypackage'],

Expand Down
92 changes: 0 additions & 92 deletions src/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,93 +1 @@
# -*- coding: utf-8 -*-
import json
from typing import Any

import requests

from src.api.base import Base
from src.utils import UA

from .article import ArticleAPI
from .chat import ChatAPI
from .chatroom import ChatRoomAPI
from .config import GLOBAL_CONFIG
from .user import UserAPI


class UserInfo(object):

def __init__(self, username: str, password: str, api_key: str) -> None:
self.username = username
self.password = password
self.api_key = api_key
self.ws: dict[str, Any] = {}
self.in_chatroom = False

def online(self, *funcs) -> None:
if (len(self.api_key) != 0):
API.set_token(self.api_key)
API.set_current_user(self.username)
else:
API.login(self.username, self.password)
self.api_key = API.api_key
for func in funcs:
func()
self.in_chatroom = True
GLOBAL_CONFIG.auth_config.username = self.username
GLOBAL_CONFIG.auth_config.password = self.password
GLOBAL_CONFIG.auth_config.key = self.api_key
API.user_key_write_to_config_file()

def out_chatroom(self) -> None:
if 'fishpi.cn/chat-room-channel' in self.ws:
self.ws['fishpi.cn/chat-room-channel'].stop()
self.in_chatroom = False

def offline(self) -> None:
keys = list(self.ws.keys())
for key in keys:
self.ws[key].stop()
self.in_chatroom = False

def out_chat(self) -> None:
if 'fishpi.cn/chat-channel' in self.ws:
self.ws['fishpi.cn/chat-channel'].stop()

def chat(self, func) -> None:
self.out_chat()
self.out_chatroom()
func()


class FishPi(Base):
def __init__(self):
self.sockpuppets: dict[str, UserInfo] = {}
self.user = UserAPI()
self.chatroom = ChatRoomAPI()
self.article = ArticleAPI()
self.chat = ChatAPI()
super().__init__(self)

def set_token(self, key):
super().set_token(key)
self.user.set_token(key)
self.chatroom.set_token(key)
self.article.set_token(key)
self.chat.set_token(key)

def get_current_user(self):
return self.sockpuppets[self.current_user]

def get_breezemoons(self, page: int = 1, size: int = 10) -> dict | None:
res = requests.get(
f'{GLOBAL_CONFIG.host}/api/breezemoons?p={page}&size={size}', headers={'User-Agent': UA})
print(res.text)
response = json.loads(res.text)
if 'code' in response and response['code'] == 0:
return response['breezemoons']
else:
print(response['msg'])
return None


API = FishPi()
5 changes: 2 additions & 3 deletions src/api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import requests
from bs4 import BeautifulSoup

from src.api import Base
from src.api.base import Base
from src.config import GLOBAL_CONFIG
from src.utils import UA

from .config import GLOBAL_CONFIG


class ArticleType(Enum):
RECENT = 'recent'
Expand Down
3 changes: 1 addition & 2 deletions src/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import requests

from src.config import GLOBAL_CONFIG
from src.utils import HELP, UA

from .config import GLOBAL_CONFIG


class Base(object):
def __init__(self, key=''):
Expand Down
2 changes: 1 addition & 1 deletion src/api/bolo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import requests

from src.api.config import GLOBAL_CONFIG
from src.config import GLOBAL_CONFIG
from src.utils import UA


Expand Down
5 changes: 2 additions & 3 deletions src/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import requests

from src.api.base import Base
from src.config import GLOBAL_CONFIG
from src.utils import UA

from .base import Base
from .config import GLOBAL_CONFIG


class ChatAPI(Base):

Expand Down
5 changes: 2 additions & 3 deletions src/api/chatroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

import requests

from src.api import Base
from src.api.base import Base
from src.api.redpacket import RedPacket, RedPacketType
from src.config import GLOBAL_CONFIG
from src.utils import UA
from src.utils.version import __version__

from .config import GLOBAL_CONFIG


class ChatRoomAPI(Base):

Expand Down
151 changes: 0 additions & 151 deletions src/api/config.py

This file was deleted.

5 changes: 2 additions & 3 deletions src/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import requests

from src.api import Base
from src.api.base import Base
from src.config import GLOBAL_CONFIG
from src.utils import UA

from .config import GLOBAL_CONFIG


class UserAPI(Base):

Expand Down
43 changes: 43 additions & 0 deletions src/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
import configparser

from src.utils import HOST

from .auth import AuthConfig
from .bolo import BoloConfig
from .chat import ChatConfig
from .redpacket import RedPacketConfig


class Config(object):
def __init__(self, auth: AuthConfig = None, redpacket: RedPacketConfig = None, chat: ChatConfig = None, bolo: BoloConfig = None, cfg_path: str = None, host: str = 'https://fishpi.cn'):
self.auth_config = auth
self.redpacket_config = redpacket
self.chat_config = chat
self.bolo_config = bolo
self.cfg_path = cfg_path
self.host = host

def to_ini_template(self) -> configparser.ConfigParser:
config = configparser.ConfigParser()
config['auth'] = self.auth_config.to_config()
config['redPacket'] = self.redpacket_config.to_config()
config['chat'] = self.chat_config.to_config()
config['bolo'] = self.bolo_config.to_config()
return config


class CliOptions(object):
def __init__(self, username: str = '', password: str = '', code: str = '', file_path: str = None, host: str = None):
self.username = username
self.password = password
self.code = code
self.file_path = file_path
self.host = host


def init_defualt_config() -> Config:
return Config(AuthConfig(), RedPacketConfig(), ChatConfig(), BoloConfig('', '', ''), None, HOST)


GLOBAL_CONFIG = Config()
Loading

0 comments on commit 815b1d3

Please sign in to comment.