mirror of
https://git.wownero.com/houndvoyager/suchbot.git
synced 2024-08-15 01:03:17 +00:00
resetting master branch
This commit is contained in:
commit
f03cc75f2b
5 changed files with 152 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
__pycache__/
|
||||||
|
test.py
|
||||||
|
.env
|
||||||
|
venv/
|
28
README.md
Normal file
28
README.md
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# Suchbot, a bot for suchmemes ._.
|
||||||
|
|
||||||
|
# Supported platforms:
|
||||||
|
- [x] Mastodon (Come check it out at [@wownero](https://mastodon.social/@wownero))
|
||||||
|
- [x] Tumblr (only posts image due to the package limitations. Check out the feed here: [wownero](https://wownero.tumblr.com/)
|
||||||
|
- [ ] XMPP
|
||||||
|
- [ ] IRC
|
||||||
|
|
||||||
|
## It uses a [Supabase](https://supabase.com/) database to store the json from https://suchwow.xyz/api/list.
|
||||||
|
|
||||||
|
> Posts image data directly to services without storing it.
|
||||||
|
|
||||||
|
# Reproducing:
|
||||||
|
To reproduce, set up a .env with the following and install the necessary modules found in `requirements.txt`:
|
||||||
|
|
||||||
|
```
|
||||||
|
SUPABASE_URL=
|
||||||
|
SUPABASE_KEY=
|
||||||
|
|
||||||
|
Mastodon:
|
||||||
|
MAST_TOKEN=
|
||||||
|
|
||||||
|
Tumblr:
|
||||||
|
consumer_key=
|
||||||
|
consumer_secret=
|
||||||
|
oauth_token=
|
||||||
|
oauth_secret=
|
||||||
|
```
|
45
main.py
Normal file
45
main.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import httpx
|
||||||
|
import time
|
||||||
|
import modules
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from supabase import create_client, Client
|
||||||
|
load_dotenv()
|
||||||
|
url: str = os.environ.get("SUPABASE_URL")
|
||||||
|
key: str = os.environ.get("SUPABASE_KEY")
|
||||||
|
supabase: Client = create_client(url, key)
|
||||||
|
|
||||||
|
|
||||||
|
def scraper():
|
||||||
|
transport = httpx.HTTPTransport(retries=5)
|
||||||
|
client = httpx.Client(transport=transport)
|
||||||
|
|
||||||
|
api_list = client.get("https://suchwow.xyz/api/list", timeout=100).json()
|
||||||
|
api_list.reverse()
|
||||||
|
|
||||||
|
for item in api_list:
|
||||||
|
try:
|
||||||
|
supabase.table("suchmeme").insert(item).execute()
|
||||||
|
print(f'Inserted meme {item["id"]} to Supabase DB')
|
||||||
|
post(item)
|
||||||
|
except Exception as e:
|
||||||
|
if 'duplicate key value violates unique constraint' in str(e):
|
||||||
|
print("Meme already exists")
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
print(f'Error upon inserting data in DB with meme {item["id"]} due to {e}')
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
def post(item):
|
||||||
|
modules.masto(item)
|
||||||
|
modules.tumblr(item)
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
scraper()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print("Database updated")
|
||||||
|
time.sleep(120)
|
38
modules.py
Normal file
38
modules.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
from mastodon import Mastodon
|
||||||
|
import pytumblr2
|
||||||
|
import mimetypes
|
||||||
|
import httpx
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
|
def masto(post):
|
||||||
|
mastodon = Mastodon(
|
||||||
|
access_token=os.environ.get("MAST_TOKEN"),
|
||||||
|
api_base_url='https://mastodon.social'
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
i = httpx.get(post["image"]).content
|
||||||
|
mime = mimetypes.guess_type(post["image"], strict=True)[0]
|
||||||
|
media_ids = mastodon.media_post(i, mime, description=f'{post["title"]}')["id"]
|
||||||
|
media_ids = [media_ids]
|
||||||
|
content = f'New meme by {post["submitter"]}!\n{post["title"]} - {post["text"]}\n{post["href"]}'
|
||||||
|
mastodon.status_post(content, media_ids=media_ids)
|
||||||
|
print(f'Posted {post["id"]} to Mastodon @wownero')
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def tumblr(post):
|
||||||
|
client = pytumblr2.TumblrRestClient(
|
||||||
|
os.environ.get("consumer_key"),
|
||||||
|
os.environ.get("consumer_secret"),
|
||||||
|
os.environ.get("oauth_token"),
|
||||||
|
os.environ.get("oauth_secret"),
|
||||||
|
)
|
||||||
|
|
||||||
|
client.legacy_create_photo("wownero", state="published", tags=["wownero", "such", "meme", "wow", "memes"], caption=f'New meme by {post["submitter"]}!\n{post["title"]} - {post["text"]}', link=f'{post["href"]}',
|
||||||
|
source=post["image"])
|
37
requirements.txt
Normal file
37
requirements.txt
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
anyio==3.5.0
|
||||||
|
blurhash==1.1.4
|
||||||
|
certifi==2021.10.8
|
||||||
|
charset-normalizer==2.0.12
|
||||||
|
decorator==5.1.1
|
||||||
|
deprecation==2.1.0
|
||||||
|
dnspython==2.2.1
|
||||||
|
future==0.18.2
|
||||||
|
gotrue==0.5.0
|
||||||
|
h11==0.12.0
|
||||||
|
httpcore==0.14.7
|
||||||
|
httpx==0.21.3
|
||||||
|
idna==3.3
|
||||||
|
Mastodon.py==1.5.1
|
||||||
|
oauthlib==3.2.0
|
||||||
|
packaging==21.3
|
||||||
|
Pillow==9.0.1
|
||||||
|
postgrest-py==0.9.2
|
||||||
|
psycopg2==2.9.3
|
||||||
|
pydantic==1.9.0
|
||||||
|
pymongo==4.0.2
|
||||||
|
pyparsing==3.0.7
|
||||||
|
python-dateutil==2.8.2
|
||||||
|
python-dotenv==0.19.2
|
||||||
|
python-magic==0.4.25
|
||||||
|
PyTumblr2==0.2.2
|
||||||
|
pytz==2022.1
|
||||||
|
realtime==0.0.4
|
||||||
|
requests==2.27.1
|
||||||
|
requests-oauthlib==1.3.1
|
||||||
|
rfc3986==1.5.0
|
||||||
|
six==1.16.0
|
||||||
|
sniffio==1.2.0
|
||||||
|
supabase==0.5.3
|
||||||
|
typing-extensions==4.1.1
|
||||||
|
urllib3==1.26.9
|
||||||
|
websockets==9.1
|
Loading…
Reference in a new issue