소스 검색

More accurate handling when using get_site(lang, project).

Some wikis (like frwiki), set their projects to localized forms of
the expected (so "wikipedia" becomes "wikipédia"). An additional
search by URL in _get_site_name_from_sitesdb() fixes this.
tags/v0.1^2
Ben Kurtovic 12 년 전
부모
커밋
3f1737717c
1개의 변경된 파일16개의 추가작업 그리고 3개의 파일을 삭제
  1. +16
    -3
      earwigbot/wiki/sitesdb.py

+ 16
- 3
earwigbot/wiki/sitesdb.py 파일 보기

@@ -220,14 +220,27 @@ class SitesDB(object):
def _get_site_name_from_sitesdb(self, project, lang):
"""Return the name of the first site with the given project and lang.

If we can't find the site with the given information, we'll also try
searching for a site whose base_url contains "{lang}.{project}". There
are a few sites, like the French Wikipedia, that set their project to
something other than the expected "wikipedia" ("wikipédia" in this
case), but we should correctly find them when doing get_site(lang="fr",
project="wikipedia").

If the site is not found, return None. An empty sitesdb will be created
if none exists.
"""
query = "SELECT site_name FROM sites WHERE site_project = ? and site_lang = ?"
query1 = "SELECT site_name FROM sites WHERE site_project = ? and site_lang = ?"
query2 = "SELECT site_name FROM sites WHERE site_base_url LIKE ?"
with sqlite.connect(self._sitesdb) as conn:
try:
site = conn.execute(query, (project, lang)).fetchone()
return site[0] if site else None
site = conn.execute(query1, (project, lang)).fetchone()
if site:
return site[0]
else:
url = "%{0}.{1}%".format(lang, project)
site = conn.execute(query2, (url,)).fetchone()
return site[0] if site else None
except sqlite.OperationalError:
self._create_sitesdb()



불러오는 중...
취소
저장