Skip to content

Commit

Permalink
Merge branch 'master' into python3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
daboross committed May 8, 2017
2 parents 8c9a725 + 2e8253f commit 395c613
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
7 changes: 6 additions & 1 deletion plugins/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ def amazon(text, _parsed=False):
r"|Spedizione gratuita)", item.text, re.I):
tags.append("$(b)Free Shipping$(b)")

price = item.find('span', {'class': ['s-price', 'a-color-price']}).text
try:
price = item.find('span', {'class': ['s-price', 'a-color-price']}).text
except AttributeError:
for i in item.find_all('sup', {'class': 'sx-price-fractional'}):
i.string.replace_with('.' + i.string)
price = item.find('span', {'class': 'sx-price'}).text

# use a whole lot of BS4 and regex to get the ratings
try:
Expand Down
2 changes: 1 addition & 1 deletion plugins/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


SESSION = collections.OrderedDict()
API_URL = "http://www.cleverbot.com/webservicemin/"
API_URL = "http://www.cleverbot.com/webservicemin?uc=321&"

HEADERS = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
Expand Down
37 changes: 17 additions & 20 deletions plugins/scene.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"""
scene.py
Provides commands for searching scene releases using orlydb.com.
Provides commands for searching scene releases using pre.corrupt-net.org.
Created By:
- Ryan Hitchman <https://github.com/rmmh>
Modified By:
- Luke Rogers <https://github.com/lukeroge>
Converted to pre.corrupt-net.org By:
- whocares <http://github.com/whocares-openscene>
License:
GPL v3
"""

import datetime

import requests
import re
from lxml import html

from cloudbot import hook
Expand All @@ -24,37 +28,30 @@

@hook.command("pre", "scene")
def pre(text):
"""pre <query> -- searches scene releases using orlydb.com"""
"""pre <query> -- searches scene releases using pre.corrupt.org"""

try:
request = requests.get("http://orlydb.com/", params={"q": text})
headers = {'Accept-Language': 'en-US'}
request = requests.get("https://pre.corrupt-net.org/search.php", params={"search": text}, headers=headers)
request.raise_for_status()
except requests.exceptions.HTTPError as e:
return 'Unable to fetch results: {}'.format(e)
split = request.text.partition('</tr><tr>')

h = html.fromstring(request.text)

results = h.xpath("//div[@id='releases']/div/span[@class='release']/..")

if not results:
results = re.search("<tr><td id\=\"rlstype\".*>(.*)</td><td.*>&nbsp;&nbsp;(.*)<span id\=\"rlsgroup\"><font color\='#C0C0C0'>(.*)</font>.*>(\d*F).*>([\d\.]*M).*&nbsp;&nbsp;(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})</td>", split[0], flags=re.IGNORECASE)
if results is None:
return "No results found."

result = results[0]

date = result.xpath("span[@class='timestamp']/text()")[0]
section = result.xpath("span[@class='section']//text()")[0]
name = result.xpath("span[@class='release']/text()")[0]
date = results.group(6)
section = results.group(1)
name = results.group(2) + results.group(3)
size = results.group(5)
files = results.group(4)

# parse date/time
date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
date_string = date.strftime("%d %b %Y")
since = timeformat.time_since(date)

size = result.xpath("span[@class='inforight']//text()")
if size:
size = ' - ' + size[0].split()[0]
else:
size = ''

return '{} - {}{} - {} ({} ago)'.format(section, name, size, date_string, since)
return '{} - {} - {} - {} - {} ({} ago)'.format(section, name, size, files, date_string, since)

0 comments on commit 395c613

Please sign in to comment.