#!/usr/bin/python # -*- coding: utf-8 -*- import json import urllib2 import sys import time import host BUFFER_SIZE = 500 def addSources(sources_buffer): data = { 'operation': 'addSources', 'sources':sources } req = urllib2.Request(address) req.add_header('Content-Type', 'application/json') urllib2.urlopen(req, json.dumps(data)) address = 'http://'+host.concordia_host if len(host.concordia_port) > 0: address += ':'+host.concordia_port with open(sys.argv[1]) as sources_file: counter = 0 sources_buffer = [] for line in sources_file: counter += 1 sources_buffer.append(line.rstrip().split('\t')) if len(sources_buffer) == BUFFER_SIZE: addSources(sources_buffer) sources_buffer = [] print("Added %d sources" % counter) if len(sources_buffer) > 0: addSources(sources_buffer) print("Added all %d sources" % counter)