import feedparser
import os.path
from goose import Goose
import requests
import time
import codecs

def titleget(url):
	d = feedparser.parse(url)
	title = d['feed']['title']
	return title

def getlinks(url):
	'''
	Function is used to get all the links of the feed selected.
	'''
	d = feedparser.parse(url)
	entries = []
	for post in d.entries:
		entries.append(post.link)
	return entries

def extractarticle(url):
	'''
	Function is used to get the text, image, meta and title keywords of the article.
	'''
	g = Goose()
	article = g.extract(url=url)
	title = article.title
	text = article.cleaned_text
	meta = article.meta_keywords
	image = article.top_image.src

	return text, meta, image, title  # return text from the article

textopen = open("feedsurl.txt", "rb")  # open the txt file which contains the links
feedsurl = []
feeds = {}
for feed in textopen:  # loop to get all feeds url
	feedsurl.append(feed)

counter = 1
alltitles = []
print ""  # Blank lines
for titles in feedsurl:
	alltitles.append(titleget(titles))
	print str(counter) + ". "+titleget(titles)
	counter += 1
print ""  # Blank lines

num = int(raw_input("Enter the number of feed for which new articles are need to checked : "))

allentries = getlinks(feedsurl[num-1])

redirecturls = []  # dictionary for redirected urls

for entry in allentries:  # this is used to get all the urls for splitting
	response = requests.get(entry)
	redirecturls.append(response.text.partition("URL='")[-1].rpartition("'\"")[0])  # to get the redirected URL. A proper funtioning is not present

for a in redirecturls:
	if not os.path.exists(alltitles[num-1]):  # make a new directory for the feed if doesn't exist already
		os.makedirs(alltitles[num-1])
		print "Directory created : " + alltitles[num-1]
	text, meta, aimage, title = extractarticle(a)
	namefile = str(title).replace("?", "").replace("\"", "").replace(":", "")+".txt"
	if os.path.isfile(os.getcwd()+'\\'+alltitles[num-1]+'\\'+namefile+".txt") == False:  # check if the file is present
		newfile = codecs.open(os.path.join(os.getcwd()+'\\'+alltitles[num-1], namefile+".txt"), "w", encoding='utf-8')
		newfile.write("Article downloaded on : "+time.strftime("%d/%m/%Y")+"\n\n")
		newfile.write("-"*40+"\n\n")
		newfile.write(title+"\n\n")
		if aimage is not None:
			newfile.write(aimage+"\n\n")
		newfile.write(text+"\n\n")
		newfile.write("-"*40+"\n\n")
		newfile.write("Tags : "+meta)
		newfile.write('\nSource : '+a)  # to get the source where the article was found
		newfile.close()
		print "Article : " + title.encode('utf-8') + "; Downloaded"
	else:
		print "Article : " + title + "; Already Present"
Fixed Bugs