aboutsummaryrefslogtreecommitdiffstats
path: root/fuzzycat/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzycat/__main__.py')
-rw-r--r--fuzzycat/__main__.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/fuzzycat/__main__.py b/fuzzycat/__main__.py
index b2c8e60..89e3a12 100644
--- a/fuzzycat/__main__.py
+++ b/fuzzycat/__main__.py
@@ -17,13 +17,20 @@ import io
import json
import logging
import pstats
+import random
import sys
import tempfile
+import requests
+
from fuzzycat.cluster import (Cluster, release_key_title, release_key_title_ngram,
release_key_title_normalized, release_key_title_nysiis,
release_key_title_sandcrawler)
-from fuzzycat.verify import GroupVerifier
+from fuzzycat.utils import random_word
+from fuzzycat.verify import GroupVerifier, verify
+
+logging.getLogger("requests").setLevel(logging.WARNING)
+logging.getLogger("urllib3").setLevel(logging.WARNING)
def run_cluster(args):
@@ -57,6 +64,31 @@ def run_verify(args):
gv.run()
+def run_verify_single(args):
+ """
+ Run a single verification on a pair.
+ """
+ result = {}
+ if args.a and args.b:
+ a, b = args.a, args.b
+ elif not args.a and not args.b:
+ word = random_word(wordsfile='/usr/share/dict/words')
+ a, b = random_idents_from_query(query=word, r=2)
+ result.update({"extra": {"q": "https://fatcat.wiki/release/search?q={}".format(word)}})
+ else:
+ raise ValueError('specify either both -a, -b or none')
+
+ def fetch_ident(ident):
+ return requests.get("https://api.fatcat.wiki/v0/release/{}".format(ident)).json()
+
+ result.update({
+ "a": "https://fatcat.wiki/release/{}".format(a),
+ "b": "https://fatcat.wiki/release/{}".format(b),
+ "r": verify(fetch_ident(a), fetch_ident(b)),
+ })
+ print(json.dumps(result))
+
+
if __name__ == '__main__':
logging.basicConfig(
level=logging.DEBUG,
@@ -91,6 +123,13 @@ if __name__ == '__main__':
sub_verify.add_argument('-f', '--files', default="-", help='input files')
sub_verify.set_defaults(func=run_verify)
+ sub_verify_single = subparsers.add_parser('verify-single',
+ help='verify a single pair',
+ parents=[parser])
+ sub_verify_single.add_argument('-a', help='ident or url to release')
+ sub_verify_single.add_argument('-b', help='ident or url to release')
+ sub_verify_single.set_defaults(func=run_verify_single)
+
args = parser.parse_args()
if not args.__dict__.get("func"):
print(__doc__, file=sys.stderr)