

import requests
from bs4 import BeautifulSoup

CRICINFO_RSS_URL = 'http://static.cricinfo.com/rss/livescores.xml'

# Fetching matches
def get_matches():
	r = requests.get(CRICINFO_RSS_URL)
	soup = BeautifulSoup(r.text)
	return soup.find_all('item')
	
matches = get_matches()
for match in matches:
	print match.contents['title']
	print match.contents['description']
	print match.contents['link']



import requests
from bs4 import BeautifulSoup
import xmltodict
import click

CRICINFO_RSS_URL = 'http://static.cricinfo.com/rss/livescores.xml'

class Match(object):

	def __init__(self, title, link, description, guid):
		self.title = title
		self.link = link
		self.description = description
		self.guid = guid
	
	@staticmethod
	def from_xml(xml):
		item = xmltodict.parse(xml)['item']
		return Match(item['title'], item['link'], item['description'], item['guid'])
		
	def __repr__(self):
		return self.title

def get_matches():
	"""Fetches matches from the cricinfo url"""
	
	r = requests.get(CRICINFO_RSS_URL)
	soup = BeautifulSoup(r.text)
	for match in soup.find_all('item'):
		yield Match.from_xml(str(match))
	
def print_posts(matches):
  """Prints all matches to the console."""

  click.echo()
  for match in matches:
    click.secho('%s\t' % match.title, bold=True, fg="red", nl=False)
    click.echo()

@click.command()
def main():
  """A cli to Cricinfo to see live scores"""
  
  # fetch matches
  matches = get_matches()
  # print matches
  print_posts(matches)

if __name__ == '__main__':
  main()
Add fetching live scores feature
Add fetching live scores feature

  
  
  import requests
  from bs4 import BeautifulSoup
+ import xmltodict
+ import click
  
  CRICINFO_RSS_URL = 'http://static.cricinfo.com/rss/livescores.xml'
  
- # Fetching matches
+ class Match(object):
+ 
+ 	def __init__(self, title, link, description, guid):
+ 		self.title = title
+ 		self.link = link
+ 		self.description = description
+ 		self.guid = guid
+ 	
+ 	@staticmethod
+ 	def from_xml(xml):
+ 		item = xmltodict.parse(xml)['item']
+ 		return Match(item['title'], item['link'], item['description'], item['guid'])
+ 		
+ 	def __repr__(self):
+ 		return self.title
+ 
  def get_matches():
+ 	"""Fetches matches from the cricinfo url"""
+ 	
  	r = requests.get(CRICINFO_RSS_URL)
  	soup = BeautifulSoup(r.text)
- 	return soup.find_all('item')
+ 	for match in soup.find_all('item'):
+ 		yield Match.from_xml(str(match))
  	
+ def print_posts(matches):
+   """Prints all matches to the console."""
- matches = get_matches()
- for match in matches:
- 	print match.contents['title']
- 	print match.contents['description']
- 	print match.contents['link']
  
+   click.echo()
+   for match in matches:
+     click.secho('%s\t' % match.title, bold=True, fg="red", nl=False)
+     click.echo()
+ 
+ @click.command()
+ def main():
+   """A cli to Cricinfo to see live scores"""
+   
+   # fetch matches
+   matches = get_matches()
+   # print matches
+   print_posts(matches)
+ 
+ if __name__ == '__main__':
+   main()
Add fetching live scores feature
## Code Before:


import requests
from bs4 import BeautifulSoup

CRICINFO_RSS_URL = 'http://static.cricinfo.com/rss/livescores.xml'

# Fetching matches
def get_matches():
	r = requests.get(CRICINFO_RSS_URL)
	soup = BeautifulSoup(r.text)
	return soup.find_all('item')
	
matches = get_matches()
for match in matches:
	print match.contents['title']
	print match.contents['description']
	print match.contents['link']

## Instruction:
Add fetching live scores feature
## Code After:


import requests
from bs4 import BeautifulSoup
import xmltodict
import click

CRICINFO_RSS_URL = 'http://static.cricinfo.com/rss/livescores.xml'

class Match(object):

	def __init__(self, title, link, description, guid):
		self.title = title
		self.link = link
		self.description = description
		self.guid = guid
	
	@staticmethod
	def from_xml(xml):
		item = xmltodict.parse(xml)['item']
		return Match(item['title'], item['link'], item['description'], item['guid'])
		
	def __repr__(self):
		return self.title

def get_matches():
	"""Fetches matches from the cricinfo url"""
	
	r = requests.get(CRICINFO_RSS_URL)
	soup = BeautifulSoup(r.text)
	for match in soup.find_all('item'):
		yield Match.from_xml(str(match))
	
def print_posts(matches):
  """Prints all matches to the console."""

  click.echo()
  for match in matches:
    click.secho('%s\t' % match.title, bold=True, fg="red", nl=False)
    click.echo()

@click.command()
def main():
  """A cli to Cricinfo to see live scores"""
  
  # fetch matches
  matches = get_matches()
  # print matches
  print_posts(matches)

if __name__ == '__main__':
  main()