Skip to content

Commit 2801eee

Browse files
committed
util.py HTMLParser deprecation fix
also: - some minimal PEP8 standartizations - update dead 8chan urls - update version according to docs/conf.py
1 parent ba191de commit 2801eee

File tree

10 files changed

+28
-25
lines changed

10 files changed

+28
-25
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Usage
3333
.. code:: python
3434
3535
import pyvichan
36-
v = pyvichan.Board('v', '8ch.pl')
37-
thread = v.get_thread(462)
36+
v = pyvichan.Board('v', '8kun.top')
37+
thread = v.get_thread(16959924)
3838
3939
print(thread)
4040

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
# built documents.
5050
#
5151
# The short X.Y version.
52-
version = '0.4.2'
52+
version = '0.4.3'
5353
# The full version, including alpha/beta/rc tags.
54-
release = '0.4.2'
54+
release = '0.4.3'
5555

5656
# The language for content autogenerated by Sphinx. Refer to documentation
5757
# for a list of supported languages.

examples/example2.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# credits to Anarov for improved example.py
22
from __future__ import print_function
3+
import sys
34
import pyvichan
45

56
def main():

examples/example3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# credits to Anarov for improved example.py
22
import pyvichan
33

4-
b = pyvichan.Board('b')
4+
b = pyvichan.Board('v')
55
threads = b.get_threads()
66
print("Got %i threads" % len(threads))
77
first_thread = threads[0]

examples/example6-download-thread.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# example6-download-thread.py - download json and all full-size images from a thread
22
from __future__ import print_function
3-
import pyvichan
43
import sys
54
import os
6-
import requests
75
import json
6+
import requests
7+
8+
import pyvichan
89

910
def mkdirs(path):
1011
"""Make directory, if it doesn't exist."""
@@ -43,14 +44,14 @@ def main():
4344
print("%s - Save the JSON and all images for an 8chan post." % (sys.argv[0]))
4445
print("\tUsage: %s <board> <thread_id>" % (sys.argv[0]))
4546
sys.exit(1)
46-
47+
4748
board_name = sys.argv[1]
4849
thread_id = sys.argv[2]
49-
50+
5051
# grab the first thread on the board by checking first page
5152
board = pyvichan.Board(board_name)
5253
thread = board.get_thread(thread_id)
53-
54+
5455
# create folders according to chan.arc standard
5556
path = os.path.join(os.getcwd(), "8chan", board_name, thread_id)
5657
images_path = os.path.join(path, "images")

pyvichan/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
information quickly and easily.
1313
"""
1414

15-
__version__ = '0.0.1'
15+
__version__ = '0.4.3'
1616

1717
from .board import Board, board, get_boards, get_all_boards
1818
from .url import Url
1919
from .thread import Thread
2020
from .post import Post
21-
from .file import File
21+
from .file import File

pyvichan/board.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import requests
4-
54
from . import __version__
65
from .thread import Thread
76
from .url import Url
87

98
# default site URL
10-
_SITE_URL = '8ch.pl'
9+
_SITE_URL = '8kun.top'
1110

1211
# cached metadata for boards
1312
_metadata = {}
@@ -56,7 +55,6 @@ def get_boards(board_name_list, *args, **kwargs):
5655
board_name_list = board_name_list.split()
5756
return [Board(name, *args, **kwargs) for name in board_name_list]
5857

59-
6058
# TODO: Fix this board lister for vichan
6159
def get_all_boards(*args, **kwargs):
6260
"""Returns every board on 4chan.
@@ -262,7 +260,7 @@ def clear_cache(self):
262260
"""Remove everything currently stored in our cache."""
263261
self._thread_cache.clear()
264262

265-
# root site URL provided by the user, such as `8ch.pl`
263+
# root site URL provided by the user, such as `8kun.top`
266264
@property
267265
def site_url(self):
268266
return self._site_url

pyvichan/url.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
# default site URL
5-
_SITE_URL = '8ch.pl'
5+
_SITE_URL = '8kun.top'
66

77
# 8chan URL generator. Inherit and override this for derivative classes (e.g. 420chan API, 8chan/vichan API)
88
class Url(object):
@@ -11,7 +11,7 @@ def __init__(self, board, https=False, site_url=_SITE_URL):
1111
self._board = board
1212
self._protocol = 'https://' if https else 'http://'
1313
self._site_url = site_url
14-
#self._site_url = "8ch.pl"
14+
#self._site_url = "8kun.top"
1515

1616

1717
# Examples

pyvichan/util.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
import re
66

7-
# HTML parser was renamed in python 3.x
7+
# HTMLParser was deprecated since 3.4
88
try:
9-
from html.parser import HTMLParser
9+
from html import unescape
1010
except ImportError:
11-
from HTMLParser import HTMLParser
12-
13-
_parser = HTMLParser()
11+
try:
12+
from html.parser import HTMLParser
13+
except ImportError:
14+
from HTMLParser import HTMLParser
15+
_parser = HTMLParser()
16+
unescape = _parser.unescape
1417

1518

1619
def clean_comment_body(body):
@@ -19,7 +22,7 @@ def clean_comment_body(body):
1922
Converts all HTML tags and entities within 4chan comments
2023
into human-readable text equivalents.
2124
"""
22-
body = _parser.unescape(body)
25+
body = unescape(body)
2326
body = re.sub(r'<a [^>]+>(.+?)</a>', r'\1', body)
2427
body = body.replace('<br>', '\n')
2528
body = re.sub(r'<.+?>', '', body)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='vichan',
20-
version='0.0.1',
20+
version='0.4.3',
2121
description=("Python vichan API Wrapper. Based on BASC-py4chan by the Bbiliotheca Anonoma"),
2222
long_description=open('README.rst').read(),
2323
license=open('LICENSE').read(),

0 commit comments

Comments
 (0)