Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

desktop notifier in python

import requests
import xml.etree.ElementTree as ET
  
# url of news rss feed
RSS_FEED_URL = "http://www.hindustantimes.com/rss/topnews/rssfeed.xml"    
  
def loadRSS():
    '''
    utility function to load RSS feed
    '''
    # create HTTP request response object
    resp = requests.get(RSS_FEED_URL)
  
    # return response content
    return resp.content
  
def parseXML(rss):
    '''
    utility function to parse XML format rss feed
    '''
    # create element tree root object
    root = ET.fromstring(rss)
  
    # create empty list for news items
    newsitems = []
  
    # iterate news items
    for item in root.findall('./channel/item'):
        news = {}
  
        # iterate child elements of item
        for child in item:
  
            # special checking for namespace object content:media
            if child.tag == '{http://search.yahoo.com/mrss/}content':
                news['media'] = child.attrib['url']
            else:
                news[child.tag] = child.text.encode('utf8')
        newsitems.append(news)
  
    # return news items list
    return newsitems
  
def topStories():
    '''
    main function to generate and return news items
    '''
    # load rss feed
    rss = loadRSS()
  
    # parse XML
    newsitems = parseXML(rss)
    return newsitems
Comment

PREVIOUS NEXT
Code Example
Python :: python recursion example 
Python :: python string lenght 
Python :: defaultdict item count 
Python :: pyttsx3 saving the word to speak 
Python :: how to pass multiple parameters by 1 arguments in python 
Python :: nrf24l01 arduino to raspberry pi struct 
Python :: swapping upper case and lower case string python 
Python :: circular dependencies in python 
Python :: dependency injection python 
Python :: find index of value in list python 
Python :: convert hex rgb to matplotlib color 
Python :: python re.sub() 
Python :: list slice in python 
Python :: python index for all matches 
Python :: make button in tk 
Python :: if statement python explained 
Python :: install pyimagesearch python3 
Python :: anonymous function python 
Python :: drop row pandas column value not a number 
Python :: polymorphism in python 
Python :: giving number of letter in python 
Python :: how to import data in python 
Python :: how to find the last occurrence of a character in a string in python 
Python :: add header info in django response 
Python :: python remove the element in list 
Python :: change the format of date in python 
Python :: pandas take entries from other column if column is nan 
Python :: python ravel function 
Python :: python struct 
Python :: install python anaconda 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =