-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
A. Tapekhin
committed
Jan 27, 2016
1 parent
cc19ee3
commit 406f78d
Showing
9 changed files
with
689 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import sqlite3 | ||
import base64 | ||
import requests | ||
import json | ||
import hashlib | ||
import logging | ||
|
||
|
||
def approve_batch(session, approve_url, entities): | ||
status = session.patch(approve_url, json={'entities': entities}) | ||
return status | ||
|
||
|
||
def approve(session, server_url,dictionary_client_id, dictionary_object_id, client_id, object_id): | ||
from time import time | ||
start = time() | ||
connect_url = server_url + 'dictionary/%s/%s/perspective/%s/%s/all_count' % (dictionary_client_id, | ||
dictionary_object_id, | ||
client_id, object_id) | ||
status = session.get(connect_url) | ||
|
||
count = json.loads(status.text)['count'] | ||
connect_url = server_url + 'dictionary/%s/%s/perspective/%s/%s/all?count=%s' % (dictionary_client_id, | ||
dictionary_object_id, | ||
client_id, object_id, | ||
count) | ||
approve_url = server_url + 'dictionary/%s/%s/perspective/%s/%s/approve' % (dictionary_client_id, | ||
dictionary_object_id, | ||
client_id, object_id) | ||
perspective = session.get(connect_url) | ||
perspective = json.loads(perspective.text) | ||
entities = list() | ||
for lexicalentry in perspective['lexical_entries']: | ||
for entity in lexicalentry['contains']: | ||
if entity['level'] in ['leveloneentity', 'groupingentity']: | ||
not_publ = True | ||
if entity.get('contains'): | ||
for entity2 in entity['contains']: | ||
if 'publ' in entity2['level']: | ||
if not entity2['marked_for_deletion']: | ||
not_publ = False | ||
else: | ||
if entity2['level'] == 'leveltwoentity': | ||
not_publ_2 = True | ||
if entity2.get('contains'): | ||
for entity3 in entity2['contains']: | ||
if 'publ' in entity3['level']: | ||
if not entity3['marked_for_deletion']: | ||
not_publ_2 = False | ||
break | ||
if not_publ_2: | ||
entity2['type'] = entity2['level'] | ||
entities += [entity2] | ||
if len(entities) > 100: | ||
approve_batch(session, approve_url, entities) | ||
entities = list() | ||
if not_publ: | ||
entity['type'] = entity['level'] | ||
entities += [entity] | ||
if len(entities) > 100: | ||
approve_batch(session, approve_url, entities) | ||
entities = list() | ||
approve_batch(session, approve_url, entities) | ||
return {'time': time() - start} | ||
|
||
|
||
def approve_all_outer(login, password_hash,dictionary_client_id, dictionary_object_id, | ||
perspective_client_id, perspective_object_id, server_url="http://localhost:6543/"): | ||
log = logging.getLogger(__name__) | ||
log.debug("Starting convert_one") | ||
log.debug("Creating session") | ||
session = requests.Session() | ||
session.headers.update({'Connection': 'Keep-Alive'}) | ||
adapter = requests.adapters.HTTPAdapter(pool_connections=3, pool_maxsize=3, max_retries=3) | ||
session.mount('http://', adapter) | ||
log.debug("Going to login") | ||
login_data = {"login": login, "passwordhash": password_hash} | ||
log.debug("Login data: " + login_data['login'] + login_data['passwordhash']) | ||
cookie_set = session.post(server_url + 'cheatlogin', json=login_data) | ||
log.debug("Login status:" + str(cookie_set.status_code)) | ||
if cookie_set.status_code != 200: | ||
log.error("Cheat login for conversion was unsuccessful") | ||
exit(-1) | ||
try: | ||
status = approve(session, server_url, | ||
dictionary_client_id, dictionary_object_id, perspective_client_id, perspective_object_id) | ||
except Exception as e: | ||
log.error("approving failed") | ||
log.error(e.__traceback__) | ||
raise | ||
log.error(status) | ||
return status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,58 @@ | ||
bcrypt==2.0.0 | ||
passlib==1.6.5 | ||
Babel==2.0 | ||
Babel==2.1.1 | ||
Chameleon==2.22 | ||
Mako==1.0.1 | ||
Mako==1.0.3 | ||
MarkupSafe==0.23 | ||
PasteDeploy==1.5.2 | ||
Pygments==2.0.2 | ||
SQLAlchemy==1.0.8 | ||
WebOb==1.5.0a1 | ||
alembic==0.8.0 | ||
argparse==1.3.0 | ||
debtcollector==0.7.0 | ||
WebTest==2.0.20 | ||
alembic==0.8.3 | ||
argparse==1.1 | ||
bcrypt==2.0.0 | ||
beautifulsoup4==4.4.1 | ||
cffi==1.3.1 | ||
debtcollector==1.0.0 | ||
futures==3.0.3 | ||
iso8601==0.1.10 | ||
monotonic==0.3 | ||
gunicorn==19.4.2 | ||
iso8601==0.1.11 | ||
monotonic==0.4 | ||
msgpack-python==0.4.6 | ||
netaddr==0.7.15 | ||
netaddr==0.7.18 | ||
netifaces==0.10.4 | ||
nltk==3.0.5 | ||
nose==1.3.7 | ||
oslo.config==2.2.0 | ||
oslo.i18n==2.3.0 | ||
oslo.serialization==1.8.0 | ||
oslo.utils==2.2.0 | ||
pbr==1.5.0 | ||
pluggy==0.3.0 | ||
numpy==1.10.1 | ||
oslo.config==3.0.0 | ||
oslo.i18n==3.0.0 | ||
oslo.serialization==2.0.0 | ||
oslo.utils==3.0.0 | ||
passlib==1.6.5 | ||
pbr==1.8.1 | ||
prettytable==0.7.2 | ||
py==1.4.30 | ||
psycopg2==2.6.1 | ||
pycparser==2.14 | ||
pympi-ling==1.40 | ||
pyramid==1.6a2 | ||
pyramid-chameleon==0.3 | ||
pyramid-debugtoolbar==2.4.1 | ||
pyramid-mako==1.0.2 | ||
pyramid-tm==0.12 | ||
python-editor==0.3 | ||
python-keystoneclient==1.6.0 | ||
python-swiftclient==2.5.0 | ||
pytz==2015.4 | ||
python-editor==0.4 | ||
python-keystoneclient==1.8.1 | ||
python-swiftclient==2.6.0 | ||
pytz==2015.7 | ||
repoze.lru==0.6 | ||
requests==2.7.0 | ||
simplejson==3.8.0 | ||
six==1.9.0 | ||
stevedore==1.7.0 | ||
tox==2.1.1 | ||
six==1.10.0 | ||
stevedore==1.9.0 | ||
tgt==1.3.1 | ||
transaction==1.4.4 | ||
translationstring==1.3 | ||
venusian==1.0 | ||
virtualenv==13.1.2 | ||
waitress==0.8.9 | ||
wrapt==1.10.5 | ||
zope.deprecation==4.1.2 | ||
zope.interface==4.1.2 | ||
zope.sqlalchemy==0.7.6 | ||
webtest==2.0.18 | ||
psycopg2==2.6.1 | ||
nltk==3.0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ | |
'waitress', | ||
'alembic', | ||
'passlib', | ||
'py-bcrypt', | ||
'bcrypt', | ||
|
||
'requests', | ||
'simplejson', | ||
'nltk', | ||
|
Oops, something went wrong.