LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Arch
User Name
Password
Arch This Forum is for the discussion of Arch Linux.

Notices


Reply
  Search this Thread
Old 01-07-2021, 03:20 PM   #1
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Read the arch news before Updating.


This will run from tty, in case you are X/wayland broken, or running without GUI.

Only needs python3, urllib and xml.etree
Code:
#!/usr/bin/python

#Get the Arch Latest News

from xml.etree import ElementTree
from urllib import request
import re

#Make a user agent string for urllib to use
agent = ('Mozilla/5.0 (Windows NT 10.1; Win64; x64; rv:82.0) '
        'Gecko/20100101 Firefox/82.0')
        
user_agent = {'User-Agent': agent}

class MakeList():
    def __init__(self, url, fname):
    
        #Get the xml to parse
        req = request.Request(url, data=None, headers=user_agent)
        html = request.urlopen(req)
        tree = ElementTree.parse(html)
        root = tree.getroot()
        
        #Get tag data
        tagA = root.findall('./channel/item/title')
        tagB = root.findall('./channel/item/link')
        tagC = root.findall('./channel/item/description')
        tagD = []
        
        #Append lines with separator
        for a,b,c in zip(tagA,tagB,tagC):
            tagD.extend([a.text, b.text, c.text, '_' * 70])
       
        #Print and Write list to file
        with open(fname, 'a') as f:
           for line in tagD:
                print('%s\n' % re.sub('<[^>]*>', '', line))
                f.write('%s\n\n' % re.sub('<[^>]*>', '', line))
                
if __name__ == "__main__":
    
    #Urls, log names
    A = ('https://archlinux.org/feeds/news/', 'Arch_RSS.log')
        
    B = ('file:///local/file/archfeed.xml', 'test.log')
    
    #Choose RSS feed here
    url, fname = A

    MakeList(url, fname)
 
Old 01-08-2021, 08:22 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by teckk View Post
Code:
from xml.etree import ElementTree
I'd replace that line with this:
Code:
try:
    from lxml import etree
    print('Running with lxml.etree')
except:
    try:
        import xml.etree.ElementTree as etree
        print('Running with ElementTree')
    except:
        print('Failed to import ElementTree')
...
Code:
        tree = etree.parse(html)
But actually, I'd rather parse an RSS feed with Xidel:
Code:
#!/bin/bash

url='https://archlinux.org/feeds/news'
cols=${COLUMNS:-70}

line(){ l={1..$cols};eval printf -- $1%.0s $l;echo;}

eval $(xidel --output-format=bash -s "$url" 2>/dev/null \
  -e 'title:=//title' -e 'link:=//link' -e 'desc:=//description')

for (( i=0; i<${#title[@]}; i++ ))
do
  line '='
  echo "${title[$i]}"
  echo "${link[$i]}"
  line '-'
  echo "${desc[$i]}"|html2text -b$cols
done
or just read it in something like Newsboat or Canto.

Last edited by shruggy; 01-10-2021 at 07:27 AM.
 
Old 01-08-2021, 01:58 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Or use informant as a pacman hook.
Or one of those AUR/pacman helpers that also check the news for you.
 
Old 01-24-2021, 05:25 AM   #4
hish2021
Member
 
Registered: Jan 2021
Posts: 117

Rep: Reputation: Disabled
This alias works for me, for now:
Code:
alias syu='w3m -dump https://www.archlinux.org/news/ | grep -A1 Published && sudo pacman -Syu'
 
  


Reply

Tags
xml



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
New installs, read the Arch news. teckk Arch 3 10-14-2019 08:30 AM
LXer: Latest Cinnamon Release Lands in Antergos, but Read This Before Updating Python LXer Syndicated Linux News 0 01-08-2017 11:54 PM
LXer: Read This Article Before Updating Your Arch Linux LXer Syndicated Linux News 1 06-04-2013 06:28 AM
Arch user wanted to help padawan learner install arch and use it thomas-linuxing Linux - Software 9 10-18-2006 04:02 PM
The strange 'News Importante: Read this before posting!' ruiP *BSD 2 07-06-2005 10:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Arch

All times are GMT -5. The time now is 01:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration