Skip to content

Commit

Permalink
add a validator script to the repo
Browse files Browse the repository at this point in the history
[fix #49]
  • Loading branch information
yanivpas committed Nov 5, 2014
1 parent fe2b127 commit c514816
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 0 additions & 2 deletions engine/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ def upload_dir_from_zip(solr,path):
AD in info.filename and
info.filename.endswith(".xml"))]

# TODO: also search the Ads

for article_file in article_files:
# Create the article object.
ar = Article(zip_file.open(article_file.filename, "r"))
Expand Down
53 changes: 53 additions & 0 deletions engine/upload/validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from upload import upload_all
from os.path import join, splitext, exists
from zipfile import ZipFile
import sys
import os

import json
import urllib2


SERVER = "opa.org.il"

class ArticleError(Exception): pass


def validate_article(article):


# Set the request URL
url = 'http://%s/api/v1/?articleId=%s' %(SERVER, article['id'])

req = urllib2.Request(url)

# Read the response
resp = urllib2.urlopen(req).read()

# Interpret the JSON response
data = json.loads(resp.decode('utf8'))
if data['count'] != 1:
articles = []
for article in data['results']:
articles.append(article['id'])
raise ArticleError("The count for %s is different then one the list - %s" %(article['id'],str(articles)))

def validate_articles(articles):
for article in articles:
validate_article(article)


class DemoSolr(object):
def add(self, articles):
''' this is an hack so we wouldn't have to copy alot of code'''
validate_articles(articles)



def main(argv):
solr = DemoSolr()
upload_all(solr, argv[1])


if __name__ == "__main__":
main(sys.argv)

0 comments on commit c514816

Please sign in to comment.