From db613ad7b9ce1c20dc06d925153a944b6cfe9387 Mon Sep 17 00:00:00 2001 From: samedamci Date: Mon, 14 Nov 2022 21:28:39 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ README.md | 19 +++++++++++++++++++ db.json | 1 + main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 5 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 db.json create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..17a28c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +.venv/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..00d0932 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Telegramero Bot + +Join to `@wowneromemes` Telegram channel and view bot in action. + +## How to use? + +Install requirements and run with bot token. You can also specify different channel ID directly in `main.py`. + +### Windows +```ps1 +$Env:TOKEN = "TOKEN_HERE"; python.exe .\main.py +``` + +### Linux +```bash +TOKEN = "TOKEN_HERE" python ./main.py +``` + +You need `db.json` file to run this bot and by default it should have only empty array (`[]`) inside. \ No newline at end of file diff --git a/db.json b/db.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/db.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..dc71d8c --- /dev/null +++ b/main.py @@ -0,0 +1,48 @@ +import requests +from os import environ +import json +from datetime import datetime +from time import sleep + +TOKEN = environ.get("TOKEN") +CHANNEL_ID = "@wowneromemes" + +while True: + memes = json.loads(requests.get("https://suchwow.xyz/api/list").text) + + for meme in memes[::-1]: + with open("db.json", "r") as f: + db = json.loads(f.read()) + + if meme["id"] in db: + print("skip") + continue + else: + date = datetime.strptime(meme["timestamp"], "%a, %d %b %Y %H:%M:%S %Z").strftime("%Y-%m-%d, %H:%M:%S GMT") + title = meme["title"] + media = meme["image"] + submitter = meme["submitter"] + address = meme["address"] + meme_url = meme["href"] + + params = { + "chat_id": CHANNEL_ID, + "photo": media, + "parse_mode": "HTML", + "caption": f'{title}\n\nSubmitted by {submitter} at {date}.\n\nDonate author:\n{address}', + "reply_markup": { + "inline_keyboard": [[{"text": "Original post", "url": meme_url}]] + } + } + + url = f"https://api.telegram.org/bot{TOKEN}/sendPhoto" + r = requests.post(url, json=params) + + print(r.text) + + db.append(meme["id"]) + with open("db.json", "w") as f: + f.write(json.dumps(db)) + + sleep(3) + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file