Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import urlparse
- import feedparser
- import MySQLdb as mdb
- import re
- import time
- # DATABASE VARS
- """***************"""
- HOST = 'nsa.gov'
- USER = 'root'
- PASSWORD = 'god'
- DATABASE = 'NSA'
- """****************"""
- con = mdb.connect(HOST, USER, PASSWORD, DATABASE);
- with con:
- feeds = []
- cur = con.cursor()
- cur.execute("SELECT * FROM feeds")
- rows = cur.fetchall()
- for row in rows:
- feeds.append(row[1])
- Errors = []
- Invalid = []
- Passed = []
- for this in feeds:
- localTime = time.ctime()
- Today = localTime.split(" ")[0], localTime.split(" ")[1], int(localTime.split(" ")[3])
- try:
- SummaryLengths = []
- DescriptionLengths = []
- Feed = feedparser.parse(this)
- if len(Feed) >0:
- FeedTitle = Feed['feed']['title']
- Entries = Feed['entries']
- if len(Entries) > 0:
- Article = Entries[0]
- Published = Entries[0]['published']
- WeekDay = re.sub(',','',Published.split(" ")[0])
- Day = re.sub(',','',Published.split(" ")[1])
- Month = re.sub(',','',Published.split(" ")[2])
- FeedDate = str(WeekDay), str(Month), int(Day)
- if FeedDate and FeedDate == Today and Article:
- ArticleTitle = Article['title']
- ArticleSummary = Article['summary']
- ArticleDescription = Article['description']
- SummaryLengths.append(len(ArticleSummary))
- DescriptionLengths.append(len(ArticleDescription))
- print str(FeedDate)
- print str(Today)
- print "Average Summary Length %d" % (sum(SummaryLengths) / len(SummaryLengths))
- print "Average Description Length Length %d" % (sum(DescriptionLengths) / len(DescriptionLengths))
- except Exception as error:
- Errors.append(error)
- Invalid.append(this)
- print "%d Errors" % (len(Errors))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement