# Path: apps/cryptonews/models/db.py
# class News(models.Model):
#     slug = fields.RandomCharField(
#         length=12,
#         unique=True,
#         include_alpha=False,
#         db_index=True,
#         editable=False,
#     )
#     title = models.CharField(max_length=1024)
#     content = models.TextField(blank=True, default="")
#     published_at = models.DateTimeField(default=timezone.now, db_index=True)
#     origin_link = models.URLField(
#         max_length=1024, null=True, blank=True, unique=True
#     )
# 
#     class Meta:
#         ordering = ["-published_at"]
# 
#     def __str__(self):
#         return f"{self.title} - {self.published_at} - {self.origin_link}"
# 
#     @cached_property
#     def domain(self):
#         o = parse.urlparse(self.origin_link)
#         return o.netloc
# 
# Path: apps/cryptonews/serializers.py
# class PushExchangeAnnSerializer(serializers.ModelSerializer):
#     channel = serializers.CharField(
#         default="ExchangeAnnChannel", read_only=True
#     )
# 
#     class Meta:
#         model = News
#         exclude = [
#             "id",
#             "content",
#             "slug",
#         ]
# 
# Path: apps/cryptonews/utils/translator.py
# def translate_text(text, source="ok", target="en") -> str:
#     _r = requests.post(
#         translate_url,
#         json={
#             "text": text,
#             "source": source,
#             "target": target,
#         },
#     )
#     _data = json.loads(_r.text)
#     return _data["TranslatedText"]


import re
import requests
import logging
import opencc
from datetime import datetime, timedelta
from django.conf import settings
from apps.cryptonews.models import News
from apps.cryptonews.serializers import PushExchangeAnnSerializer
from apps.cryptonews.utils.translator import translate_text

logger = logging.getLogger("django")

debug = getattr(settings, "DEBUG")

p = re.compile(r"^\[.*?\]", re.IGNORECASE)
gate_pattern = re.compile("^gate\\.io", re.IGNORECASE)

# Path: apps/cryptonews/models/db.py
# class News(models.Model):
#     slug = fields.RandomCharField(
#         length=12,
#         unique=True,
#         include_alpha=False,
#         db_index=True,
#         editable=False,
#     )
#     title = models.CharField(max_length=1024)
#     content = models.TextField(blank=True, default="")
#     published_at = models.DateTimeField(default=timezone.now, db_index=True)
#     origin_link = models.URLField(
#         max_length=1024, null=True, blank=True, unique=True
#     )
# 
#     class Meta:
#         ordering = ["-published_at"]
# 
#     def __str__(self):
#         return f"{self.title} - {self.published_at} - {self.origin_link}"
# 
#     @cached_property
#     def domain(self):
#         o = parse.urlparse(self.origin_link)
#         return o.netloc
# 
# Path: apps/cryptonews/serializers.py
# class PushExchangeAnnSerializer(serializers.ModelSerializer):
#     channel = serializers.CharField(
#         default="ExchangeAnnChannel", read_only=True
#     )
# 
#     class Meta:
#         model = News
#         exclude = [
#             "id",
#             "content",
#             "slug",
#         ]
# 
# Path: apps/cryptonews/utils/translator.py
# def translate_text(text, source="ok", target="en") -> str:
#     _r = requests.post(
#         translate_url,
#         json={
#             "text": text,
#             "source": source,
#             "target": target,
#         },
#     )
#     _data = json.loads(_r.text)
#     return _data["TranslatedText"]


# Path: apps/cryptonews/signals.py
import re
import requests
import logging
import opencc
from datetime import datetime, timedelta
from django.conf import settings
from apps.cryptonews.models import News
from apps.cryptonews.serializers import PushExchangeAnnSerializer
from apps.cryptonews.utils.translator import translate_text


logger = logging.getLogger("django")

debug = getattr(settings, "DEBUG")

p = re.compile(r"^\[.*?\]", re.IGNORECASE)
gate_pattern = re.compile("^gate\\.io", re.IGNORECASE)

binance_pattern = re.compile("^幣安")