pep8
This commit is contained in:
parent
447db7a133
commit
6ff12032b3
@ -13,26 +13,27 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests_cache
|
import requests_cache
|
||||||
import sys
|
|
||||||
from . import __version__
|
|
||||||
|
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.lexers import guess_lexer, get_lexer_by_name
|
|
||||||
from pygments.formatters.terminal import TerminalFormatter
|
from pygments.formatters.terminal import TerminalFormatter
|
||||||
|
from pygments.lexers import guess_lexer, get_lexer_by_name
|
||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
|
|
||||||
from pyquery import PyQuery as pq
|
from pyquery import PyQuery as pq
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
from requests.exceptions import SSLError
|
from requests.exceptions import SSLError
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
|
|
||||||
# Handle imports for Python 2 and 3
|
# Handle imports for Python 2 and 3
|
||||||
if sys.version < '3':
|
if sys.version < '3':
|
||||||
import codecs
|
import codecs
|
||||||
from urllib import quote as url_quote
|
from urllib import quote as url_quote
|
||||||
from urllib import getproxies
|
from urllib import getproxies
|
||||||
|
|
||||||
|
|
||||||
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
|
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
|
||||||
def u(x):
|
def u(x):
|
||||||
return codecs.unicode_escape_decode(x)[0]
|
return codecs.unicode_escape_decode(x)[0]
|
||||||
@ -40,10 +41,10 @@ else:
|
|||||||
from urllib.request import getproxies
|
from urllib.request import getproxies
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
|
|
||||||
|
|
||||||
def u(x):
|
def u(x):
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
if os.getenv('HOWDOI_DISABLE_SSL'): # Set http instead of https
|
if os.getenv('HOWDOI_DISABLE_SSL'): # Set http instead of https
|
||||||
SCHEME = 'http://'
|
SCHEME = 'http://'
|
||||||
VERIFY_SSL_CERTIFICATE = False
|
VERIFY_SSL_CERTIFICATE = False
|
||||||
@ -59,7 +60,7 @@ USER_AGENTS = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/2010
|
|||||||
('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) '
|
('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) '
|
||||||
'Chrome/19.0.1084.46 Safari/536.5'),
|
'Chrome/19.0.1084.46 Safari/536.5'),
|
||||||
('Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46'
|
('Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46'
|
||||||
'Safari/536.5'), )
|
'Safari/536.5'),)
|
||||||
SEARCH_URLS = {
|
SEARCH_URLS = {
|
||||||
'bing': SCHEME + 'www.bing.com/search?q=site:{0}%20{1}',
|
'bing': SCHEME + 'www.bing.com/search?q=site:{0}%20{1}',
|
||||||
'google': SCHEME + 'www.google.com/search?q=site:{0}%20{1}'
|
'google': SCHEME + 'www.google.com/search?q=site:{0}%20{1}'
|
||||||
@ -104,7 +105,7 @@ def _extract_links_from_bing(html):
|
|||||||
|
|
||||||
def _extract_links_from_google(html):
|
def _extract_links_from_google(html):
|
||||||
return [a.attrib['href'] for a in html('.l')] or \
|
return [a.attrib['href'] for a in html('.l')] or \
|
||||||
[a.attrib['href'] for a in html('.r')('a')]
|
[a.attrib['href'] for a in html('.r')('a')]
|
||||||
|
|
||||||
|
|
||||||
def _extract_links(html, search_engine):
|
def _extract_links(html, search_engine):
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from redbot.core import Config
|
||||||
|
from redbot.core.utils.chat_formatting import box
|
||||||
|
|
||||||
from .utils.chat_formatting import pagify
|
from .howdoi_source import howdoi as hdi
|
||||||
from .utils.chat_formatting import box
|
|
||||||
|
|
||||||
from .howdoi_source import howdoi as hdi, Answer
|
|
||||||
|
|
||||||
|
|
||||||
class Howdoi:
|
class Howdoi:
|
||||||
@ -24,7 +22,7 @@ class Howdoi:
|
|||||||
"num_answers": 1,
|
"num_answers": 1,
|
||||||
"clear_cache": False,
|
"clear_cache": False,
|
||||||
"version": False
|
"version": False
|
||||||
}
|
}
|
||||||
|
|
||||||
self.config.register_global(**default_global)
|
self.config.register_global(**default_global)
|
||||||
|
|
||||||
@ -36,7 +34,7 @@ class Howdoi:
|
|||||||
await ctx.send_help()
|
await ctx.send_help()
|
||||||
|
|
||||||
@howdoiset.command(pass_context=True, name="answers")
|
@howdoiset.command(pass_context=True, name="answers")
|
||||||
async def howdoiset_answers(self, ctx, num_answers: int=1):
|
async def howdoiset_answers(self, ctx, num_answers: int = 1):
|
||||||
"""Adjust number of answers provided.
|
"""Adjust number of answers provided.
|
||||||
Defaults to 1"""
|
Defaults to 1"""
|
||||||
|
|
||||||
@ -75,11 +73,11 @@ class Howdoi:
|
|||||||
|
|
||||||
await self.config.query.set(self.query)
|
await self.config.query.set(self.query)
|
||||||
|
|
||||||
out = hdi.howdoi(await self.config.all()) # .encode('utf-8', 'ignore')
|
out = hdi(await self.config.all()) # .encode('utf-8', 'ignore')
|
||||||
|
|
||||||
if await self.config.links():
|
if await self.config.links():
|
||||||
await ctx.send(out)
|
await ctx.send(out)
|
||||||
else:
|
else:
|
||||||
await ctx.send(box(out,"python"))
|
await ctx.send(box(out, "python"))
|
||||||
# for page in pagify(out, shorten_by=24):
|
# for page in pagify(out, shorten_by=24):
|
||||||
# await ctx.send(box(page))
|
# await ctx.send(box(page))
|
||||||
|
@ -13,26 +13,27 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests_cache
|
import requests_cache
|
||||||
import sys
|
|
||||||
from . import __version__
|
|
||||||
|
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.lexers import guess_lexer, get_lexer_by_name
|
|
||||||
from pygments.formatters.terminal import TerminalFormatter
|
from pygments.formatters.terminal import TerminalFormatter
|
||||||
|
from pygments.lexers import guess_lexer, get_lexer_by_name
|
||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
|
|
||||||
from pyquery import PyQuery as pq
|
from pyquery import PyQuery as pq
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
from requests.exceptions import SSLError
|
from requests.exceptions import SSLError
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
|
|
||||||
# Handle imports for Python 2 and 3
|
# Handle imports for Python 2 and 3
|
||||||
if sys.version < '3':
|
if sys.version < '3':
|
||||||
import codecs
|
import codecs
|
||||||
from urllib import quote as url_quote
|
from urllib import quote as url_quote
|
||||||
from urllib import getproxies
|
from urllib import getproxies
|
||||||
|
|
||||||
|
|
||||||
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
|
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
|
||||||
def u(x):
|
def u(x):
|
||||||
return codecs.unicode_escape_decode(x)[0]
|
return codecs.unicode_escape_decode(x)[0]
|
||||||
@ -40,10 +41,10 @@ else:
|
|||||||
from urllib.request import getproxies
|
from urllib.request import getproxies
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
|
|
||||||
|
|
||||||
def u(x):
|
def u(x):
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
if os.getenv('HOWDOI_DISABLE_SSL'): # Set http instead of https
|
if os.getenv('HOWDOI_DISABLE_SSL'): # Set http instead of https
|
||||||
SCHEME = 'http://'
|
SCHEME = 'http://'
|
||||||
VERIFY_SSL_CERTIFICATE = False
|
VERIFY_SSL_CERTIFICATE = False
|
||||||
@ -59,7 +60,7 @@ USER_AGENTS = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/2010
|
|||||||
('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) '
|
('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) '
|
||||||
'Chrome/19.0.1084.46 Safari/536.5'),
|
'Chrome/19.0.1084.46 Safari/536.5'),
|
||||||
('Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46'
|
('Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46'
|
||||||
'Safari/536.5'), )
|
'Safari/536.5'),)
|
||||||
SEARCH_URLS = {
|
SEARCH_URLS = {
|
||||||
'bing': SCHEME + 'www.bing.com/search?q=site:{0}%20{1}',
|
'bing': SCHEME + 'www.bing.com/search?q=site:{0}%20{1}',
|
||||||
'google': SCHEME + 'www.google.com/search?q=site:{0}%20{1}'
|
'google': SCHEME + 'www.google.com/search?q=site:{0}%20{1}'
|
||||||
@ -109,7 +110,7 @@ def _extract_links_from_bing(html):
|
|||||||
|
|
||||||
def _extract_links_from_google(html):
|
def _extract_links_from_google(html):
|
||||||
return [a.attrib['href'] for a in html('.l')] or \
|
return [a.attrib['href'] for a in html('.l')] or \
|
||||||
[a.attrib['href'] for a in html('.r')('a')]
|
[a.attrib['href'] for a in html('.r')('a')]
|
||||||
|
|
||||||
|
|
||||||
def _extract_links(html, search_engine):
|
def _extract_links(html, search_engine):
|
||||||
|
@ -1,10 +1,28 @@
|
|||||||
{
|
{
|
||||||
"author" : ["Bobloy"],
|
"author": [
|
||||||
"bot_version" : [3,0,0],
|
"Bobloy"
|
||||||
"description" : "Answer coding questions using stackexchange",
|
],
|
||||||
"hidden" : false,
|
"bot_version": [
|
||||||
"install_msg" : "Thank you for installing Howdoi.",
|
3,
|
||||||
"requirements" : ["Pygments==2.1.1", "argparse==1.4.0", "cssselect==0.9.1", "pyquery==1.4.0", "requests==2.9.1", "requests-cache==0.4.11"],
|
0,
|
||||||
"short" : "Answer coding questions",
|
0
|
||||||
"tags" : ["coding", "tools", "utils", "bobloy"]
|
],
|
||||||
|
"description": "Answer coding questions using stackexchange",
|
||||||
|
"hidden": false,
|
||||||
|
"install_msg": "Thank you for installing Howdoi.",
|
||||||
|
"requirements": [
|
||||||
|
"Pygments==2.1.1",
|
||||||
|
"argparse==1.4.0",
|
||||||
|
"cssselect==0.9.1",
|
||||||
|
"pyquery==1.4.0",
|
||||||
|
"requests==2.9.1",
|
||||||
|
"requests-cache==0.4.11"
|
||||||
|
],
|
||||||
|
"short": "Answer coding questions",
|
||||||
|
"tags": [
|
||||||
|
"coding",
|
||||||
|
"tools",
|
||||||
|
"utils",
|
||||||
|
"bobloy"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user