Jump to content
LuckyEgg

[Python] Get Rst News

Recommended Posts

  • Active Members
Posted

Mi-am aruncat si eu un ochi repede. Nu am testat:

 

import requests
from lxml import html
from gi.repository import Notify, GdkPixbuf
from time import sleep

s = requests.session()


def get_news():
    """
    Return the last topic
    """
    page = s.get("https://rstforums.com")
    tree = html.fromstring(page.content)
    subject = tree.xpath('//a[@class="postTitle"]/text()')
    title = tree.xpath('//span[@class="author"]/text()')
    topic = "Subject: {0} -- Posted by: {1}".format(subject[0], title[0])
    
    return topic


def get_notification(x):
    """
    Show notification
    """
    Notify.init("RST News")
    notification = Notify.Notification.new("New post on rstforums.com!", x)
    image = GdkPixbuf.Pixbuf.new_from_file("rst.png")
    notification.set_icon_from_pixbuf(image)
    notification.set_image_from_pixbuf(image)
    notification.show()



def main():
    last_new = []
    while True:
        try:
            last_message = get_news()
        except:
            print("error - ce error ? tre' sa ghicesc ?\n")
            continue
        if last_message != last_new:
            last_new = last_message
            get_notification(last_message)
            sleep(3)


if __name__ == '__main__':
    main()

- calea catre imagine as pune-o ca argument

- ce ofera nou asta spre deosebire de un feed ?

 

Spor in continuare, e un inceput bun :)

 

Citeste PEP8 !

Posted

Nu ofera prea multe.. dar l-am facut sa vad daca il pot face si daca ma descurc.

Cine primeste eroarea

"DBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name :1.221 was not provided by any .service files" 

sa deie

sudo apt-get install libnotify-cil-dev

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...