Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
scateu authored May 11, 2024
2 parents 6c2a912 + ab67ec8 commit 6c337da
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 32 deletions.
54 changes: 27 additions & 27 deletions .build/validator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

from os import sys,path,environ

environ['LANGUAGE'] = 'en'

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

Expand Down Expand Up @@ -33,26 +33,26 @@

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

site = entry.get('htmlUrl')
code = -1
print "Testing HTTP connectivity...: %s" % site
print("Testing HTTP connectivity...: %s" % site)
try:
resp = urllib2.urlopen(site)
resp = urllib.request.urlopen(site)
code = resp.getcode()
except Exception as e:
print "Cannot connect to site: %s" % str(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
print("Site successfully responded with code %s" % code)
elif code >= 0:
print "Site responded with unexpected response code %s" % code
print("Site responded with unexpected response code %s" % code)
siteFailed.append([title, entry])

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

events = None
Expand All @@ -61,7 +61,7 @@
except feedvalidator.logging.ValidationFailure as vf:
events = [vf.event]
except Exception as e:
print "Unable to fetch feed: %s" % str(e)
print("Unable to fetch feed: %s" % str(e))
feedCritical.append(e)

if events is not None:
Expand All @@ -70,38 +70,38 @@

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

print ""
print("")

print "### SUMMARY ###"
print "In total of %s entries:" % len(entries)
print "%s entries failed the connectivity test:" % len(siteFailed)
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("\t%s: %s" % (title, entry))
print("")

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

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

if len(feedCritical) > 0:
sys.exit(1)
107 changes: 107 additions & 0 deletions .build/validator.python2.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/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
import socket
socket.setdefaulttimeout(5)

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=1)['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)
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python 2.7
uses: actions/setup-python@v2
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 2.7
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ TUNA的同学们有权限可以直接编辑此文件;其它同学们烦请发
|Kxn's eXercise Notes| http://blog.kangkang.org/index.php/feed | http://blog.kangkang.org/ |
|laike9m's blog| https://laike9m.com/blog/rss/ | https://laike9m.com/blog/ |
|Librehat's Blog| https://www.librehat.com/feed/ | https://www.librehat.com/ |
|Lv. MAX| https://maxlv.net/rss/ | https://maxlv.net/ |
|MaskRay| http://maskray.me/atom.xml | http://maskray.me/blog |
|May the #! be with you| https://onebitbug.me/feed/atom.xml | https://onebitbug.me/ |
|oldj's blog| http://oldj.net/feed/ | http://oldj.net/ |
Expand Down Expand Up @@ -219,6 +218,9 @@ TUNA的同学们有权限可以直接编辑此文件;其它同学们烦请发
| ECWU's Notebook | https://ecwuuuuu.com/index.xml | https://ecwuuuuu.com |
| Amicoyuan | https://xingyuanjie.top/rss.xml | https://xingyuanjie.top |
| 九仞之行 | https://styunlen.cn/feed | https://styunlen.cn/ |
| A小編也推薦 | https://alittleeditor.com/rss.xml | https://alittleeditor.com/ |
| Starkakrats | https://raw.githubusercontent.com/starkakrats/starkakrats-feed/main/index.xml | https://starkakrats.tiddlyhost.com |


## OPML

Expand Down

0 comments on commit 6c337da

Please sign in to comment.