Skip to content

Instantly share code, notes, and snippets.

@mango314
Last active December 11, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mango314/4560320 to your computer and use it in GitHub Desktop.
Save mango314/4560320 to your computer and use it in GitHub Desktop.
A new quiz generator
import urllib, nltk, sendgrid
from BeautifulSoup import BeautifulStoneSoup
def parse(x):
if(x[1] == 'NNS'):
y = '___'
else:
y = x[0]
return y
world = 'http://feeds.bbci.co.uk/news/world/rss.xml'
politics = 'http://feeds.bbci.co.uk/news/politics/rss.xml'
science = 'http://feeds.bbci.co.uk/news/science_and_environment/rss.xml'
url = {'world': world, 'politics':politics, 'science':science }
def quiz(url):
xml = urllib.urlopen(url).read()
soup = BeautifulStoneSoup(xml)
articles = soup.findAll('item')
html = '<span style="font:courier;">'
for x in articles[:10]:
html += '<h3>%s</h3><p>%s</p>'%(x.title.text,''.join([parse(y)+' ' for y in nltk.pos_tag(nltk.word_tokenize(x.description.text))[:-1]])+'.')
#print nltk.pos_tag(nltk.word_tokenize(x.description.text))
html += '<p><a href="%s">Answers</a></p>'%(url)
html += '</span>'
# make a secure connection to SendGrid
s = sendgrid.Sendgrid('username', 'password', secure=True)
# make a message object
message = sendgrid.Message("me@fmail.com", "BBC World News Quiz", None,html)
# add a recipient
message.add_to("you@hmail.com", "Jada Lopez")
# use the Web API to send your message
s.web.send(message)
return html
if __name__ == "__main__":
quiz(science)

Algeria military operation 'over'

An Algerian military raid to free ___ at a desert gas plant is over , Algeria 's state news agency says , with a number of ___ reported killed in the operation .

'Lavish profit' from match-fixing

Match-fixing in football now generates ___ of ___ of ___ per year - ___ comparable to big multinational ___ , Interpol warns .

Regulators ground all Boeing 787s

US aviation ___ order the country 's ___ to ground Boeing 's 787 Dreamliner , after a battery fault on one of the aircraft in Japan .

Pakistan deal on cleric protest

The Pakistani government reaches a deal with cleric Tahirul Qadri to end his mass protest , agreeing to dissolve the National Assembly before its term ___ .

France boosts Mali troop numbers

France ___ its troop strength in Mali to 1,400 to help fight militant ___ in the north , the French defence minister says .

Delhi rape case is fast-tracked

The Delhi gang rape case , which has shocked India and sparked a debate about its treatment of ___ , is moved to a fast-track court for trial .

Kurds mass for PKK women funerals

___ in south-east Turkey pour onto the ___ for the ___ of three Kurdish ___ killed in Paris .

Pakistan in Kashmir talks offer

Pakistan 's foreign minister calls for ___ with her Indian counterpart to defuse military ___ in Kashmir .

Iraq bombings hit Shia pilgrims

A series of bomb ___ across Iraq has killed at least 12 ___ , most of them Shia pilgrims , ___ say .

French agent 'killed in Somalia'

Somali Islamist group al-Shabab says it has killed French intelligence agent Denis Allex in retaliation for a failed French operation to free him .

Answers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment