<commit_before>"""Validate GTFS"""
import os
import subprocess
import argparse

import transitland.registry

import util

class FeedValidator(object):
  def __init__(self, filename):
    self.exceptions = []
    self.filename = filename
    
  def errors(self):
    # Filter for errors
    return self.exceptions
    
  def warnings(self):
    # Filter for warnings
    return self.exceptions    
    
  def feedvalidator(self, report='report.html'):
    self.exceptions = []
    p = subprocess.Popen(
      [
        'feedvalidator.py',
        '--memory_db',
        '--noprompt',
        '--output',
        report,
        self.filename
      ],
      stdout=subprocess.PIPE, 
      stderr=subprocess.PIPE
    )
    stdout, stderr = p.communicate()
    returncode = p.returncode
    errors = [i for i in stdout.split('\n') if i.startswith('ERROR:')]
    if returncode:
      self.exceptions.append(Exception('Invalid feed'))

def run():
  parser = util.default_parser('Validate GTFS')
  args = parser.parse_args()
  r = transitland.registry.FeedRegistry(path=args.registry)
  feedids = args.feedids
  if args.all:
    feedids = r.feeds()
  if len(feedids) == 0:
    raise Exception("No feeds specified! Try --all")
  for feedid in feedids:
    feed = r.feed(feedid)
    validator = FeedValidator(feed.filename())
    validator.feedvalidator('%s.html'%feed.onestop())
    if validator.errors():
      print "Feed contains errors."
    elif validator.warnings():
      print "Feed contains warnings."
    else:
      print "Feed appears valid!"
      
    
if __name__ == "__main__":
  run()<commit_msg>Cosmetic<commit_after>"""Validate GTFS"""
import os
import subprocess
import argparse

import transitland.registry

import util

class FeedValidator(object):
  def __init__(self, filename):
    self.exceptions = []
    self.filename = filename
    
  def errors(self):
    # Filter for errors
    return self.exceptions
    
  def warnings(self):
    # Filter for warnings
    return self.exceptions    
    
  def feedvalidator(self, report='report.html'):
    self.exceptions = []
    p = subprocess.Popen(
      [
        'feedvalidator.py',
        '--memory_db',
        '--noprompt',
        '--output',
        report,
        self.filename
      ],
      stdout=subprocess.PIPE, 
      stderr=subprocess.PIPE
    )
    stdout, stderr = p.communicate()
    returncode = p.returncode
    errors = [i for i in stdout.split('\n') if i.startswith('ERROR:')]
    if returncode:
      self.exceptions.append(Exception('Invalid feed'))

def run():
  parser = util.default_parser('Validate GTFS')
  args = parser.parse_args()
  #
  r = transitland.registry.FeedRegistry(path=args.registry)
  feedids = args.feedids
  if args.all:
    feedids = r.feeds()
  if len(feedids) == 0:
    raise Exception("No feeds specified! Try --all")
  #
  for feedid in feedids:
    print feedid
    feed = r.feed(feedid)
    validator = FeedValidator(feed.filename())
    validator.feedvalidator('%s.html'%feed.onestop())
    if validator.errors():
      print "Feed contains errors."
    elif validator.warnings():
      print "Feed contains warnings."
    else:
      print "Feed appears valid!"
      
    
if __name__ == "__main__":
  run()
{'fraction_non_alphanumeric': 0.12198142414860681, 'fraction_numerical': 0.0006191950464396285, 'mean_word_length': 2.7439165701042874, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5416829', 'n_tokens_mistral': 1020, 'n_tokens_neox': 1015, 'n_words': 239}