howdoi
Bobloy 7 years ago
parent 447db7a133
commit 6ff12032b3

@ -13,26 +13,27 @@ import glob
import os
import random
import re
import requests
import requests_cache
import sys
from . import __version__
import requests
import requests_cache
from pygments import highlight
from pygments.lexers import guess_lexer, get_lexer_by_name
from pygments.formatters.terminal import TerminalFormatter
from pygments.lexers import guess_lexer, get_lexer_by_name
from pygments.util import ClassNotFound
from pyquery import PyQuery as pq
from requests.exceptions import ConnectionError
from requests.exceptions import SSLError
from . import __version__
# Handle imports for Python 2 and 3
if sys.version < '3':
import codecs
from urllib import quote as url_quote
from urllib import getproxies
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
def u(x):
return codecs.unicode_escape_decode(x)[0]
@ -40,10 +41,10 @@ else:
from urllib.request import getproxies
from urllib.parse import quote as url_quote
def u(x):
return x
if os.getenv('HOWDOI_DISABLE_SSL'): # Set http instead of https
SCHEME = 'http://'
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) '
'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'
'Safari/536.5'), )
'Safari/536.5'),)
SEARCH_URLS = {
'bing': SCHEME + 'www.bing.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):
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):

@ -1,11 +1,9 @@
import discord
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 .utils.chat_formatting import box
from .howdoi_source import howdoi as hdi, Answer
from .howdoi_source import howdoi as hdi
class Howdoi:
@ -24,7 +22,7 @@ class Howdoi:
"num_answers": 1,
"clear_cache": False,
"version": False
}
}
self.config.register_global(**default_global)
@ -36,7 +34,7 @@ class Howdoi:
await ctx.send_help()
@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.
Defaults to 1"""
@ -75,11 +73,11 @@ class Howdoi:
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():
await ctx.send(out)
else:
await ctx.send(box(out,"python"))
await ctx.send(box(out, "python"))
# 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 random
import re
import requests
import requests_cache
import sys
from . import __version__
import requests
import requests_cache
from pygments import highlight
from pygments.lexers import guess_lexer, get_lexer_by_name
from pygments.formatters.terminal import TerminalFormatter
from pygments.lexers import guess_lexer, get_lexer_by_name
from pygments.util import ClassNotFound
from pyquery import PyQuery as pq
from requests.exceptions import ConnectionError
from requests.exceptions import SSLError
from . import __version__
# Handle imports for Python 2 and 3
if sys.version < '3':
import codecs
from urllib import quote as url_quote
from urllib import getproxies
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
def u(x):
return codecs.unicode_escape_decode(x)[0]
@ -40,10 +41,10 @@ else:
from urllib.request import getproxies
from urllib.parse import quote as url_quote
def u(x):
return x
if os.getenv('HOWDOI_DISABLE_SSL'): # Set http instead of https
SCHEME = 'http://'
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) '
'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'
'Safari/536.5'), )
'Safari/536.5'),)
SEARCH_URLS = {
'bing': SCHEME + 'www.bing.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):
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):

@ -1,10 +1,28 @@
{
"author" : ["Bobloy"],
"bot_version" : [3,0,0],
"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"]
"author": [
"Bobloy"
],
"bot_version": [
3,
0,
0
],
"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…
Cancel
Save