-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
368 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File : migrate_110_to_1212.py | ||
@Date : 2023-02-06 | ||
cmd: | ||
$ python domain_admin/migrate/migrate_110_to_1212.py | ||
""" | ||
|
||
from playhouse.migrate import SqliteMigrator, migrate | ||
|
||
from domain_admin.model.base_model import db | ||
from domain_admin.model.domain_model import DomainModel | ||
|
||
|
||
def execute_migrate(): | ||
""" | ||
版本升级 1.1.0 => 1.2.12 | ||
:return: | ||
""" | ||
migrator = SqliteMigrator(db) | ||
|
||
migrate( | ||
migrator.add_column(DomainModel._meta.table_name, DomainModel.domain_check_time.name, DomainModel.domain_check_time), | ||
migrator.add_column(DomainModel._meta.table_name, DomainModel.ip_check_time.name, DomainModel.ip_check_time), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import datetime | ||
|
||
from peewee import CharField, IntegerField, DateTimeField | ||
|
||
from domain_admin.model.base_model import BaseModel | ||
|
||
|
||
class CacheDomainInfoModel(BaseModel): | ||
""" | ||
域名信息缓存表 | ||
@since 1.2.12 | ||
""" | ||
id = IntegerField(primary_key=True) | ||
|
||
# 域名 | ||
domain = CharField(unique=True) | ||
|
||
# 域名注册时间 | ||
domain_start_time = DateTimeField(default=None, null=True) | ||
|
||
# 域名过期时间 | ||
domain_expire_time = DateTimeField(default=None, null=True) | ||
|
||
# 缓存过期时间 | ||
expire_time = DateTimeField(default=None, null=True) | ||
|
||
# 创建时间 | ||
create_time = DateTimeField(default=datetime.now) | ||
|
||
# 更新时间 | ||
update_time = DateTimeField(default=datetime.now) | ||
|
||
class Meta: | ||
table_name = 'cache_domain_info' | ||
|
||
@property | ||
def is_expired(self) -> [bool, None]: | ||
""" | ||
过期时间 | ||
:return: | ||
""" | ||
if self.expire_time: | ||
return (self.expire_time - datetime.now()).seconds <= 0 | ||
else: | ||
return None | ||
|
||
@property | ||
def domain_expire_days(self) -> [int, None]: | ||
"""域名过期天数""" | ||
if self.domain_expire_time: | ||
return (self.domain_expire_time - datetime.now()).days | ||
else: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File : cache_domain_info_service.py | ||
@Date : 2023-04-22 | ||
""" | ||
from datetime import datetime, timedelta | ||
|
||
from domain_admin.model.cache_domain_info_model import CacheDomainInfoModel | ||
from domain_admin.utils import domain_util | ||
from domain_admin.utils import domain_util | ||
from domain_admin.utils.whois_util import whois_util | ||
|
||
|
||
def get_domain_info(domain: str) -> CacheDomainInfoModel: | ||
""" | ||
加一个缓存获取域名信息 | ||
:param domain: | ||
:return: | ||
""" | ||
root_domain = domain_util.get_root_domain(domain) | ||
|
||
row = CacheDomainInfoModel.select().where( | ||
CacheDomainInfoModel.domain == root_domain | ||
).get_or_none() | ||
|
||
# 不存在或者已过期,重新获取 | ||
if not row or row.is_expired is True: | ||
domain_whois = whois_util.get_domain_whois(root_domain) | ||
|
||
if domain_whois is None: | ||
raise Exception("域名信息获取失败") | ||
|
||
row = CacheDomainInfoModel.create( | ||
domain=root_domain, | ||
domain_start_time=domain_whois['start_time'], | ||
domain_expire_time=domain_whois['expire_time'], | ||
expire_time=datetime.now() + timedelta(hours=1) | ||
) | ||
|
||
return row |
Oops, something went wrong.