Skip to content

Commit

Permalink
requests patch update
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Nov 1, 2018
1 parent 9282214 commit cbc3aba
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -8,6 +8,7 @@ python:
install:
- pip install -r requirements.txt
- python setup.py install
script:
- pip install pprint
- python tests.py
script:
- python tests/crud_test.py
- python tests/custom_decoder_test.py
13 changes: 5 additions & 8 deletions README.md
Expand Up @@ -117,18 +117,15 @@ from resteasy import RESTEasy
from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.found = False
self.anime = None

'''Custom HTML parser'''

def handle_starttag(self, tag, attrs):
'''Inherited method'''
'''Overriding abstract method'''
if tag == 'title' and not self.found:
self.found = True

def handle_data(self, data):
'''Inherited method'''
'''Overriding abstract method'''
if self.found and self.anime is None:
self.anime = data

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1 +1 @@
requests==2.18.4
requests==2.20.0
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from os import path


VERSION = 'v1.0.3'
VERSION = 'v1.0.4'

here = path.abspath(path.dirname(__file__))

Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions tests/custom_decoder_test.py
@@ -0,0 +1,36 @@
from pprint import pprint
from resteasy import RESTEasy
try:
from html.parser import HTMLParser
except ImportError:
from HTMLParser import HTMLParser


class MyHTMLParser(HTMLParser):
'''Custom HTML parser'''

def handle_starttag(self, tag, attrs):
'''Overriding abstract method'''
if tag == 'title' and not self.found:
self.found = True

def handle_data(self, data):
'''Overriding abstract method'''
if self.found and self.anime is None:
self.anime = data

def parse(self, content):
'''Parse content and return object'''
self.found = False
self.anime = None
self.feed(content)
title = self.anime.strip().replace(
' - MyAnimeList.net', '') if self.found else None
return dict(title=title)


parser = MyHTMLParser()

api = RESTEasy(base_url='https://myanimelist.net', decoder=parser.parse)

pprint(api.route('anime', 1).get())

0 comments on commit cbc3aba

Please sign in to comment.