Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import urlparse
  4. import feedparser
  5. import MySQLdb as mdb
  6. import re
  7. import time
  8.  
  9. # DATABASE VARS
  10. """***************"""
  11. HOST = 'nsa.gov'
  12. USER = 'root'
  13. PASSWORD = 'god'
  14. DATABASE = 'NSA'
  15. """****************"""
  16.  
  17. con = mdb.connect(HOST, USER, PASSWORD, DATABASE);
  18.  
  19. with con:
  20. feeds = []
  21. cur = con.cursor()
  22. cur.execute("SELECT * FROM feeds")
  23. rows = cur.fetchall()
  24. for row in rows:
  25. feeds.append(row[1])
  26.  
  27. Errors = []
  28. Invalid = []
  29. Passed = []
  30.  
  31. for this in feeds:
  32. localTime = time.ctime()
  33. Today = localTime.split(" ")[0], localTime.split(" ")[1], int(localTime.split(" ")[3])
  34. try:
  35. SummaryLengths = []
  36. DescriptionLengths = []
  37. Feed = feedparser.parse(this)
  38. if len(Feed) >0:
  39. FeedTitle = Feed['feed']['title']
  40. Entries = Feed['entries']
  41. if len(Entries) > 0:
  42. Article = Entries[0]
  43. Published = Entries[0]['published']
  44. WeekDay = re.sub(',','',Published.split(" ")[0])
  45. Day = re.sub(',','',Published.split(" ")[1])
  46. Month = re.sub(',','',Published.split(" ")[2])
  47. FeedDate = str(WeekDay), str(Month), int(Day)
  48. if FeedDate and FeedDate == Today and Article:
  49. ArticleTitle = Article['title']
  50. ArticleSummary = Article['summary']
  51. ArticleDescription = Article['description']
  52. SummaryLengths.append(len(ArticleSummary))
  53. DescriptionLengths.append(len(ArticleDescription))
  54. print str(FeedDate)
  55. print str(Today)
  56. print "Average Summary Length %d" % (sum(SummaryLengths) / len(SummaryLengths))
  57. print "Average Description Length Length %d" % (sum(DescriptionLengths) / len(DescriptionLengths))
  58. except Exception as error:
  59. Errors.append(error)
  60. Invalid.append(this)
  61. print "%d Errors" % (len(Errors))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement