Skip to content

Commit 0cf0151

Browse files
committed
Initial Commit.
0 parents  commit 0cf0151

28 files changed

+3554
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.archive
2+
.env
3+
.venv/*
4+
.venv
5+
.vscode
6+
.vscode/*
7+
__pycache__
8+
*.egg-info/
9+
manual_tester.py
10+
_build
11+
build
12+
dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-Present Anson Quek
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Weverse.py
2+
3+
Weverse.py is a Python API Wrapper that interacts with Weverse's private API.
4+
5+
## Intended Use
6+
7+
Weverse.py seeks to provide developers with a tool that allows them to make a bot that is able to retrieve Weverse Posts in semi real-time with relative ease.
8+
9+
## Installation
10+
11+
You can install Weverse.py by using a terminal of your choice, and typing `pip install weverse-py`.\
12+
Alternatively, you can install from source by typing `pip install git+https://github.com/Anson-Quek/weverse-py.git`.
13+
14+
## Disclaimer
15+
16+
As this is my first ever serious project, coupled with my lack of necessary coding experience, I seek your understanding that there could be many aspects that are lacking.\
17+
Any tips, advices and constructive criticisms that seeks to make this project a better project, and me a better coder will be greatly appreciated.
18+
19+
## Example Usage
20+
21+
```python
22+
from weverse import WeverseClient
23+
24+
25+
# Create your own class that subclasses from WeverseClient
26+
class WeverseBot(WeverseClient):
27+
def __init__(self, email: str, password: str):
28+
super().__init__(email, password)
29+
30+
# This method is called every time there is a new
31+
# notification detected. The likelihood of you actually
32+
# using this method is highly unlikely as there are more
33+
# specialised methods that are called that should achieve
34+
# what you want.
35+
async def on_new_notification(self, notification: Notification) -> None:
36+
# Do what you want with the notification.
37+
print(notification.title)
38+
39+
# This method is called every time there is a new
40+
# comment detected.
41+
async def on_new_comment(self, comment: Comment) -> None:
42+
# Do what you want with the comment.
43+
print(comment.body)
44+
45+
# This method is called every time there is a new
46+
# post detected.
47+
async def on_new_post(self, post: Post) -> None:
48+
# Do what you want with the post.
49+
print(post.plain_body)
50+
51+
# This method is called every time there is a new
52+
# media detected.
53+
async def on_new_media(self, media: ImageMedia | WeverseMedia | YoutubeMedia) -> None:
54+
# Since the media parameter will return either ImageMedia,
55+
# WeverseMedia or YoutubeMedia, isinstance should be used to
56+
# determine the type of object the media is.
57+
if isinstance(media, ImageMedia):
58+
# Do what you want with the Image Media.
59+
print(media.photos)
60+
61+
elif isinstance(media, WeverseMedia):
62+
# Do what you want with the Weverse Media.
63+
print(media.internal_video_id)
64+
65+
else:
66+
# Do what you want with the Youtube Media.
67+
print(media.youtube_url)
68+
69+
# This method is called every time there is a new live
70+
# broadcast detected.
71+
async def on_new_live(self, live: Live) -> None:
72+
# Do what you want with the Weverse Live Broadcast.
73+
print(live.message_count)
74+
75+
# This method is called every time there is a new notice
76+
# detected
77+
async def on_new_notice(self, notice: Notice) -> None:
78+
# Do what you want with the Weverse Notice.
79+
print(notice.photos)
80+
81+
# This method is called every time there is a new moment
82+
# detected.
83+
async def on_new_moment(self, moment: Moment | OldMoment) -> None:
84+
# Since the moment parameter will return either Moment
85+
# or OldMoment, isinstance should be used to determine
86+
# the type of object the moment is.
87+
if isinstance(moment, Moment):
88+
# Do what you want with the Moment.
89+
print(moment.video)
90+
91+
else:
92+
# Do what you want with the OldMoment. (Old Moment
93+
# refers to moments that were created before the Weverse
94+
# remake which happened somewhere in July or August)
95+
print(moment.photo)
96+
97+
if __name__ == "__main__":
98+
client = WeverseBot(
99+
email="the email of the account you want to sign in with",
100+
password="the password of the account you want to sign in with"
101+
)
102+
loop = asyncio.new_event_loop()
103+
asyncio.set_event_loop(loop)
104+
loop.run_until_complete(client.start())
105+
loop.run_forever()
106+
107+
```

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/api.rst

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
.. py:currentmodule:: weverse
2+
3+
WeverseClient
4+
=============
5+
.. autoclass:: WeverseClient
6+
:members:
7+
8+
.. _obj_types:
9+
10+
Objects
11+
=======
12+
Attachment
13+
----------
14+
.. autoclass:: weverse.objects.attachment.Photo
15+
:members:
16+
17+
.. autoclass:: weverse.objects.attachment.Video
18+
:members:
19+
20+
.. autoclass:: weverse.objects.attachment.Snippet
21+
:members:
22+
23+
Comment
24+
-------
25+
.. autoclass:: weverse.objects.comment.BaseParent
26+
:members:
27+
28+
.. autoclass:: weverse.objects.comment.ParentComment
29+
:members:
30+
31+
.. autoclass:: weverse.objects.comment.ParentPost
32+
:members:
33+
34+
.. autoclass:: weverse.objects.comment.ParentMediaPost
35+
:members:
36+
37+
.. autoclass:: weverse.objects.comment.RootPost
38+
:members:
39+
40+
.. autoclass:: weverse.objects.comment.RootMediaPost
41+
:members:
42+
43+
.. autoclass:: weverse.objects.comment.Comment
44+
:members:
45+
46+
Community
47+
---------
48+
.. autoclass:: weverse.objects.community.PartialCommunity
49+
:members:
50+
51+
.. autoclass:: weverse.objects.community.Community
52+
:members:
53+
54+
Live
55+
----
56+
.. autoclass:: weverse.objects.live.Live
57+
:members:
58+
59+
Media
60+
-----
61+
.. autoclass:: weverse.objects.media.MediaLike
62+
:members:
63+
64+
.. autoclass:: weverse.objects.media.ImageMedia
65+
:members:
66+
67+
.. autoclass:: weverse.objects.media.YoutubeMedia
68+
:members:
69+
70+
.. autoclass:: weverse.objects.media.WeverseMedia
71+
:members:
72+
73+
Member
74+
------
75+
.. autoclass:: weverse.objects.member.PartialMember
76+
:members:
77+
78+
.. autoclass:: weverse.objects.member.Artist
79+
:members:
80+
81+
.. autoclass:: weverse.objects.member.ArtistProfile
82+
:members:
83+
84+
.. autoclass:: weverse.objects.member.PostAuthor
85+
:members:
86+
87+
.. autoclass:: weverse.objects.member.Member
88+
:members:
89+
90+
Moment
91+
------
92+
.. autoclass:: weverse.objects.moment.MomentLike
93+
:members:
94+
95+
.. autoclass:: weverse.objects.moment.Moment
96+
:members:
97+
98+
.. autoclass:: weverse.objects.moment.OldMoment
99+
:members:
100+
101+
Notice
102+
------
103+
.. autoclass:: weverse.objects.notice.Notice
104+
:members:
105+
106+
Notification
107+
------------
108+
.. autoclass:: weverse.objects.notification.Notification
109+
:members:
110+
111+
Post
112+
----
113+
.. autoclass:: weverse.objects.post.PostLike
114+
:members:
115+
116+
.. autoclass:: weverse.objects.post.Post
117+
:members:
118+
119+
Exceptions
120+
==========
121+
.. autoexception:: WeverseException
122+
:members:
123+
124+
.. autoexception:: LoginError
125+
:members:
126+
127+
.. autoexception:: RequestFailed
128+
:members:
129+
130+
.. autoexception:: TokenExpired
131+
:members:
132+
133+
.. autoexception:: Forbidden
134+
:members:
135+
136+
.. autoexception:: NotFound
137+
:members:
138+
139+
.. autoexception:: InternalServerError
140+
:members:

docs/conf.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
# -- Project information -----------------------------------------------------
7+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
9+
import os
10+
import sys
11+
12+
sys.path.insert(0, os.path.abspath(".."))
13+
14+
15+
project = 'Weverse.py'
16+
copyright = '2023-Present, Anson Quek'
17+
author = 'Anson Quek'
18+
release = '1.0.0'
19+
20+
# -- General configuration ---------------------------------------------------
21+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
22+
23+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"]
24+
autodoc_member_order = "bysource"
25+
26+
templates_path = ['_templates']
27+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
28+
29+
30+
31+
# -- Options for HTML output -------------------------------------------------
32+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
33+
34+
html_theme = 'sphinx_rtd_theme'
35+
html_static_path = ['_static']

docs/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. Weverse.py documentation master file, created by
2+
sphinx-quickstart on Wed Jan 11 15:07:09 2023.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to Weverse.py's documentation!
7+
======================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
api.rst
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

0 commit comments

Comments
 (0)