Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/news-updater.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-04-16 10:05:22 +0300
committerBernhard Posselt <dev@bernhard-posselt.com>2016-04-16 10:05:34 +0300
commit6cbf90a6a3106a56219c05589a1a57b91efa7db5 (patch)
tree154719a32189318136df2c0db27e37eaa5622783
parent3c7c38ba2fedfed1ab43c3f6e749e3df9bfbd965 (diff)
Get rid of python-requests8.3.0
-rw-r--r--CHANGELOG.rst6
-rw-r--r--README.rst22
-rw-r--r--owncloud_news_updater/http.py17
-rw-r--r--owncloud_news_updater/updater.py21
-rw-r--r--owncloud_news_updater/version.txt2
-rw-r--r--requirements.txt1
-rw-r--r--setup.py5
7 files changed, 34 insertions, 40 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 1541b0a..191ba99 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,6 +2,12 @@
Changelog
---------
+8.3.0
++++++
+
+**Improvements**
+
+- Get rid of the python-requests dependency. The library now needs zero dependencies and can be used very easily.
8.2.6
+++++
diff --git a/README.rst b/README.rst
index e8b5b5a..5f60b16 100644
--- a/README.rst
+++ b/README.rst
@@ -24,7 +24,7 @@ Dependencies
------------
* **Python >=3.2**
-* **requests**
+
Pre-Installation
----------------
@@ -87,17 +87,9 @@ To uninstall the updater run::
No Installation
~~~~~~~~~~~~~~~
-If you do not want to install the script at all you can call it directly. This
-however requires the requests module to be installed. To do that
-either get the package from your distro or use pip to install it. On Ubuntu this would be::
-
- sudo apt-get install python3-requests
-
-or via pip::
+If you do not want to install the script at all you can call it directly.
- sudo pip3 install -r requirements.txt
-
-Then run the updater using::
+Simply run the updater using::
python3 -m owncloud_news_updater /path/to/owncloud
@@ -233,15 +225,9 @@ user, but again, that might vary depending on your distribution.
Self Signed Certificates
------------------------
-Should you use a self signed certificate over SSL, first consider getting a
-free valid cert signed from
+Should you use a self signed certificate over SSL, consider getting a free valid cert signed from:
* `Lets Encrypt <https://letsencrypt.org/>`_
* `StartSSL <https://www.startssl.com/>`_
* `WoSign <https://www.wosign.com/english/>`_
-If you don't want to get a valid certificate, you need to add it to the installed certs::
-
- cat /path/to/your/cert/cacert.pem >> /usr/local/lib/python3.X/dist-packages/requests/cacert.pem
-
-The directories might vary depending on your distribution and Python version.
diff --git a/owncloud_news_updater/http.py b/owncloud_news_updater/http.py
new file mode 100644
index 0000000..0f556ca
--- /dev/null
+++ b/owncloud_news_updater/http.py
@@ -0,0 +1,17 @@
+import urllib.request
+import base64
+
+def create_basic_auth(user, password):
+ auth = bytes(user + ':' + password, 'utf-8')
+ return 'Basic ' + base64.b64encode(auth).decode('utf-8')
+
+def http_get(url, auth, timeout=5*60):
+ """
+ Small wrapper for getting rid of the requests library
+ """
+ auth_header = create_basic_auth(auth[0], auth[1])
+ req = urllib.request.Request(url)
+ req.add_header('Authorization', auth_header)
+ response = urllib.request.urlopen(req, timeout=timeout)
+ return response.read().decode('utf8')
+
diff --git a/owncloud_news_updater/updater.py b/owncloud_news_updater/updater.py
index d2a36de..5179c53 100644
--- a/owncloud_news_updater/updater.py
+++ b/owncloud_news_updater/updater.py
@@ -3,18 +3,12 @@ import sys
import traceback
import json
import threading
-import requests
import time
import logging
import urllib.parse
from subprocess import check_output
-
-def check_status_code(response):
- if response.status_code != 200:
- raise Exception('Request failed with %i: %s' % (response.status_code,
- response.text))
-
+from owncloud_news_updater.http import http_get
class Updater:
def __init__(self, thread_num, interval, run_once, log_level):
@@ -130,25 +124,21 @@ class WebUpdater(Updater):
def before_update(self):
self.logger.info(
'Calling before update url: %s' % self.before_cleanup_url)
- before = requests.get(self.before_cleanup_url, auth=self.auth)
- check_status_code(before)
+ before = http_get(self.before_cleanup_url, auth=self.auth)
def start_update_thread(self, feeds):
return WebUpdateThread(feeds, self.logger, self.update_url, self.auth,
self.timeout)
def all_feeds(self):
- feeds_response = requests.get(self.all_feeds_url, auth=self.auth)
- check_status_code(feeds_response)
- feeds_json = feeds_response.text
+ feeds_json = http_get(self.all_feeds_url, auth=self.auth)
self.logger.info('Received these feeds to update: %s' % feeds_json)
return json.loads(feeds_json)['feeds']
def after_update(self):
self.logger.info(
'Calling after update url: %s' % self.after_cleanup_url)
- after = requests.get(self.after_cleanup_url, auth=self.auth)
- check_status_code(after)
+ after = http_get(self.after_cleanup_url, auth=self.auth)
class WebUpdateThread(UpdateThread):
@@ -166,8 +156,7 @@ class WebUpdateThread(UpdateThread):
# turn the pyton dict into url parameters
data = urllib.parse.urlencode(feed)
url = '%s?%s' % (self.update_url, data)
- request = requests.get(url, auth=self.auth, timeout=self.timeout)
- check_status_code(request)
+ request = http_get(url, auth=self.auth, timeout=self.timeout)
class ConsoleUpdater(Updater):
diff --git a/owncloud_news_updater/version.txt b/owncloud_news_updater/version.txt
index bcd9546..9f4a0fb 100644
--- a/owncloud_news_updater/version.txt
+++ b/owncloud_news_updater/version.txt
@@ -1 +1 @@
-8.2.6 \ No newline at end of file
+8.3.0 \ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index f229360..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-requests
diff --git a/setup.py b/setup.py
index ffc56b6..eebf0e9 100644
--- a/setup.py
+++ b/setup.py
@@ -6,9 +6,6 @@ if version_info < (3, 2):
print('Error: Python 3.2 required but found %s' % python_version())
exit(1)
-with open('requirements.txt', 'r') as infile:
- install_requires = infile.read().split('\n')
-
with open('README.rst', 'r') as infile:
long_description = infile.read()
@@ -26,7 +23,7 @@ setup(
packages=find_packages(),
include_package_data=True,
license='GPL',
- install_requires=install_requires,
+ install_requires=[],
keywords=['owncloud', 'news', 'updater', 'RSS', 'Atom', 'feed', 'reader'],
classifiers=[
'Intended Audience :: System Administrators',