mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 03:15:05 +08:00
add colorful logs, bump go.mod
This commit is contained in:
@@ -19,3 +19,4 @@ git+https://github.com/tgbot-collection/python-akismet
|
||||
openpyxl==3.1.1
|
||||
zhconv==1.4.3
|
||||
jinja2==3.1.2
|
||||
coloredlogs==15.0.1
|
||||
|
||||
@@ -38,7 +38,9 @@ from database import (AnnouncementResource, BlacklistResource, CaptchaResource,
|
||||
NameResource, NotificationResource, OtherResource, Redis,
|
||||
ResourceLatestResource, ResourceResource, TopResource,
|
||||
UserEmailResource, UserResource)
|
||||
from utils import Cloudflare, check_spam, send_mail, ts_date
|
||||
from utils import Cloudflare, check_spam, send_mail, setup_logger, ts_date
|
||||
|
||||
setup_logger()
|
||||
|
||||
lib_path = pathlib.Path(__file__).parent.parent.joinpath("yyetsbot").resolve().as_posix()
|
||||
sys.path.append(lib_path)
|
||||
|
||||
@@ -43,4 +43,4 @@ def sync_douban():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sync_douban()
|
||||
sync_douban()
|
||||
|
||||
@@ -19,6 +19,9 @@ import fakeredis
|
||||
import redis
|
||||
from captcha.image import ImageCaptcha
|
||||
|
||||
from utils import setup_logger
|
||||
|
||||
setup_logger()
|
||||
captcha_ex = 60 * 10
|
||||
predefined_str = re.sub(r"[1l0oOI]", "", string.ascii_letters + string.digits)
|
||||
|
||||
|
||||
@@ -22,8 +22,9 @@ import pymysql
|
||||
import pymysql.cursors
|
||||
from tqdm import tqdm
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
from utils import setup_logger
|
||||
|
||||
setup_logger()
|
||||
data_path = pathlib.Path(__file__).parent.joinpath("templates", "dump")
|
||||
data_path.mkdir(exist_ok=True)
|
||||
sqlite_file = data_path.joinpath("yyets.db")
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
module yyetsweb
|
||||
|
||||
go 1.20
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/glebarez/go-sqlite v1.19.1
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
)
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/glebarez/go-sqlite v1.19.1
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.10.0 // indirect
|
||||
github.com/goccy/go-json v0.9.7 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
golang.org/x/crypto v0.1.0 // indirect
|
||||
golang.org/x/net v0.1.0 // indirect
|
||||
golang.org/x/sys v0.1.0 // indirect
|
||||
golang.org/x/text v0.4.0 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
modernc.org/libc v1.19.0 // indirect
|
||||
modernc.org/mathutil v1.5.0 // indirect
|
||||
modernc.org/memory v1.4.0 // indirect
|
||||
modernc.org/sqlite v1.19.1 // indirect
|
||||
)
|
||||
require (
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.10.0 // indirect
|
||||
github.com/goccy/go-json v0.9.7 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
golang.org/x/crypto v0.1.0 // indirect
|
||||
golang.org/x/net v0.7.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
modernc.org/libc v1.19.0 // indirect
|
||||
modernc.org/mathutil v1.5.0 // indirect
|
||||
modernc.org/memory v1.4.0 // indirect
|
||||
modernc.org/sqlite v1.19.1 // indirect
|
||||
)
|
||||
|
||||
@@ -80,8 +80,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
|
||||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -94,14 +94,14 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
|
||||
@@ -31,10 +31,10 @@ from tornado.auth import GoogleOAuth2Mixin, OAuth2Mixin, TwitterMixin
|
||||
from tornado.concurrent import run_on_executor
|
||||
|
||||
from database import CaptchaResource, Redis
|
||||
from utils import Cloudflare
|
||||
from utils import Cloudflare, setup_logger
|
||||
|
||||
escape.json_encode = lambda value: json.dumps(value, ensure_ascii=False)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
setup_logger()
|
||||
cf = Cloudflare()
|
||||
if getattr(sys, '_MEIPASS', None):
|
||||
adapter = "SQLite"
|
||||
@@ -270,13 +270,13 @@ class UserAvatarHandler(BaseHandler):
|
||||
def get(self, username):
|
||||
resp = yield self.get_avatar(username)
|
||||
self.write(resp)
|
||||
|
||||
|
||||
@gen.coroutine
|
||||
def head(self, username):
|
||||
resp = yield self.get_avatar(username)
|
||||
self.write(resp)
|
||||
|
||||
|
||||
|
||||
class ResourceHandler(BaseHandler):
|
||||
class_name = f"Resource{adapter}Resource"
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ from apscheduler.triggers.cron import CronTrigger
|
||||
from tornado import httpserver, ioloop, options, web
|
||||
from tornado.log import enable_pretty_logging
|
||||
|
||||
import dump_db
|
||||
from Mongo import OtherMongoResource, ResourceLatestMongoResource
|
||||
from commands.douban_sync import sync_douban
|
||||
from dump_db import entry_dump
|
||||
from handler import (AnnouncementHandler, BlacklistHandler, CaptchaHandler,
|
||||
CategoryHandler, CommentChildHandler, CommentHandler,
|
||||
CommentNewestHandler, CommentReactionHandler,
|
||||
@@ -36,12 +36,13 @@ from handler import (AnnouncementHandler, BlacklistHandler, CaptchaHandler,
|
||||
SpamProcessHandler, TopHandler, TwitterOAuth2LoginHandler,
|
||||
UserAvatarHandler, UserEmailHandler, UserHandler)
|
||||
from sync import YYSub
|
||||
from utils import Cloudflare
|
||||
from utils import Cloudflare, setup_logger
|
||||
|
||||
enable_pretty_logging()
|
||||
setup_logger()
|
||||
cf = Cloudflare()
|
||||
if os.getenv("debug"):
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
class RunServer:
|
||||
@@ -120,7 +121,7 @@ if __name__ == "__main__":
|
||||
scheduler = BackgroundScheduler(timezone=timez)
|
||||
scheduler.add_job(OtherMongoResource().reset_top, trigger=CronTrigger.from_crontab("0 0 1 * *"))
|
||||
scheduler.add_job(sync_douban, trigger=CronTrigger.from_crontab("1 1 1 * *"))
|
||||
scheduler.add_job(dump_db.entry_dump, trigger=CronTrigger.from_crontab("2 2 1 * *"))
|
||||
scheduler.add_job(entry_dump, trigger=CronTrigger.from_crontab("2 2 1 * *"))
|
||||
scheduler.add_job(ResourceLatestMongoResource().refresh_latest_resource, 'interval', hours=1)
|
||||
scheduler.add_job(OtherMongoResource().import_ban_user, 'interval', seconds=300)
|
||||
scheduler.add_job(cf.clear_fw, trigger=CronTrigger.from_crontab("0 0 */5 * *"))
|
||||
@@ -129,7 +130,7 @@ if __name__ == "__main__":
|
||||
scheduler.start()
|
||||
logging.info("Triggering dump database now...")
|
||||
if not os.getenv("PYTHON_DEV"):
|
||||
threading.Thread(target=dump_db.entry_dump).start()
|
||||
threading.Thread(target=entry_dump).start()
|
||||
|
||||
options.define("p", default=8888, help="running port", type=int)
|
||||
options.define("h", default='127.0.0.1', help="listen address", type=str)
|
||||
|
||||
@@ -10,9 +10,10 @@ from copy import deepcopy
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
from Mongo import Mongo
|
||||
from utils import setup_logger
|
||||
|
||||
setup_logger()
|
||||
|
||||
|
||||
class BaseSync:
|
||||
|
||||
@@ -18,12 +18,17 @@ from email.header import Header
|
||||
from email.mime.text import MIMEText
|
||||
from email.utils import formataddr, parseaddr
|
||||
|
||||
import coloredlogs
|
||||
import pytz
|
||||
import requests
|
||||
from akismet import Akismet
|
||||
from jinja2 import Template
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
def setup_logger():
|
||||
coloredlogs.install(level=logging.INFO,
|
||||
fmt='%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] - %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
def ts_date(ts=None):
|
||||
|
||||
Reference in New Issue
Block a user