A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

69 lignes
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. from time import time
  3. from urlparse import urlparse
  4. from earwigbot import exceptions
  5. from .misc import cache
  6. __all__ = ["get_site", "update_sites"]
  7. def get_site(query):
  8. lang, project, name = query.lang, query.project, query.name
  9. wiki = cache.bot.wiki
  10. if project not in [proj[0] for proj in cache.projects]:
  11. return None
  12. if project == "wikimedia" and name: # Special sites:
  13. try:
  14. return wiki.get_site(name=name)
  15. except exceptions.SiteNotFoundError:
  16. try:
  17. return wiki.add_site(lang=lang, project=project)
  18. except (exceptions.APIError, exceptions.LoginError):
  19. return None
  20. try:
  21. return wiki.get_site(lang=lang, project=project)
  22. except exceptions.SiteNotFoundError:
  23. try:
  24. return wiki.add_site(lang=lang, project=project)
  25. except (exceptions.APIError, exceptions.LoginError):
  26. return None
  27. def update_sites():
  28. if time() - cache.last_sites_update > 60 * 60 * 24 * 7:
  29. cache.langs, cache.projects = _load_sites()
  30. cache.last_sites_update = time()
  31. def _load_sites():
  32. site = cache.bot.wiki.get_site()
  33. matrix = site.api_query(action="sitematrix")["sitematrix"]
  34. del matrix["count"]
  35. langs, projects = set(), set()
  36. for site in matrix.itervalues():
  37. if isinstance(site, list): # Special sites
  38. bad_sites = ["closed", "private", "fishbowl"]
  39. for special in site:
  40. if all([key not in special for key in bad_sites]):
  41. full = urlparse(special["url"]).netloc
  42. if full.count(".") == 1: # No subdomain, so use "www"
  43. lang, project = "www", full.split(".")[0]
  44. else:
  45. lang, project = full.rsplit(".", 2)[:2]
  46. code = u"{0}::{1}".format(lang, special["dbname"])
  47. name = special["code"].capitalize()
  48. langs.add((code, u"{0} ({1})".format(lang, name)))
  49. projects.add((project, project.capitalize()))
  50. else:
  51. this = set()
  52. for web in site["site"]:
  53. if "closed" in web:
  54. continue
  55. proj = "wikipedia" if web["code"] == u"wiki" else web["code"]
  56. this.add((proj, proj.capitalize()))
  57. if this:
  58. code = site["code"]
  59. langs.add((code, u"{0} ({1})".format(code, site["name"])))
  60. projects |= this
  61. return list(sorted(langs)), list(sorted(projects))