• Stars
    star
    100
  • Rank 328,770 (Top 7 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“ฐ Fast, parallel feed updater for the News app; written in Python

Nextcloud News Updater

https://travis-ci.org/nextcloud/news-updater.svg?branch=master

This Python library is a parallel feed updater for the Nextcloud News app

Nextcloud does not require people to install threading or multiprocessing libraries. Because the feed update process is mainly limited by I/O, parallel fetching of RSS feed updates can speed up the updating process significantly.

In addition, Web Cron is not a supported cron setting since the update process may time out.

Therefore the News app provides an API that offers a more fine grained control over updating feeds. This Python project implements an update mechanism that is based on the updater REST API or (new in Nextcloud News 8.1.0) the console based update API.

Dependencies

  • Python >=3.5

Pre-Installation

To run the updates via an external threaded script the cron updater has to be disabled. To do that go to the admin section an uncheck the Use Nextcloud cron checkbox or open nextcloud/data/news/config/config.ini and set:

useCronUpdates = true

to:

useCronUpdates = false

Installation

There are two different ways to install the updater:

  • Installation using pip (recommended)
  • Manual installation
  • No installation

Installation Using Pip

Since 8.2 the package is available on pypi for installation via pip (the Python library package manager).

To install pip on your distribution of choice, consolidate the pip documentation

Note: You need to install the Python 3 version of pip

After installing pip, run:

sudo pip3 install nextcloud_news_updater

To update the library, run:

sudo pip3 install --upgrade nextcloud_news_updater

To uninstall the library run:

sudo pip3 uninstall nextcloud_news_updater

Manual Installation

If you don't want to install the updater via pip, you can install it manually. This requires setuptools to be installed. On Ubuntu this can be done by running:

sudo apt-get install python3-setuptools

Then install the package like this:

python3 setup.py install --install-scripts=/usr/bin

To uninstall the updater run:

python3 setup.py uninstall

No Installation

If you do not want to install the script at all you can call it directly.

Simply run the updater using:

python3 -m nextcloud_news_updater /path/to/nextcloud

Usage

There are two ways to run the updater:

  • Using the console API (recommended):

    nextcloud-news-updater /path/to/nextcloud
    
  • Using the REST API (when running the updater on a different machine than Nextcloud):

    nextcloud-news-updater https://domain.com/path/to/nextcloud --user admin_user --password admin_password
    

Note: admin_user is a user id with admin rights, admin_password the user's password

You can view all options by running:

nextcloud-news-updater --help
usage: __main__.py [-h] [--threads THREADS] [--timeout TIMEOUT]
                   [--interval INTERVAL] [--apilevel {v1-2,v2,v15}]
                   [--loglevel {info,error}] [--config CONFIG]
                   [--phpini PHPINI] [--user USER] [--password PASSWORD]
                   [--version] [--mode {endless,singlerun}] [--php PHP]
                   [url]

positional arguments:
  url                   The URL or absolute path to the directory where
                        Nextcloud is installed. Must be specified on the
                        command line or in the config file. If the URL starts
                        with http:// or https://, a user and password are
                        required. Otherwise the updater tries to use the
                        console based API which was added in 8.1.0

optional arguments:
  -h, --help            show this help message and exit
  --threads THREADS, -t THREADS
                        How many feeds should be fetched in parallel, defaults
                        to 10
  --timeout TIMEOUT, -s TIMEOUT
                        Maximum number of seconds for updating a feed,
                        defaults to 5 minutes
  --interval INTERVAL, -i INTERVAL
                        Update interval between fetching the next round of
                        updates in seconds, defaults to 15 minutes. The update
                        timespan will be subtracted from the interval.
  --apilevel {v1-2,v2,v15}, -a {v1-2,v2,v15}
                        API level. Use v15 for News 15 or later, or v1-2 for
                        releases prior to that
  --loglevel {info,error}, -l {info,error}
                        Log granularity, info will log all urls and received
                        data, error will only log errors
  --config CONFIG, -c CONFIG
                        Path to config file where all parameters except can be
                        defined as key values pair. See the README.rst for
                        more information
  --phpini PHPINI, -P PHPINI
                        Custom absolute path to the php.ini file to use for
                        the command line updater. If omitted, the default one
                        will be used
  --user USER, -u USER  Admin username to log into Nextcloud. Must be
                        specified on the command line or in the config file if
                        the updater should update over HTTP
  --password PASSWORD, -p PASSWORD
                        Admin password to log into Nextcloud if the updater
                        should update over HTTP
  --version, -v         Prints the updater's version
  --mode {endless,singlerun}, -m {endless,singlerun}
                        Mode to run the updater in: endless runs the update
                        again after the specified interval, singlerun only
                        executes the update once
  --php PHP             Path to the PHP binary, e.g. /usr/bin/php7.0, defaults
                        to php

You can also put your settings in a config file, looking like this:

[updater]
threads = 10
interval = 900
loglevel = error
# or https://domain.com/nextcloud when using the REST API
url = /path/to/nextcloud
# or v2 which is currently a draft
apilevel = v15
mode = endless

# The following lines are only needed when using the REST API
user = admin
password = admin

# The following lines are only needed when using the console API
# path to php binary
php = /usr/bin/php7.0
phpini = /path/to/custom/php.ini

Warning: If you use REST API with user and password assigned in the config file, you probably don't want anyone else but the file owner to see your user/password in the file. Secure it with:

chmod 600 /path/to/config

Note: You can omit options in the config file if you want to use the defaults, but you can not have more than the allowed parameters present, otherwise an exception will abort the updater.

Then run the updater with:

nextcloud-news-updater -c /path/to/config

Note: Command line parameters will always overwrite config parameters, so if you just want to change your loglevel to info for one run you can now do the following without globally changing the config file:

nextcloud-news-updater -c /path/to/config --mode singlerun --loglevel info

Running The Updater As Systemd Service

Almost always you want to run and stop the updater using your in init system. As for Systemd, you can create a simple text file at /etc/systemd/system/nextcloud-news-updater.service with the following contents:

[Unit]
After=default.target

[Service]
Type=simple
User=http
ExecStart=/usr/bin/nextcloud-news-updater -c /etc/nextcloud/news/updater.ini

[Install]
WantedBy=default.target

Then to enable and start it run:

sudo systemctl enable nextcloud-news-updater.service
sudo systemctl start nextcloud-news-updater.service

Note: If you are using the cli based updater (as in set an absolute directory as url) you need to set the web-server user as user in the unit file. Otherwise the command will fail because Nextcloud checks for the owner of its files. This user varies from distribution to distribution, e.g in Debian and Ubuntu you would use the www-data user:

[Unit]
After=default.target

[Service]
Type=simple
User=www-data
ExecStart=/usr/bin/nextcloud-news-updater -c /etc/nextcloud/news/updater.ini

[Install]
WantedBy=default.target

If you are using the REST API, most of the time you can get away by using nobody as user, but again, that might vary depending on your distribution.

Running The Updater As OpenRC Service

On Alpine/postmarketOS/Gentoo/Artix or the other OpenRC based distros, you can create a simple text file at /etc/init.d/nextcloud-news-updater with the following contents:

#!/sbin/openrc-run

description="Nextcloud News Updater Daemon"

pidfile=${pidfile:-/run/nextcloud-news-updater.pid}
output_log="/var/log/nextcloud-news-updater/output.log"
error_log="/var/log/nextcloud-news-updater/error.log"

command=${command:-/usr/bin/nextcloud-news-updater}
command_user=${command_user:-www-data:www-data}
command_args="-c /etc/nextcloud/news/updater.ini"
command_background=true

Then to enable and start it run:

sudo -u www-data mkdir /var/log/nextcloud-news-updater
sudo -u www-data touch /var/log/nextcloud-news-updater/output.log \
                       /var/log/nextcloud-news-updater/error.log
sudo chmod 755 /etc/init.d/nextcloud-news-updater
sudo rc-update add nextcloud-news-updater
sudo rc-service nextcloud-news-updater start

Troubleshooting

If you are having trouble debugging updater errors, try running it again using the info loglevel:

nextcloud-news-updater --loglevel info -c /path/to/config.ini

How Do I Enable Support For Self-Signed Certificates

If you are using self-signed certificates, don't. It's very easy to sign your cert for free from Lets Encrypt

If you still have to use a self-signed certificate no matter what, don't patch the code to turn off certificate verification but rather globally add your certificate to the trusted certificates. Read up on your distributions documentation to find out how.

Can I Run The Updater Using Cron

Yes, you can by using the --mode singlerun parameter which will exit after one full update.

However it's your job to ensure, that the job will not be executed more than once at the same time. If update jobs overlap, they can take down your system and/or server since each new updater will slow down the previous ones causing more updaters to be spawned.

If you can not ensure that the updater is run only one at a time use the default mode (--mode endless). This mode runs the update in a loop. You can control the update frequency through the --interval parameter (or interval using a config file). The updater works in the following way: * If a full update takes longer than the passed interval, another update will be run immediately afterwards * If a full update took less than the passed interval, the updater will sleep for the remaining time and run an update afterwards

Using The CLI Based Updater Fails

The updater uses the PHP executable to run the occ file inside your nextcloud directory. The general process boils down to the following:

# delete folders and feeds marked for deletion
php -f /home/bernhard/programming/core/occ news:updater:before-update

# get all feeds to udpate
php -f /home/bernhard/programming/core/occ news:updater:all-feeds

# run all feed updates
php -f /home/bernhard/programming/core/occ news:updater:update-feed FEED_ID USER_ID

# delete old articles
php -f /home/bernhard/programming/core/occ news:updater:after-update

Most of the time there are two possible points of failure that can be debugged by using the --logelevel info parameter:

  • Most distributions uses different php.ini files for your command line and web-server. This can manifest itself in weird errors like not being able to connect to the database. The solution is to either adjust php.ini used for the CLI PHP or to use a different php.ini altogether by specifying the --phpini parameter, e.g.:

    nextcloud-news-updater -c /path/to/config --phpini /etc/php/nextcloud-news-updater.ini
    
  • The news:updater:all-feeds command returns invalid JSON. This can be due to due broken or missing php.ini settings or PHP warnings/errors produced by Nextcloud. The solution to this issue can range from adjusting your php.ini (see previous point) to manually patching Nextcloud to remove the warnings from the output.

Working with Centos/RHEL

Since Centos only provides Python 3.4, you can use SoftwareCollections to install a newer Python version.

For example Python 3.5: https://www.softwarecollections.org/en/scls/rhscl/rh-python35/

# 1. Install the Software Collection Repository
$ sudo yum install centos-release-scl

# 2. Install the collection:
$ sudo yum install rh-python35

# 3. Start using software collections:
$ scl enable rh-python35 bash

# 4. Install nextcloud-news.updater
$ sudo pip3 install nextcloud_news_updater

After the install you can run the updater as a service by extending the service file with the correct environment variable for your Python version. In this example we use Python 3.5:

[Unit]
After=default.target

[Service]
Type=simple
User=http
ExecStart=/usr/bin/nextcloud-news-updater -c /etc/nextcloud-news-updater.ini
Environment=LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64

[Install]
WantedBy=default.target

More Repositories

1

server

โ˜๏ธ Nextcloud server, a safe home for all your data
PHP
23,691
star
2

docker

โ›ด Docker image of Nextcloud
Shell
5,429
star
3

all-in-one

๐Ÿ“ฆ The official Nextcloud installation method. Provides easy deployment and maintenance with most features included in this one Nextcloud instance.
PHP
3,965
star
4

android

๐Ÿ“ฑ Nextcloud Android app
Java
3,848
star
5

desktop

๐Ÿ’ป Desktop sync client for Nextcloud
C++
2,770
star
6

nextcloudpi

๐Ÿ“ฆ Build code for NextcloudPi: Raspberry Pi, Odroid, Rock64, curl installer...
Shell
2,380
star
7

ios

๐Ÿ“ฑ Nextcloud iOS App
Swift
1,800
star
8

spreed

๐Ÿ—จ๏ธ Nextcloud Talk โ€“ chat, video & audio calls for Nextcloud
JavaScript
1,441
star
9

vm

๐Ÿ’ปโ˜๐Ÿ“ฆ The Nextcloud VM (virtual machine appliance), Home/SME Server and scripts for RPi (4). Community developed and maintained.
Shell
1,252
star
10

deck

๐Ÿ—‚ Kanban-style project & personal management tool for Nextcloud, similar to Trello
JavaScript
1,136
star
11

bookmarks

๐Ÿ”– Bookmark app for Nextcloud
JavaScript
956
star
12

notes-android

โœŽ Android client for Nextcloud Notes app.
Java
894
star
13

calendar

๐Ÿ“† Calendar app for Nextcloud
JavaScript
887
star
14

mail

๐Ÿ’Œ Mail app for Nextcloud
JavaScript
788
star
15

news

๐Ÿ“ฐ RSS/Atom feed reader
PHP
786
star
16

passman

๐Ÿ” Open source password manager with Nextcloud integration
JavaScript
769
star
17

news-android

๐Ÿ“ฑ๐Ÿ—ž๏ธ Android client for the Nextcloud news/feed reader app
Java
663
star
18

notes

โœŽ Distraction-free notes and writing
JavaScript
580
star
19

contacts

๐Ÿ“‡ Contacts app for Nextcloud
JavaScript
541
star
20

tasks

โœ… Tasks app for Nextcloud
JavaScript
536
star
21

text

๐Ÿ“‘ Collaborative document editing using Markdown
JavaScript
500
star
22

cookbook

๐Ÿฒ A library for all your recipes
HTML
492
star
23

photos

๐Ÿ“ธ Your memories under your control
JavaScript
481
star
24

maps

๐ŸŒ๐ŸŒ๐ŸŒŽ The whole world fits inside your cloud!
JavaScript
474
star
25

recognize

๐Ÿ‘ ๐Ÿ‘‚ Smart media tagging for Nextcloud: recognizes faces, objects, landscapes, music genres
PHP
470
star
26

social

๐ŸŽ‰ Social can be used for work, or to connect to the fediverse!
PHP
464
star
27

documentation

๐Ÿ“˜ Nextcloud documentation
JavaScript
464
star
28

talk-android

๐Ÿ“ฑ๐Ÿ˜€ Video & audio calls through Nextcloud on Android
Kotlin
461
star
29

previewgenerator

Nextcloud app to do preview generation in the background.
PHP
440
star
30

richdocuments

๐Ÿ“‘ Collabora Online for Nextcloud
JavaScript
336
star
31

forms

๐Ÿ“ Simple form & survey app for Nextcloud
JavaScript
301
star
32

twofactor_totp

๐Ÿ”‘ Second factor TOTP (RFC 6238) provider for Nextcloud
JavaScript
265
star
33

helm

A community maintained helm chart for deploying Nextcloud on Kubernetes.
Smarty
263
star
34

groupfolders

๐Ÿ“๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Admin-configured folders shared by everyone in a group. https://github.com/nextcloud-releases/groupfolders
PHP
262
star
35

appstore

๐Ÿช App Store for Nextcloud
Python
262
star
36

end_to_end_encryption

๐Ÿ” Server API to support End-to-End Encryption
PHP
253
star
37

polls

๐Ÿ—ณ๏ธ Polls app for Nextcloud
JavaScript
249
star
38

providers

community-maintained list of Nextcloud providers
213
star
39

nextcloud.com

๐ŸŒ Our website
PHP
207
star
40

notify_push

Update notifications for nextcloud clients
Rust
202
star
41

backup

Backup now. Restore later.
PHP
202
star
42

nextcloud-vue

๐Ÿฑ Vue.js components for Nextcloud app development โœŒ https://npmjs.org/@nextcloud/vue
Vue
198
star
43

client_theming

๐Ÿ’ป Nextcloud themed desktop client - Moved over to https://github.com/nextcloud/desktop
Shell
197
star
44

fulltextsearch

๐Ÿ” Core of the full-text search framework for Nextcloud
PHP
197
star
45

ocsms

๐Ÿ“ฑ Nextcloud/ownCloud PhoneSync server application
JavaScript
190
star
46

circles

๐Ÿ‘ช Create groups with other users on a Nextcloud instance and share with them
PHP
139
star
47

registration

User registration app for Nextcloud
JavaScript
134
star
48

ansible-collection-nextcloud-admin

The ansible galaxy for your nextcloud administrative needs.
Jinja
130
star
49

cms_pico

๐Ÿ—ƒ Integrate Pico CMS and let your users manage their own websites
PHP
127
star
50

talk-ios

๐Ÿ“ฑ๐Ÿ˜€ Video & audio calls through Nextcloud on iOS
Objective-C
123
star
51

documentserver_community

Document server for onlyoffice
PHP
122
star
52

tables

๐Ÿฑ Nextcloud tables app
JavaScript
114
star
53

twofactor_u2f

๐Ÿ”‘ U2F second factor provider for Nextcloud
JavaScript
113
star
54

passman-webextension

Webextension for the Passman Nextcloud app. Also offers browser extension & Android app.
JavaScript
111
star
55

talk-desktop

๐Ÿ’ฌ๐Ÿ’ป Nextcloud Talk Desktop Client Preview
JavaScript
110
star
56

gallery

DEPRECATED Gallery app was replaced by Photos
JavaScript
110
star
57

twofactor_gateway

๐Ÿ”‘ Second factor provider using an external messaging gateway (SMS, Telegram, Signal)
PHP
109
star
58

activity

โšก Activity app for Nextcloud
JavaScript
108
star
59

external

๐ŸŒ Embed external sites in your Nextcloud
JavaScript
104
star
60

notifications

๐Ÿ”” Notifications app for Nextcloud
PHP
102
star
61

user_external

๐Ÿ‘ฅ External user authentication methods like IMAP, SMB and FTP
PHP
101
star
62

neon

A framework for building convergent cross-platform Nextcloud clients using Flutter.
Dart
100
star
63

integration_google

๐Ÿ‡ฌ Google integration into Nextcloud
JavaScript
98
star
64

nextcloud-filelink

โœ‰๏ธ ๐Ÿ“ค "Nextcloud for Filelink" is a Thunderbird extension which makes it easy to send large attachments with Thunderbird by uploading them first to a Nextcloud server and by then inserting the link into the body of your email.
JavaScript
96
star
65

user_saml

๐Ÿ”’ App for authenticating Nextcloud users using SAML https://apps.nextcloud.com/apps/user_saml
PHP
93
star
66

files_videoplayer

๐Ÿ“ผ Old video viewer for Nextcloud
JavaScript
91
star
67

health

Nextcloud health app
JavaScript
89
star
68

passman-android

๐Ÿ”‘ Android app for Passman.
C++
89
star
69

android-library

โ˜Ž๏ธ Nextcloud Android library
Java
85
star
70

serverinfo

๐Ÿ“Š A monitoring app which creates a server info dashboard for admins
JavaScript
85
star
71

viewer

๐Ÿ–ผ Simple file viewer with slideshow for media
JavaScript
83
star
72

unsplash

๐Ÿ“ธ๐Ÿ”€โ˜๏ธ Random Nextcloud log in background from Unsplash
JavaScript
82
star
73

files_pdfviewer

๐Ÿ“– A PDF viewer for Nextcloud
JavaScript
81
star
74

suspicious_login

Detect and warn about suspicious IPs logging into Nextcloud
PHP
80
star
75

fulltextsearch_elasticsearch

๐Ÿ” Use Elasticsearch to index the content of your Nextcloud
PHP
77
star
76

files_antivirus

๐Ÿ‘พ Antivirus app for Nextcloud Files
JavaScript
74
star
77

collectives

Collectives is a Nextcloud App for activist and community projects to organize together.
JavaScript
73
star
78

Android-SingleSignOn

Single sign-on for Nextcloud (Android Library Project)
Java
70
star
79

files_texteditor

๐Ÿ“„ Text editor for plaintext files
JavaScript
69
star
80

user_oidc

OIDC connect user backend for Nextcloud
PHP
66
star
81

workflow_script

Rule based processing of files through specified external scripts
PHP
65
star
82

user_sql

๐Ÿ”’ App for authenticating Nextcloud users using SQL
PHP
65
star
83

files_rightclick

๐Ÿ‘‰ Right click menu for Nextcloud
JavaScript
64
star
84

ransomware_protection

An app that prevents uploading files that have names that are linked to known ransomware
PHP
62
star
85

windows-universal

๐Ÿ“ฑ Nextcloud Windows Mobile app
C#
58
star
86

dashboard

ARCHIVED, new Dashboard is in the server
PHP
58
star
87

security-advisories

๐Ÿ‘ฎ Security advisories of Nextcloud
PHP
55
star
88

integration_whiteboard

โœ A whiteboard for Nextcloud, using Spacedeck
PHP
53
star
89

files_automatedtagging

๐Ÿ”– An app for Nextcloud that assigns tags to newly uploaded files based on some conditions
JavaScript
53
star
90

logreader

๐Ÿ“œ Log reader for Nextcloud
JavaScript
52
star
91

calendar_resource_management

Resources back-end for the Nextcloud CalDAV server
PHP
52
star
92

impersonate

๐Ÿ‘ป Allow administrators to become a different user
JavaScript
52
star
93

cdav-library

๐Ÿ“… ๐Ÿ“‡ CalDAV and CardDAV client library for JavaScript
JavaScript
51
star
94

integration_openproject

Integration of OpenProject project manager in Nextcloud
PHP
51
star
95

3rdparty

๐Ÿ”‹ 3rd party libraries that are needed to run Nextcloud
PHP
51
star
96

files_fulltextsearch

๐Ÿ” Index the content of your files
PHP
50
star
97

files_accesscontrol

๐Ÿšซ App to manage access control for files
PHP
49
star
98

integration_github

๐Ÿ™ GitHub integration into Nextcloud
JavaScript
49
star
99

strengthify

๐Ÿ”’๐Ÿ” Combine jQuery and zxcvbn to create a password strength meter
JavaScript
49
star
100

bruteforcesettings

๐Ÿ•ต Allow admins to configure the brute force settings
JavaScript
48
star