Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wikitables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
log = logging.getLogger('wikitables')


def import_tables(article, lang='en'):
client = Client(lang)
def import_tables(article, base_url='wikipedia.org/w/api.php', lang='en'):
client = Client(base_url, lang)
page = client.fetch_page(article)
body = page['revisions'][0]['*']

Expand Down
7 changes: 6 additions & 1 deletion wikitables/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def main():
parser.add_argument('-d', '--debug',
action='store_true',
help='enable debug output')
parser.add_argument('-u', '--base-url',
action='store',
dest='base_url',
default='wikipedia.org/w/api.php',
help='set the base url')
parser.add_argument('article', help='article title')

args = parser.parse_args()
Expand All @@ -38,7 +43,7 @@ def main():
else:
logging.basicConfig(level=logging.WARN)

tables = import_tables(args.article, lang=args.lang)
tables = import_tables(args.article, base_url=args.base_url, lang=args.lang)
tables_dict = {table.name: table.rows for table in tables}
if args.pretty:
jprint(tables_dict)
Expand Down
7 changes: 5 additions & 2 deletions wikitables/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class ArticleNotFound(RuntimeError):
class Client(requests.Session):
""" Mediawiki API client """

def __init__(self, lang="en"):
def __init__(self, base_url='wikipedia.org/w/api/php', lang="en"):
super(Client, self).__init__()
self.base_url = 'https://' + lang + '.wikipedia.org/w/api.php'
if base_url.startswith('wikipedia.org'):
self.base_url = f'https://{lang}.{base_url}'
else:
self.base_url = base_url

def fetch_page(self, title, method='GET'):
""" Query for page by title """
Expand Down