瀏覽代碼

Validate site info if not in sites DB

copyvios-ng
Ben Kurtovic 5 年之前
父節點
當前提交
4cebe36eee
共有 1 個檔案被更改,包括 13 行新增8 行删除
  1. +13
    -8
      copyvios/sites.py

+ 13
- 8
copyvios/sites.py 查看文件

@@ -18,23 +18,28 @@ def get_site(query):
try:
return wiki.get_site(name=name)
except exceptions.SiteNotFoundError:
try:
return wiki.add_site(lang=lang, project=project)
except (exceptions.APIError, exceptions.LoginError):
return None
return _add_site(lang, project)
try:
return wiki.get_site(lang=lang, project=project)
except exceptions.SiteNotFoundError:
try:
return wiki.add_site(lang=lang, project=project)
except (exceptions.APIError, exceptions.LoginError):
return None
return _add_site(lang, project)

def update_sites():
if time() - cache.last_sites_update > 60 * 60 * 24 * 7:
cache.langs, cache.projects = _load_sites()
cache.last_sites_update = time()

def _add_site(lang, project):
update_sites()
if not any(project == item[0] for item in cache.projects):
return None
if lang != "www" and not any(lang == item[0] for item in cache.langs):
return None
try:
return cache.bot.wiki.add_site(lang=lang, project=project)
except (exceptions.APIError, exceptions.LoginError):
return None

def _load_sites():
site = cache.bot.wiki.get_site()
matrix = site.api_query(action="sitematrix")["sitematrix"]


Loading…
取消
儲存