I have a python program that downloads article text and then turns it into a txt file. The program currently spits out the txt files in the directory the program is located in. I would like to arrange this text in folders specific to the news source they came from. Could I save the data in the folder in the python program itself and change the directory as the news source file changes? Or should I create a shell script that runs the python program inside the folder it needs to be in? Or is there a better way to sort these files that I am missing?
Here is the code of the Python program:
import feedparser from goose import Goose import urllib2 import codecs url = "http://rss.cnn.com/rss/cnn_tech.rss" feed = feedparser.parse(url) g = Goose() entryLength = len(feed['entries']) count = 0 while True: article = g.extract(feed.entries[count]['link']) title = article.title text = article.cleaned_text file = codecs.open(feed['entries'][count]['title'] + ".txt", 'w', encoding = 'utf-8') file.write(text) file.close() count = count + 1 if count == entryLength: break