Skip to content

Commit f4b6002

Browse files
committed
Removed dependency on MechanicalSoup (solves #47)
1 parent ab74c9d commit f4b6002

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ Pycaching has following requirements:
4646
.. code::
4747
4848
Python>=3.4
49-
MechanicalSoup>=0.3.0
50-
geopy>=1.0.0
49+
requests >= 2.8
50+
beautifulsoup4 >= 4.4
51+
geopy>=1.11
5152
5253
5354
-------------

pycaching/geo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def _download_utfgrid(self, *, get_png=False):
312312
def load(self):
313313
"""Parse cache coordinates from UTFGrid
314314
315-
Consume json-decoded UTFGrid data from MechanicalSoup browser.
315+
Consume json-decoded UTFGrid data from browser.
316316
Calculate waypoint coordinates and fill caches' location.
317317
318318
Geocaching.com UTFGrids do not follow UTFGrid specification [2]

pycaching/geocaching.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env python3
22

33
import logging
4-
import requests
54
import datetime
5+
import requests
6+
import bs4
67
from urllib.parse import urljoin
7-
from mechanicalsoup import Browser
8-
from bs4 import BeautifulSoup
98
from pycaching.cache import Cache, Type, Size
109
from pycaching.log import Log, Type as LogType
1110
from pycaching.geo import Point
@@ -25,7 +24,7 @@ class Geocaching(object):
2524

2625
def __init__(self):
2726
self._logged_in = False
28-
self._browser = Browser()
27+
self._session = requests.Session()
2928

3029
def _request(self, url, *, expect="soup", method="GET", login_check=True, **kwargs):
3130
# check login unless explicitly turned off
@@ -35,12 +34,12 @@ def _request(self, url, *, expect="soup", method="GET", login_check=True, **kwar
3534
url = url if "//" in url else urljoin(self._baseurl, url)
3635

3736
try:
38-
res = self._browser.request(method, url, **kwargs)
37+
res = self._session.request(method, url, **kwargs)
3938
res.raise_for_status()
4039

4140
# return bs4.BeautifulSoup, JSON dict or raw requests.Response
4241
if expect == "soup":
43-
return res.soup
42+
return bs4.BeautifulSoup(res.text, "html.parser")
4443
elif expect == "json":
4544
return res.json()
4645
elif expect == "raw":
@@ -99,17 +98,17 @@ def login(self, username, password):
9998
def logout(self):
10099
"""Logs out the user.
101100
102-
Logs out the user by creating new browser."""
101+
Logs out the user by creating new session."""
103102

104103
logging.info("Logging out.")
105104
self._logged_in = False
106-
self._browser = Browser()
105+
self._session = requests.Session()
107106

108107
def get_logged_user(self, login_page=None):
109108
"""Returns the name of curently logged user or None, if no user is logged in."""
110109

111110
login_page = login_page or self._request(self._urls["login_page"], login_check=False)
112-
assert isinstance(login_page, BeautifulSoup)
111+
assert isinstance(login_page, bs4.BeautifulSoup)
113112

114113
logging.debug("Checking for already logged user.")
115114
try:
@@ -193,7 +192,7 @@ def _search_get_page(self, point, start_index):
193192
"originTreatment": 0
194193
}, expect="json")
195194

196-
return BeautifulSoup(res["HtmlString"].strip())
195+
return bs4.BeautifulSoup(res["HtmlString"].strip(), "html.parser")
197196

198197
def search_quick(self, area, *, strict=False, zoom=None):
199198
logging.info("Searching quick in {}".format(area))
@@ -228,7 +227,8 @@ def post_log(self, wp, text, type=LogType.found_it, date=datetime.date.today()):
228227
l = Log(type=type, text=text, visited=date)
229228
self.get_cache(wp).post_log(l)
230229

231-
# ensure backwards compatibility -----------------------------------------
230+
# ensure backwards compatibility ------------------------------------------
231+
# deprecated methods will be removed in next version!
232232

233233
@deprecated
234234
def load_cache(self, wp):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
info = {
1111
"name": "pycaching",
12-
"version": "3.3", # PEP 386
12+
"version": "3.3.1", # PEP 386
1313
"author": "Tomas Bedrich",
1414
"author_email": "[email protected]",
1515
"url": "https://github.com/tomasbedrich/pycaching",
@@ -19,7 +19,7 @@
1919
"description": "Geocaching.com site crawler. Provides tools for searching, fetching caches and geocoding.",
2020
"long_description": long_description,
2121
"keywords": ["geocaching", "crawler", "geocache", "cache", "search", "geocode", "travelbug"],
22-
"install_requires": ["MechanicalSoup >= 0.3.0", "geopy >= 1.0.0"],
22+
"install_requires": ["requests >= 2.8", "beautifulsoup4 >= 4.4", "geopy >= 1.11"],
2323
"test_suite": "test"
2424
}
2525

0 commit comments

Comments
 (0)