Ver a proveniência

Site.url; some refactoring and cleanup

tags/v0.1^2
Ben Kurtovic há 12 anos
ascendente
cometimento
729aa04cc1
5 ficheiros alterados com 30 adições e 16 eliminações
  1. +2
    -0
      docs/toolset.rst
  2. +12
    -6
      earwigbot/commands/_old.py
  3. +2
    -1
      earwigbot/commands/afc_submissions.py
  4. +1
    -1
      earwigbot/wiki/page.py
  5. +13
    -8
      earwigbot/wiki/site.py

+ 2
- 0
docs/toolset.rst Ver ficheiro

@@ -80,6 +80,8 @@ following attributes:
``"en"``
- :py:attr:`~earwigbot.wiki.site.Site.domain`: the site's web domain, like
``"en.wikipedia.org"``
- :py:attr:`~earwigbot.wiki.site.Site.url`: the site's full base URL, like
``"https://en.wikipedia.org"``

and the following methods:



+ 12
- 6
earwigbot/commands/_old.py Ver ficheiro

@@ -9,18 +9,16 @@

def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s):
authy = auth(host)


if command == "access":
a = 'The bot\'s owner is "%s".' % OWNER
b = 'The bot\'s admins are "%s".' % ', '.join(ADMINS_R)
reply(a, chan, nick)
reply(b, chan, nick)
return
if command == "tock":
u = urllib.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
info = u.info()
u.close()
say('"' + info['Date'] + '" - tycho.usno.navy.mil', chan)
return


if command == "dict" or command == "dictionary":
def trim(thing):
if thing.endswith(' '):
@@ -58,6 +56,8 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s):
reply('Sorry, no definition found.', chan, nick)
else: say(result, chan)
return


if command == "ety" or command == "etymology":
etyuri = 'http://etymonline.com/?term=%s'
etysearch = 'http://etymonline.com/?search=%s'
@@ -126,6 +126,8 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s):
msg = 'Can\'t find the etymology for "%s". Try %s' % (word, uri)
reply(msg, chan, nick)
return


if command == "sub" or command == "submissions":
try:
number = int(line2[4])
@@ -162,6 +164,8 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s):
report = "\x02First %s pending AfC submissions:\x0F %s" % (number, s)
say(report, chan)
return


if command == "trout":
try:
user = line2[4]
@@ -182,6 +186,8 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s):
else:
reply("I refuse to hurt anything with \"Earwig\" in its name :P", chan, nick)
return


if command == "notes" or command == "note" or command == "about" or command == "data" or command == "database":
try:
action = line2[4]


+ 2
- 1
earwigbot/commands/afc_submissions.py Ver ficheiro

@@ -55,5 +55,6 @@ class AFCSubmissions(Command):

site = self.bot.wiki.get_site()
category = site.get_category("Pending AfC submissions")
pages = ", ".join(category.get_members(use_sql=True, limit=number))
members = category.get_members(use_sql=True, limit=number)
pages = ", ".join([member.url for member in members])
self.reply(data, "{0} pending AfC subs: {1}".format(number, pages))

+ 1
- 1
earwigbot/wiki/page.py Ver ficheiro

@@ -498,7 +498,7 @@ class Page(CopyrightMixin):
else:
slug = quote(self._title.replace(" ", "_"), safe="/:")
path = self._site._article_path.replace("$1", slug)
return ''.join((self._site._base_url, path))
return ''.join((self._site.url, path))

@property
def namespace(self):


+ 13
- 8
earwigbot/wiki/site.py Ver ficheiro

@@ -69,6 +69,7 @@ class Site(object):
- :py:attr:`project`: the site's project name, like ``"wikipedia"``
- :py:attr:`lang`: the site's language code, like ``"en"``
- :py:attr:`domain`: the site's web domain, like ``"en.wikipedia.org"``
- :py:attr:`url`: the site's URL, like ``"https://en.wikipedia.org"``

*Public methods:*

@@ -243,14 +244,7 @@ class Site(object):
e = "Tried to do an API query, but no API URL is known."
raise exceptions.SiteAPIError(e)

base_url = self._base_url
if base_url.startswith("//"): # Protocol-relative URLs from 1.18
if self._use_https:
base_url = "https:" + base_url
else:
base_url = "http:" + base_url
url = ''.join((base_url, self._script_path, "/api.php"))

url = ''.join((self.url, self._script_path, "/api.php"))
params["format"] = "json" # This is the only format we understand
if self._assert_edit: # If requested, ensure that we're logged in
params["assert"] = self._assert_edit
@@ -548,6 +542,17 @@ class Site(object):
"""The Site's web domain, like ``"en.wikipedia.org"``."""
return urlparse(self._base_url).netloc

@property
def url(self):
"""The Site's full base URL, like ``"https://en.wikipedia.org"``."""
url = self._base_url
if url.startswith("//"): # Protocol-relative URLs from 1.18
if self._use_https:
url = "https:" + url
else:
url = "http:" + url
return url

def api_query(self, **kwargs):
"""Do an API query with `kwargs` as the parameters.



Carregando…
Cancelar
Guardar