2020-11-04 02:00:58 +00:00
|
|
|
import logging
|
|
|
|
logging.basicConfig(
|
|
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
|
level=logging.DEBUG)
|
|
|
|
import requests
|
|
|
|
|
|
|
|
DECLUTTER_API = 'https://declutter.1j.nz/details'
|
2020-11-05 01:23:51 +00:00
|
|
|
DECLUTTER_COMMENT_API = 'https://declutter.1j.nz/comments'
|
2020-11-04 02:14:51 +00:00
|
|
|
TIMEOUT = 30
|
2020-11-04 02:00:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_html(url):
|
2020-11-04 02:37:19 +00:00
|
|
|
logging.info(f"Declutter Scraper: {url}")
|
|
|
|
details = get_details(url)
|
|
|
|
if not details:
|
|
|
|
return ''
|
|
|
|
return details['content']
|
2020-11-04 02:00:58 +00:00
|
|
|
|
|
|
|
def get_details(url):
|
|
|
|
try:
|
2020-11-04 02:14:51 +00:00
|
|
|
r = requests.post(DECLUTTER_API, data=dict(url=url), timeout=TIMEOUT)
|
2020-11-04 02:00:58 +00:00
|
|
|
if r.status_code != 200:
|
|
|
|
raise Exception('Bad response code ' + str(r.status_code))
|
|
|
|
return r.json()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
raise
|
|
|
|
except BaseException as e:
|
|
|
|
logging.error('Problem decluttering article: {}'.format(str(e)))
|
2020-11-05 01:23:51 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def get_comments(url):
|
|
|
|
try:
|
|
|
|
r = requests.post(DECLUTTER_COMMENT_API, data=dict(url=url), timeout=TIMEOUT)
|
|
|
|
if r.status_code != 200:
|
|
|
|
raise Exception('Bad response code ' + str(r.status_code))
|
|
|
|
return r.json()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
raise
|
|
|
|
except BaseException as e:
|
|
|
|
logging.error('Problem getting comments for article: {}'.format(str(e)))
|
2020-11-04 02:14:51 +00:00
|
|
|
return None
|