Browse Source

Add logging

main
fluffy 6 months ago
parent
commit
bbe0b08524
4 changed files with 93 additions and 6 deletions
  1. +10
    -0
      beatbot.log
  2. +23
    -5
      beatbot.py
  3. +58
    -1
      poetry.lock
  4. +2
    -0
      pyproject.toml

+ 10
- 0
beatbot.log View File

@@ -0,0 +1,10 @@
INFO:__main__:genre=acid verb1=slate verb2=zonda search=https://www.youtube.com/results?search_query=+lofi%20acid%20+beats%20slate%20zonda result=200 count=30 ytid=NAYZEkRle1U
[2021-04-29T09:56:42] DEBUG [urllib3.connectionpool._new_conn:971] Starting new HTTPS connection (1): www.youtube.com:443
[2021-04-29T09:56:42] DEBUG [urllib3.connectionpool._make_request:452] https://www.youtube.com:443 "GET /results?search_query=+lofi%20electropop%20+beats%20leach%20encamp HTTP/1.1" 200 None
[2021-04-29T09:56:52] DEBUG [urllib3.connectionpool._new_conn:971] Starting new HTTPS connection (1): www.youtube.com:443
[2021-04-29T09:56:52] DEBUG [urllib3.connectionpool._make_request:452] https://www.youtube.com:443 "GET /results?search_query=+lofi%20jazz%20+beats%20cleat%20uprose HTTP/1.1" 200 None
[2021-04-29T09:56:52] INFO [__main__.bot:65] lo-fi jazz beats to cleat and uprose to

https://youtube.com/watch?v=tBDVLey1DIE
[2021-04-29T09:56:52] DEBUG [urllib3.connectionpool._new_conn:971] Starting new HTTPS connection (1): botsin.space:443
[2021-04-29T09:56:52] DEBUG [urllib3.connectionpool._make_request:452] https://botsin.space:443 "GET /api/v1/instance/ HTTP/1.1" 200 None

+ 23
- 5
beatbot.py View File

@@ -1,8 +1,20 @@
import mastodon
import logging
import logging.handlers
import pickle
import random
import requests
import re
import pickle

import mastodon
import requests

logging.basicConfig(
handlers=[logging.handlers.RotatingFileHandler('beatbot.log', maxBytes=100000, backupCount=10),
logging.handlers.StreamHandler()],
level=logging.INFO,
format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
datefmt='%Y-%m-%dT%H:%M:%S')
LOGGER = logging.getLogger(__name__)


def randline(fname):
with open(fname) as afile:
@@ -12,6 +24,7 @@ def randline(fname):
line = aline
return line.strip()


def bot():
genre = randline('genres.txt')
verb1 = randline('1syllableverbs.txt')
@@ -26,9 +39,14 @@ def bot():
except Exception:
seen_vids = set()

query = requests.get(f'https://www.youtube.com/results?search_query={search_term}')
query = requests.get(
f'https://www.youtube.com/results?search_query={search_term}')
video_ids = re.findall(r'watch\?v=([^"]{11})"', query.text)

if query.status_code != 200 or not video_ids:
LOGGER.warning("YouTube search %s returned %d",
query.url, query.status_code)

yt_id = None

random.shuffle(video_ids)
@@ -51,7 +69,7 @@ def bot():
with open('seen-vids.dat', 'wb') as seen:
pickle.dump(seen_vids, seen)

print(text)
LOGGER.info(text)

mdon = mastodon.Mastodon(
access_token='token.secret',


+ 58
- 1
poetry.lock View File

@@ -1,3 +1,15 @@
[[package]]
name = "autopep8"
version = "1.5.6"
description = "A tool that automatically formats Python code to conform to the PEP 8 style guide"
category = "dev"
optional = false
python-versions = "*"

[package.dependencies]
pycodestyle = ">=2.7.0"
toml = "*"

[[package]]
name = "blurhash"
version = "1.1.4"
@@ -41,6 +53,19 @@ category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"

[[package]]
name = "isort"
version = "5.8.0"
description = "A Python utility / library to sort Python imports."
category = "dev"
optional = false
python-versions = ">=3.6,<4.0"

[package.extras]
pipfile_deprecated_finder = ["pipreqs", "requirementslib"]
requirements_deprecated_finder = ["pipreqs", "pip-api"]
colors = ["colorama (>=0.4.3,<0.5.0)"]

[[package]]
name = "mastodon.py"
version = "1.5.1"
@@ -63,6 +88,14 @@ blurhash = ["blurhash (>=1.1.4)"]
test = ["blurhash (>=1.1.4)", "cryptography (>=1.6.0)", "http-ece (>=1.0.5)", "pytest", "pytest-cov", "pytest-mock", "pytest-runner", "pytest-vcr", "requests-mock", "vcrpy"]
webpush = ["cryptography (>=1.6.0)", "http-ece (>=1.0.5)"]

[[package]]
name = "pycodestyle"
version = "2.7.0"
description = "Python style guide checker"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"

[[package]]
name = "python-dateutil"
version = "2.8.1"
@@ -116,6 +149,14 @@ category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"

[[package]]
name = "toml"
version = "0.10.2"
description = "Python Library for Tom's Obvious, Minimal Language"
category = "dev"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"

[[package]]
name = "urllib3"
version = "1.26.2"
@@ -140,9 +181,13 @@ python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "^3.8"
content-hash = "8ee8ca988e50681b2b43c03d064ff31812170d326f87a71b23e13d6ed0bb86e4"
content-hash = "d8ab5494b0e12ecc66da1564ec45cf8f478abb9d5a08f26d9bdff276ad7e2f9a"

[metadata.files]
autopep8 = [
{file = "autopep8-1.5.6-py2.py3-none-any.whl", hash = "sha256:f01b06a6808bc31698db907761e5890eb2295e287af53f6693b39ce55454034a"},
{file = "autopep8-1.5.6.tar.gz", hash = "sha256:5454e6e9a3d02aae38f866eec0d9a7de4ab9f93c10a273fb0340f3d6d09f7514"},
]
blurhash = [
{file = "blurhash-1.1.4-py2.py3-none-any.whl", hash = "sha256:7611c1bc41383d2349b6129208587b5d61e8792ce953893cb49c38beeb400d1d"},
{file = "blurhash-1.1.4.tar.gz", hash = "sha256:da56b163e5a816e4ad07172f5639287698e09d7f3dc38d18d9726d9c1dbc4cee"},
@@ -163,10 +208,18 @@ idna = [
{file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"},
{file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"},
]
isort = [
{file = "isort-5.8.0-py3-none-any.whl", hash = "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d"},
{file = "isort-5.8.0.tar.gz", hash = "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6"},
]
"mastodon.py" = [
{file = "Mastodon.py-1.5.1-py2.py3-none-any.whl", hash = "sha256:cc454cac0ed1ae4f105f7399ea53f5b31a1be5075d1882f47162d2e78a9e4064"},
{file = "Mastodon.py-1.5.1.tar.gz", hash = "sha256:2afddbad8b5d7326fcc8a8f8c62bfe956e34627f516b06c6694fc8c8fedc33ee"},
]
pycodestyle = [
{file = "pycodestyle-2.7.0-py2.py3-none-any.whl", hash = "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068"},
{file = "pycodestyle-2.7.0.tar.gz", hash = "sha256:c389c1d06bf7904078ca03399a4816f974a1d590090fecea0c63ec26ebaf1cef"},
]
python-dateutil = [
{file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"},
{file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"},
@@ -187,6 +240,10 @@ six = [
{file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"},
{file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"},
]
toml = [
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
]
urllib3 = [
{file = "urllib3-1.26.2-py2.py3-none-any.whl", hash = "sha256:d8ff90d979214d7b4f8ce956e80f4028fc6860e4431f731ea4a8c08f23f99473"},
{file = "urllib3-1.26.2.tar.gz", hash = "sha256:19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08"},


+ 2
- 0
pyproject.toml View File

@@ -11,6 +11,8 @@ wordfilter = "^0.2.6"
requests = "^2.25.1"

[tool.poetry.dev-dependencies]
autopep8 = "^1.5.6"
isort = "^5.8.0"

[build-system]
requires = ["poetry-core>=1.0.0"]


Loading…
Cancel
Save