Browse Source

Validate site info if not in sites DB

copyvios-ng
Ben Kurtovic 5 years ago
parent
commit
4cebe36eee
1 changed files with 13 additions and 8 deletions
  1. +13
    -8
      copyvios/sites.py

+ 13
- 8
copyvios/sites.py View File

@@ -18,23 +18,28 @@ def get_site(query):
try: try:
return wiki.get_site(name=name) return wiki.get_site(name=name)
except exceptions.SiteNotFoundError: 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: try:
return wiki.get_site(lang=lang, project=project) return wiki.get_site(lang=lang, project=project)
except exceptions.SiteNotFoundError: 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(): def update_sites():
if time() - cache.last_sites_update > 60 * 60 * 24 * 7: if time() - cache.last_sites_update > 60 * 60 * 24 * 7:
cache.langs, cache.projects = _load_sites() cache.langs, cache.projects = _load_sites()
cache.last_sites_update = time() 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(): def _load_sites():
site = cache.bot.wiki.get_site() site = cache.bot.wiki.get_site()
matrix = site.api_query(action="sitematrix")["sitematrix"] matrix = site.api_query(action="sitematrix")["sitematrix"]


Loading…
Cancel
Save