From 55f486c98d072ca6c0b1b3d4b0dacd367fc03721 Mon Sep 17 00:00:00 2001 From: ivanhercaz Date: Sun, 27 May 2018 01:59:40 +0100 Subject: [PATCH] adapting as Python package --- pysemanticmw/__init__.py | 2 ++ smw.py => pysemanticmw/smw.py | 0 smwcli.py | 8 ++++---- test.py | 23 ++++++++++++++++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 pysemanticmw/__init__.py rename smw.py => pysemanticmw/smw.py (100%) diff --git a/pysemanticmw/__init__.py b/pysemanticmw/__init__.py new file mode 100644 index 0000000..d57fe1e --- /dev/null +++ b/pysemanticmw/__init__.py @@ -0,0 +1,2 @@ +from .smw import SemanticMediaWiki +from .smw import APIErrors diff --git a/smw.py b/pysemanticmw/smw.py similarity index 100% rename from smw.py rename to pysemanticmw/smw.py diff --git a/smwcli.py b/smwcli.py index 9e53515..891576b 100644 --- a/smwcli.py +++ b/smwcli.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import argparse -from smw import * +import pysemanticmw as pysmw config = { "apiPoint": "https://semantic-mediawiki.org/w/api.php", @@ -55,12 +55,12 @@ def main(): query = args.query if args.api: - smw = SemanticMediaWiki(args.api) + smw = pysmw.SemanticMediaWiki(args.api) elif config["apiPoint"] is not "": - smw = SemanticMediaWiki(config["apiPoint"]) + smw = pysmw.SemanticMediaWiki(config["apiPoint"]) else: apiPoint = input("Insert the API URL of the Semantic MediaWiki you want to read: ") - smw = SemanticMediaWiki(apiPoint) + smw = pysmw.SemanticMediaWiki(apiPoint) if args.ask: action = "ask" diff --git a/test.py b/test.py index bbafc35..237b132 100644 --- a/test.py +++ b/test.py @@ -1,9 +1,28 @@ # -*- coding: utf-8 -*- -from smw import * +import pysemanticmw as pysmw apiPoint = "" +while apiPoint == "": + if not apiPoint: + apiPoint = input("Insert API URL (e. g., https://sandbox.semantic-mediawiki.org/w/api.php): ") + if not apiPoint: + print("You didn't insert any API URL, please, insert one.") + else: + print("API URL: {}".format(apiPoint)) + + smw = pysmw.SemanticMediaWiki(apiPoint) + +query = "[[Modification date::+]]|?Modification date|sort=Modification date|order=desc" + +ask = smw.ask(query, format="json") + +print(ask) + +''' +Test SemanticMediaWiki > ask() + while apiPoint == "": if not apiPoint: apiPoint = input("Insert API URL (e. g., https://www.semantic-mediawiki.org/w/api.php): ") @@ -19,3 +38,5 @@ ask = smw.ask(query) print(ask) + +'''