Skip to content

Commit

Permalink
Addressing #42
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 4ff0e66
Author: Travis CI <ci@travis-ci.org>
Date:   Tue Jan 8 23:36:25 2019 +0800

    Unicode, take II

commit 505d868
Author: Travis CI <ci@travis-ci.org>
Date:   Tue Jan 8 23:27:04 2019 +0800

    Unicode

commit de5e895
Author: Travis CI <ci@travis-ci.org>
Date:   Tue Jan 8 23:22:45 2019 +0800

    Fix

commit 0ef5eeb
Author: Liu Xiaoyi <circuitcoder0@gmail.com>
Date:   Tue Jan 8 23:13:13 2019 +0800

    (Trying) to fix the push script

commit 33b7971
Author: Liu Xiaoyi <circuitcoder0@gmail.com>
Date:   Tue Jan 8 23:04:12 2019 +0800

    Added the validator and only run the CI push tag on tuna/blogroll:master
  • Loading branch information
CircuitCoder committed Jan 8, 2019
1 parent d8ffcbf commit 416c9c1
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions .build/feedvalidator
Submodule feedvalidator added at 849deb
5 changes: 5 additions & 0 deletions .build/push.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

if [[ $TRAVIS_BRANCH != "master" ]] || [[ $TRAVIS_REPO_SLUG != "tuna/blogroll" ]]; then
echo "Skip deployment"
exit 0
fi

# Reference: https://gist.github.com/willprice/e07efd73fb7f13f917ea

scriptpath=$(readlink "$0")
Expand Down
105 changes: 105 additions & 0 deletions .build/validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env python2

from os import sys,path,environ

environ['LANGUAGE'] = 'en'

import urllib2
# OK I know I cannot write python
sys.path.append(path.join(path.dirname(__file__), 'feedvalidator', 'src'))

from bs4 import BeautifulSoup
import feedvalidator

with open(sys.argv[1], 'r') as opmlFile:

opml = opmlFile.read().decode('utf-8')
opml = BeautifulSoup(opml, 'xml')

entries = opml.find_all('outline')

total = len(entries)

# Ones that failed the connectivity test
siteFailed = []

# Ones that failed the feed validator test
feedCritical = []

# Ones that triggered feed validator warnings
feedWarning = []

for entry in entries:
title = entry.get('title').encode('utf-8')
print '=== Validating %s ===' % title

site = entry.get('htmlUrl')
code = -1
print "Testing HTTP connectivity...: %s" % site
try:
resp = urllib2.urlopen(site)
code = resp.getcode()
except Exception as e:
print "Cannot connect to site: %s" % str(e)
siteFailed.append([title, entry])

if code >= 200 and code < 400:
# Is a valid response
print "Site successfully responded with code %s" % code
elif code >= 0:
print "Site responded with unexpected response code %s" % code
siteFailed.append([title, entry])

print "Fetching feeds..."
feed = entry.get('xmlUrl')

events = None
try:
events = feedvalidator.validateURL(feed, firstOccurrenceOnly=0)['loggedEvents']
except feedvalidator.logging.ValidationFailure as vf:
events = [vf.event]
except Exception as e:
print "Unable to fetch feed: %s" % str(e)
feedCritical.append(e)

if events is not None:
from feedvalidator import compatibility
from feedvalidator.formatter.text_plain import Formatter

criticals = compatibility.A(events)
if len(criticals) > 0:
print "Feed failed validation with critical errors:"
output = Formatter(criticals)
print "\n".join(output)
feedCritical.append([title, entry])
else:
warnings = compatibility.AAA(events)
if len(warnings) > 0:
print "Feed passed validation with warnings:"
output = Formatter(warnings)
print "\n".join(output)
feedWarning.append([title, entry])
else:
print "Feed passed validation with no error or warning"

print ""

print "### SUMMARY ###"
print "In total of %s entries:" % len(entries)
print "%s entries failed the connectivity test:" % len(siteFailed)
for [title, entry] in siteFailed:
print "\t%s: %s" % (title, entry)
print ""

print "%s entries failed the feed validation:" % len(feedCritical)
for [title, entry] in feedCritical:
print "\t%s: %s" % (title, entry)
print ""

print "%s entries passed the feed validation with warnings:" % len(feedWarning)
for [title, entry] in feedWarning:
print "\t%s: %s" % (title, entry)
print ""

if len(feedCritical) > 0:
sys.exit(1)
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule ".build/feedvalidator"]
path = .build/feedvalidator
url = https://github.com/rubys/feedvalidator
branch = master
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
language: generic
dist: xenial

branches:
only:
- master

before_install:
- sudo apt-get install git
- sudo apt-get install python python-lxml python-bs4

script:
- .build/buildOpml.sh > opml.xml
# For now, half the tests fail, so I'm muting the error
- .build/validator.py opml.xml || true

after_success:
- .build/push.sh

0 comments on commit 416c9c1

Please sign in to comment.