concordia-server/tests/addSources.py

50 lines
928 B
Python
Raw Normal View History

2019-02-22 22:13:45 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import urllib2
import sys
import time
import host
2019-03-03 15:24:34 +01:00
BUFFER_SIZE = 500
def addSources(sources_buffer):
data = {
'operation': 'addSources',
2019-03-03 19:55:11 +01:00
'sources':sources_buffer
2019-03-03 15:24:34 +01:00
}
req = urllib2.Request(address)
req.add_header('Content-Type', 'application/json')
urllib2.urlopen(req, json.dumps(data))
2019-02-22 22:13:45 +01:00
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
2019-03-03 15:24:34 +01:00
sources_buffer = []
2019-02-22 22:13:45 +01:00
for line in sources_file:
counter += 1
2019-03-04 11:07:37 +01:00
id_raw, link, name = line.rstrip().split('\t')
sources_buffer.append([int(id_raw),name, link])
2019-03-03 15:24:34 +01:00
if len(sources_buffer) == BUFFER_SIZE:
addSources(sources_buffer)
sources_buffer = []
print("Added %d sources" % counter)
2019-02-22 22:13:45 +01:00
2019-03-03 15:24:34 +01:00
if len(sources_buffer) > 0:
addSources(sources_buffer)
2019-02-22 22:13:45 +01:00
2019-03-03 15:24:34 +01:00
print("Added all %d sources" % counter)
2019-02-22 22:13:45 +01:00