-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release v2.0.0 * refacotr: rename cli_config => options * feat: 撤回上条消息 #67 * chore: ws支持多个 * 项目名变更 * optimze: 优雅退出 * 账号多开 * doc: 文档添加
- Loading branch information
Showing
22 changed files
with
511 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
requests==2.22.0 | ||
websocket_client==1.2.3 | ||
schedule==1.1.0 | ||
click==8.1.3 | ||
click==8.1.3 | ||
objprint==0.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
from setuptools import setup | ||
import io | ||
import os | ||
import sys | ||
from shutil import rmtree | ||
|
||
from setuptools import Command, setup | ||
|
||
from src.utils.version import __version__ | ||
|
||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Note: To use the 'upload' functionality of this file, you must: | ||
# $ pipenv install twine --dev | ||
|
||
import io | ||
import os | ||
import sys | ||
from shutil import rmtree | ||
from src.utils.version import __version__ | ||
|
||
from setuptools import setup, Command | ||
|
||
# Package meta-data. | ||
NAME = 'pwl-chat-python' | ||
NAME = 'fishpi-pyclient' | ||
DESCRIPTION = '摸鱼派聊天室python客户端' | ||
URL = 'https://github.com/gakkiyomi/pwl-chat-python' | ||
URL = 'https://github.com/gakkiyomi/fishpi-pyclient' | ||
EMAIL = '[email protected]' | ||
AUTHOR = 'gakkiyomi' | ||
REQUIRES_PYTHON = '>=3.9' | ||
VERSION = __version__ | ||
|
||
# What packages are required for this module to be executed? | ||
REQUIRED = [ | ||
'requests', 'websocket-client', 'click', 'schedule' | ||
'requests', 'websocket-client', 'click', 'schedule', 'objprint' | ||
] | ||
|
||
# What packages are optional? | ||
|
@@ -122,7 +122,7 @@ def run(self): | |
}, | ||
entry_points={ | ||
'console_scripts': [ | ||
'pwl-chat-python = src.main:cli', | ||
'fishpi-pyclient = src.main:cli', | ||
], | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
from enum import Enum | ||
from typing import Any | ||
|
||
import requests | ||
|
||
from src.api import Base | ||
from src.utils import HOST, UA | ||
|
||
|
||
class ArticleType(Enum): | ||
RECENT = 'recent' | ||
HOT = RECENT+'/hot' | ||
GOOD = RECENT+'/good' | ||
REPLY = RECENT+'/reply' | ||
|
||
|
||
class Article(object): | ||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
for dict in args: | ||
for key in dict: | ||
setattr(self, key, dict[key]) | ||
for key in kwargs: | ||
setattr(self, key, kwargs[key]) | ||
|
||
def vote(self, api) -> None: | ||
api.vote_for_article(self.oId) | ||
|
||
def thanks(self, api) -> None: | ||
api.thanks_for_article(self.oId) | ||
|
||
def comment(self, api, comment: str) -> None: | ||
api.comment_article(self.oId, comment) | ||
|
||
|
||
class ArticleAPI(Base): | ||
def vote_for_article(self, article_id: str) -> None: | ||
if self.api_key == '': | ||
return None | ||
resp = requests.post( | ||
f'{HOST}/vote/up/article', headers={'User-Agent': UA}, json={ | ||
'apiKey': self.api_key, | ||
'dataId': article_id | ||
}) | ||
if resp.status_code == 200: | ||
data = json.loads(resp.text) | ||
if 'code' in data and data['code'] == 0: | ||
if data['type'] == -1: | ||
print('点赞成功') | ||
else: | ||
print('取消点赞') | ||
else: | ||
print('点赞失败: ' + data['msg']) | ||
else: | ||
print('点赞失败') | ||
|
||
def thanks_for_article(self, article_id: str) -> None: | ||
res = requests.post(f'{HOST}/article/thank?articleId={article_id}', headers={'User-Agent': UA}, json={ | ||
'apiKey': self.api_key | ||
}) | ||
response = json.loads(res.text) | ||
if 'code' in response and response['code'] == 0: | ||
print('感谢文章成功') | ||
else: | ||
print('感谢文章失败: ' + response['msg']) | ||
|
||
def list_articles(self, type: ArticleType = ArticleType.RECENT, page: int = 1, size: int = 20) -> dict: | ||
res = requests.get( | ||
f'{HOST}/api/articles/{type}?p={page}&size={size}', headers={'User-Agent': UA}, json={ | ||
'apiKey': self.api_key | ||
}) | ||
response = json.loads(res.text) | ||
if 'code' in response and response['code'] == 0: | ||
return response | ||
else: | ||
print('获取帖子列表失败: ' + response['msg']) | ||
|
||
def get_article(self, article_id: str) -> Article: | ||
res = requests.get( | ||
f'{HOST}/api/article/{article_id}', headers={'User-Agent': UA}, json={ | ||
'apiKey': self.api_key | ||
}) | ||
response = json.loads(res.text) | ||
if 'code' in response and response['code'] == 0: | ||
return Article(response['data']) | ||
else: | ||
print('获取帖子详情失败: ' + response['msg']) | ||
|
||
def comment_article(self, article_id: str, comment: str) -> Article: | ||
res = requests.post(f'{HOST}/comment/{article_id}', headers={'User-Agent': UA}, json={ | ||
'apiKey': self.api_key, | ||
'articleId': article_id, | ||
'commentAnonymous': False, | ||
'commentVisible': False, | ||
'commentContent': comment | ||
}) | ||
response = json.loads(res.text) | ||
if 'code' in response and response['code'] == 0: | ||
print('评论成功') | ||
else: | ||
print('评论失败: ' + response['msg']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import hashlib | ||
import json | ||
import sys | ||
|
||
import requests | ||
|
||
from src.utils import HELP, HOST, UA | ||
|
||
|
||
class Base(object): | ||
def __init__(self, key=''): | ||
self.current_user = '' | ||
self.set_token(key) | ||
|
||
def set_token(self, api_key=''): | ||
self.api_key = api_key | ||
|
||
def set_current_user(self, username): | ||
self.current_user = username | ||
|
||
def login(self, username: str, password: str, mfa_code=''): | ||
params = { | ||
'nameOrEmail': username, | ||
'userPassword': hashlib.md5(str(password).encode('utf-8')).hexdigest(), | ||
'mfaCode': mfa_code | ||
} | ||
res = requests.post(f"{HOST}/api/getKey", | ||
json=params, headers={'User-Agent': UA}) | ||
rsp = json.loads(res.text) | ||
if rsp['code'] == 0: | ||
self.set_token(rsp['Key']) | ||
self.set_current_user(username) | ||
print(f'登陆成功! 更多功能与趣味游戏请访问网页端: {HOST}') | ||
print(HELP) | ||
elif rsp['code'] == -1 and rsp['msg'] == '两步验证失败,请填写正确的一次性密码': | ||
self.set_token('') | ||
print("请输入两步验证码:") | ||
while len(self.api_key) == 0: | ||
code = input("") | ||
self.login(username, password, code) | ||
else: | ||
print(f"登陆失败: {rsp['msg']}") | ||
sys.exit(0) |
Oops, something went wrong.