py-3rdparty-mediawiki API Documentation
crypt
Created on 25.03.2020
@author: wf
Crypt
Bases: object
Python implementation of PBEWithMD5AndDES see https://github.com/binsgit/PBEWithMD5AndDES and https://gist.github.com/rohitshampur/da5f79c34260150aafc1
converted to class
Source code in wikibot3rd/crypt.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
__init__(cypher, iterations=20, salt=None)
construct me with the given cypher iterations and salt
Source code in wikibot3rd/crypt.py
27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
decrypt(encoded)
decrypt the given message
Source code in wikibot3rd/crypt.py
89 90 91 92 93 94 95 96 97 |
|
encrypt(msg)
encrypt the given message
Source code in wikibot3rd/crypt.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
getCrypt()
get my DES crypt
Source code in wikibot3rd/crypt.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
lambda_action
Created on 31.01.2021
@author: wf
Code
Bases: object
a piece of code
Source code in wikibot3rd/lambda_action.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
__init__(name, text, lang='python')
construct me from the given text and language
Source code in wikibot3rd/lambda_action.py
19 20 21 22 23 24 25 |
|
execute(context)
https://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python https://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3 https://stackoverflow.com/questions/2220699/whats-the-difference-between-eval-exec-and-compile
Source code in wikibot3rd/lambda_action.py
27 28 29 30 31 32 33 34 35 36 37 |
|
executeTemplate(context)
Renders the jinja-template with the query results placed in the given context and stores the result as wiki page. The name of the wiki page is either given through the template with set parameters. E.g.: {% set pagetitle = ""%} {% set pagetitle_prefix = "List of "%} If the pagetitle is empty, like in the example, the name variable of the query results is used as pagetitle. The pagetitle_prefix is added in all cases, if not defined a empty string is added. Assumption: self.text is a jinja template
Source code in wikibot3rd/lambda_action.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
LambdaAction
Bases: object
a lambda action
Source code in wikibot3rd/lambda_action.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
__init__(name, query, code)
Constructor
Source code in wikibot3rd/lambda_action.py
84 85 86 87 88 89 90 |
|
execute(context)
run my query and feed the result into the given code
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context(dict) |
a dictionary for the exchange of parameters |
required |
Source code in wikibot3rd/lambda_action.py
122 123 124 125 126 127 128 129 130 |
|
unescapeHTML(value)
staticmethod
Unescapes received html value and removes html tags.
Replaces:
<br /> -> "
"
-> "" Args: value(str): html encoded string Returns: Returns the received value but without the html tags and unescaped.Source code in
wikibot3rd/lambda_action.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146@staticmethod def unescapeHTML(value: str): """ Unescapes received html value and removes html tags. Replaces: <br /> -> "\n" <pre> -> "" Args: value(str): html encoded string Returns: Returns the received value but without the html tags and unescaped. """ if value.startswith("<pre>"): return html.unescape(value).replace("<br />", "\n")[5:][:-6] return value
mwTable
Created on 2020-08-21
@author: wf
MediaWikiTable
Bases: object
helper for https://www.mediawiki.org/wiki/Help:Tables
Source code in wikibot3rd/mwTable.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
__init__(wikiTable=True, colFormats=None, sortable=True, withNewLines=False)
Constructor
Source code in wikibot3rd/mwTable.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
addHeader(record)
add the given record as a "sample" header
Source code in wikibot3rd/mwTable.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
asWikiMarkup()
convert me to MediaWiki markup
Returns:
Name | Type | Description |
---|---|---|
string |
the MediWiki Markup for this table |
Source code in wikibot3rd/mwTable.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
pagehistory
PageHistory
Represents the history of a page
Source code in wikibot3rd/pagehistory.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
__init__(pageTitle, wikiId, debug=False)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitle(str) |
name of the page |
required | |
wikiId(str) |
id of the wiki the page is located |
required | |
debug(bool) |
If True show debug messages |
required |
Source code in wikibot3rd/pagehistory.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
exists()
Checks if the page exists Assumption: If the page exists than ot exists at least one revision entry
Returns:
Type | Description |
---|---|
bool
|
True if the page exists otherwise False |
Source code in wikibot3rd/pagehistory.py
78 79 80 81 82 83 84 85 86 |
|
getFirstUser(reverse=False, limitedUserGroup=None)
Returns the first user in the revisions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reverse(bool) |
If False start the search at the oldest entry. Otherwise, search from the newest to the oldest revision |
required | |
limitedUserGroup(list) |
limit the search to the given list. If None all users will be considered. |
required |
Returns:
Type | Description |
---|---|
Union[str, None]
|
str username that matches the search criterion |
Source code in wikibot3rd/pagehistory.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
PageRevision
Bases: JSONAble
Represents the metadata of a mediawiki page revision
Source code in wikibot3rd/pagehistory.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
selector
Created on 2020-12-20
Selector
selector class
Source code in wikibot3rd/selector.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
__init__(items)
Constructor
Source code in wikibot3rd/selector.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
createWindow(root, action, title, description)
create the Window for the selection list Args: root(tk.App Object): tk.App opened object action(str): Type of Action title(str): Title of Window description(str): Description of Task to do Returns: None
Source code in wikibot3rd/selector.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
getUpdatedPages()
Getter function for the class variable items Returns: items(list): List of pages selected in GUI by user
Source code in wikibot3rd/selector.py
171 172 173 174 175 176 177 |
|
quitSelector(root)
Quit the python program when Quit Button is pressed. Args: root(tk.App Object): tk.App opened object Returns: None
Source code in wikibot3rd/selector.py
160 161 162 163 164 165 166 167 168 169 |
|
select(selectionList, action='Select', title='Selection', description='')
staticmethod
Creates a GUI in which the user can select a subset of the provided selectionList. The user can quit the selection resulting in the return of an empty list. :param selectionList: :param action: name of the action the selection performs. Default is select :param title: title of the created window :param description: Instructions for the user (consequence of the selection) :return: user selected subset of the given selectionList
Source code in wikibot3rd/selector.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
select_all(listbox)
Button helper function to select all list items Returns: listbox(Tk Listbox Object): listbox to update to all items
Source code in wikibot3rd/selector.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
updateCheck(event)
Helper function to change state of select all checkbox Returns: event(Tk event Object): All registered events on Tkinter
Source code in wikibot3rd/selector.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
updatePages(root, listbox)
Update function to remove unselected items from list Args: root(tk.App Object): tk.App opened object listbox(TK listbox Object): listbox to update Returns: None
Source code in wikibot3rd/selector.py
146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
smw
Created on 2020-05-29
@author: wf
PrintRequest
Bases: object
Source code in wikibot3rd/smw.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
debug = PrintRequest.debug
class-attribute
instance-attribute
construct the given print request see https://www.semantic-mediawiki.org/wiki/Serialization_(JSON) :ivar smw: SMW context for this printrequest :ivar label: the label of the printrequest :ivar key: :ivar redi: :ivar typeid: :ivar mode: :ivar format:
__init__(smw, record)
construct me from the given record Args: smw(SMW): the SemanticMediaWiki context of this PrintRequest record(dict): the dict derived from the printrequest json serialization
Source code in wikibot3rd/smw.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
deserialize(result)
deserialize the given result record Args: result(dict): a single result record dict from the deserialiation of the ask query Returns: object: a single deserialized value according to my typeid
Source code in wikibot3rd/smw.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
deserializeSingle(value)
deserialize a single value Args: value(object): the value to be deserialized according to the typeid
Returns:
Type | Description |
---|---|
the deserialized value |
Source code in wikibot3rd/smw.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
QueryResultSizeExceedException
Bases: BaseException
Raised if the results of a query can not completely be queried due to SMW result limits.
Source code in wikibot3rd/smw.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
|
getResults()
Returns the queried results before the exception was raised
Source code in wikibot3rd/smw.py
685 686 687 |
|
SMW
Bases: object
Semantic MediaWiki Access e.g. for ask API see * https://www.semantic-mediawiki.org/wiki/Help:API * https://www.semantic-mediawiki.org/wiki/Serialization_(JSON) * https://www.semantic-mediawiki.org/wiki/Help:API:askargs
adapted from Java SimpleGraph Module https://github.com/BITPlan/com.bitplan.simplegraph/blob/master/simplegraph-smw/src/main/java/com/bitplan/simplegraph/smw/SmwSystem.java :ivar site: the pywikibot site to use for requests :ivar prefix: the path prefix for this site e.g. /wiki/
Source code in wikibot3rd/smw.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
__init__(site=None, prefix='/', showProgress=False, queryDivision=1, debug=False)
Constructor Args: site: the site to use (optional) showProgess(bool): if progress should be shown queryDivision(int): Defines the number of subintervals the query is divided into (must be greater equal 1) debug(bool): if debugging should be activated - default: False
Source code in wikibot3rd/smw.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
deserialize(rawresult)
deserialize the given rawresult according to https://www.semantic-mediawiki.org/wiki/Serialization_(JSON)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rawresult(dict) |
contains printrequests and results which need to be merged |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
query mainlabel (usually pageTitle) mapped to the corresponding dict of printrequests with label |
Source code in wikibot3rd/smw.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
fixAsk(ask)
fix an ask String to be usable for the API Args: ask: - a "normal" ask query
Returns:
Type | Description |
---|---|
the fixed asked query |
Source code in wikibot3rd/smw.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
getConcept(ask)
get the concept from the given ask query
Source code in wikibot3rd/smw.py
293 294 295 296 297 298 299 |
|
getOuterMostArgumentValueOfQuery(argument, query)
staticmethod
Extracts the integer value of the given argument from the given query Args: argument(string): Argument that should be extracted query(string): smw query where the given argument is assumed
Returns:
Type | Description |
---|---|
Returns integer value of the given argument in the given query. |
|
If the argument occurs multiple times the last one is returned. |
|
If it does not occur return None. |
Source code in wikibot3rd/smw.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
SMWBot
Bases: SMW
Semantic MediaWiki access using pywikibot library
Source code in wikibot3rd/smw.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
|
__init__(site=None, prefix='/', showProgress=False, debug=False)
constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site |
|
None
|
|
prefix(str) |
the prefix to use |
required | |
showProgress(bool) |
show progress if true |
required | |
debug(bool) |
set debugging mode if true |
required |
Source code in wikibot3rd/smw.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
info()
see https://www.semantic-mediawiki.org/wiki/Help:API:smwinfo
Source code in wikibot3rd/smw.py
646 647 648 649 |
|
query(ask, limit=None)
send a query and deserialize it
Source code in wikibot3rd/smw.py
665 666 667 668 669 670 671 |
|
rawquery(ask, limit=None)
send a query see https://www.semantic-mediawiki.org/wiki/Help:Inline_queries#Parser_function_.23ask
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ask(str) |
the SMW ASK query as it would be used in MediaWiki markup |
required |
Source code in wikibot3rd/smw.py
651 652 653 654 655 656 657 658 659 660 661 662 663 |
|
submit(parameters)
submit the request with the given parameters Args: parameters(list): the parameters to use for the SMW API request Returns: dict: the submit result
Source code in wikibot3rd/smw.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
|
SMWClient
Bases: SMW
Semantic MediaWiki access using mw client library
Source code in wikibot3rd/smw.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
|
ask(query, title=None, limit=None)
Ask a query against Semantic MediaWiki.
API doc: https://semantic-mediawiki.org/wiki/Ask_API
The query is devided into multiple subqueries if the results of the query exeed the defined threshold. If this happens the query is executed multiple times to retrieve all results without passing the threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query(str) |
SMW ask query to be executed |
required | |
title(str) |
title of query (optional) |
required | |
limit(int) |
the maximum number of results to be returned - please note that SMW configuration will also limit results on the server side |
required |
Returns:
Type | Description |
---|---|
Generator for retrieving all search results, with each answer as a dictionary. |
|
If the query is invalid, an APIError is raised. A valid query with zero |
|
results will not raise any error. |
Examples:
>>> query = "[[Category:my cat]]|[[Has name::a name]]|?Has property"
>>> for answer in site.ask(query):
>>> for title, data in answer.items()
>>> print(title)
>>> print(data)
Source code in wikibot3rd/smw.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
askForAllResults(query, limit=None, kwargs={})
Executes the query until all results are received of the given limit is reached. If the SMW results limit is reached before all results are retrieved the QueryResultSizeExceedException is raised. Args: query(string): the SMW inline query to be send via api limit(int): limit for the query results, None (default) for all results kwargs: Returns: query results Raises: QueryResultSizeExceedException: Raised if not all results can be retrieved
Source code in wikibot3rd/smw.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
askPartitionQuery(query, limit=None)
Splits the query into multiple subqueries by determining the 'modification date' interval in which all results lie. This interval is then divided into subintervals. The number of subintervals is defined by the user via commandline. The results of all subqueries are then returned. Args: query(string): the SMW inline query to be send via api limit(string): limit of the query Returns: All results of the given query.
Source code in wikibot3rd/smw.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
getBoundariesOfQuery(query)
Retrieves the time interval, lower and upper bound, based on the modification date in which the results of the given query lie. Args: query(string): the SMW inline query to be send via api Returns: (Datetime, Datetime): Returns the time interval (based on modification date) in which all results of the query lie potentially the start end end might be None if an error occured or the input is invalid
Source code in wikibot3rd/smw.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
getTimeStampBoundary(queryparam, order)
query according to a DATE e.g. MODIFICATION_DATE in the given order
Args:
Source code in wikibot3rd/smw.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
info()
see https://www.semantic-mediawiki.org/wiki/Help:API:smwinfo
Source code in wikibot3rd/smw.py
341 342 343 344 345 346 |
|
query(askQuery, title=None, limit=None)
run query and return list of Dicts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
askQuery(string) |
the SMW inline query to be send via api |
required | |
title(string) |
the title (if any) |
required | |
limit(int) |
the maximum number of records to be retrieved (if any) |
required |
Return
dict: mainlabel as key and value is a dict of the associated property values
Source code in wikibot3rd/smw.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
|
rawquery(askQuery, title=None, limit=None)
run the given askQuery and return the raw result
Parameters:
Name | Type | Description | Default |
---|---|---|---|
askQuery(string) |
the SMW inline query to be send via api |
required | |
title(string) |
the title (if any) |
required | |
limit(int) |
the maximum number of records to be retrieved (if any) |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
the raw query result as returned by the ask API |
Source code in wikibot3rd/smw.py
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
SplitClause
Query parameter to be used for splitting e.g. Modification date, Creation Date, could be potentially any parameter that is ordered and countable Currently we assume a parameter of type Date and use Modification date by default
Source code in wikibot3rd/smw.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
__init__(name='Modification date', label='mdate')
construct me
Source code in wikibot3rd/smw.py
145 146 147 148 149 150 |
|
deserialize(values)
deserialize my query result
Source code in wikibot3rd/smw.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
getFirst()
get the first element
Source code in wikibot3rd/smw.py
167 168 169 170 171 172 |
|
queryBounds(lowerBound, upperBound)
get the query bounds e.g. [[Modification date::>=2021-01-01T12:00
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lowerBound(datetime) |
start of the time interval |
required | |
upperBound(datetime) |
end of the time interval |
required |
Returns:
Type | Description |
---|---|
str
|
Returns the SMW ask part for the boundary |
Source code in wikibot3rd/smw.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
sso
Created on 2024-01-22
@author: wf
with ChatGPT-4 prompting
SSO
A class to implement MediaWiki single sign-on support.
This class provides functionality to connect to a MediaWiki database, verify user credentials, and handle database connections with pooling.
Attributes:
Name | Type | Description |
---|---|---|
host |
str
|
The host of the MediaWiki database. |
database |
str
|
The name of the MediaWiki database. |
sql_port |
int
|
The SQL port for the database connection. |
db_username |
Optional[str]
|
The database username. |
db_password |
Optional[str]
|
The database password. |
with_pool |
bool
|
Flag to determine if connection pooling is used. |
timeout |
float
|
The timeout for checking SQL port availability. |
debug |
Optional[bool]
|
Flag to enable debug mode. |
Source code in wikibot3rd/sso.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
__init__(host, database, sql_port=3306, db_username=None, db_password=None, with_pool=True, timeout=3, debug=False)
Constructs all the necessary attributes for the SSO object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
The host of the MediaWiki database. |
required |
database |
str
|
The name of the MediaWiki database. |
required |
sql_port |
int
|
The SQL port for the database connection. |
3306
|
db_username |
Optional[str]
|
The database username. |
None
|
db_password |
Optional[str]
|
The database password. |
None
|
with_pool |
bool
|
Flag to determine if connection pooling is used. |
True
|
timeout |
float
|
The timeout for checking SQL port availability. |
3
|
debug |
Optional[bool]
|
Flag to enable debug mode. |
False
|
Source code in wikibot3rd/sso.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
check_credentials(username, password)
Checks the validity of MediaWiki username and password.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username |
str
|
The MediaWiki username. |
required |
password |
str
|
The password to verify. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the credentials are valid, False otherwise. |
Source code in wikibot3rd/sso.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
check_port()
Checks if the specified SQL port is accessible on the configured host.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the port is accessible, False otherwise. |
Source code in wikibot3rd/sso.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
fetch_user_data_from_database(mw_username)
Fetch user data from the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mw_username(str) |
the Mediawiki username |
required |
Source code in wikibot3rd/sso.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
get_pool()
Creates a connection pool for the database.
Returns:
Name | Type | Description |
---|---|---|
MySQLConnectionPool |
MySQLConnectionPool
|
A pool of database connections. |
Source code in wikibot3rd/sso.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
get_user(username)
Retrieve details of a user by username. Returns a User object if found, otherwise None.
Source code in wikibot3rd/sso.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
verify_password(password, hash_value)
Verifies a password against a stored hash value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password |
str
|
The password to verify. |
required |
hash_value |
str
|
The stored hash value to compare against. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the password matches the hash value, False otherwise. |
Source code in wikibot3rd/sso.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
User
Mediawiki user details
Source code in wikibot3rd/sso.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
version
Created on 2022-03-24
@author: wf
Version
Bases: object
Version handling for py-3rdparty-mediawiki
Source code in wikibot3rd/version.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
wiki
Created on 2020-11-05
@author: wf
Wiki
Bases: object
common interface for WikiBot and WikiClient
Source code in wikibot3rd/wiki.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
__init__(wikiUser, debug=False, smw_enabled=True)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wikiUser(WikiUser) |
the wiki user to initialize me for |
required |
Source code in wikibot3rd/wiki.py
13 14 15 16 17 18 19 20 21 22 |
|
__str__()
return a string representation of myself
Source code in wikibot3rd/wiki.py
24 25 26 27 28 29 30 31 |
|
wikiaction
Created on 2021-02-02
@author: wf
WikiAction
Bases: object
perform an action on the given semantic media wiki
Source code in wikibot3rd/wikiaction.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
__init__(smw, debug=False)
Constructor
Source code in wikibot3rd/wikiaction.py
17 18 19 20 21 22 23 |
|
getLambdaAction(name, queryName, actionName)
get an action from the result with the given query and actionName
Source code in wikibot3rd/wikiaction.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
wikibackup
Created on 2020-12-05
@author: wf
wikibot
Created on 2020-03-24
@author: wf
WikiBot
Bases: Wiki
WikiBot
Source code in wikibot3rd/wikibot.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
__init__(wikiUser, debug=False, withLogin=False, maxRetries=2)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wikiUser(WikiUser) |
the wiki user to initialize me for |
required | |
debug(bool) |
True if debug mode should be on |
required | |
withLogin(bool) |
True if init should automatically login |
required |
Source code in wikibot3rd/wikibot.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
checkFamily()
check if a valid family file exists and if not create it
watch out for https://stackoverflow.com/questions/76612838/how-to-work-with-custom-wikibase-using-pywikibot 8.2 changes that might break old family files
Source code in wikibot3rd/wikibot.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
getHtml(pageTitle)
get the HTML code for the given page Title
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitle(str) |
the title of the page to retrieve |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
the rendered HTML code for the page |
Source code in wikibot3rd/wikibot.py
179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
getPage(pageTitle)
get the page with the given title Args: pageTitle(str): the title of the page to retrieve Returns: Page: the wikibot3rd page for the given pageTitle
Source code in wikibot3rd/wikibot.py
193 194 195 196 197 198 199 200 201 |
|
getWikiMarkup(pageTitle)
get the wiki markup code (text) for the given page Title
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitle(str) |
the title of the page to retrieve |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
the wiki markup code for the page |
Source code in wikibot3rd/wikibot.py
165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
register_family_file(familyName, famfile)
register the family file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family(str) |
the familyName to register |
required | |
famfile(str) |
the path to the family file |
required |
Source code in wikibot3rd/wikibot.py
88 89 90 91 92 93 94 95 96 97 98 |
|
savePage(pageTitle, pageContent, pageSummary)
save a page with the given pageTitle, pageContent and pageSummary
Source code in wikibot3rd/wikibot.py
203 204 205 206 207 |
|
wikiclient
WikiClient
Bases: Wiki
Access MediaWiki via mwclient library.
Source code in wikibot3rd/wikiclient.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
__init__(wiki_user, debug=False, smw_enabled=True)
Initialize the WikiClient with a WikiUser and an optional debug mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wiki_user |
WikiUser
|
A WikiUser instance containing login credentials. |
required |
debug |
bool
|
A flag to enable debug mode. |
False
|
Source code in wikibot3rd/wikiclient.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
getClients()
staticmethod
Deprecated: Use get_clients instead.
Source code in wikibot3rd/wikiclient.py
217 218 219 220 |
|
getHtml(pageTitle)
Deprecated: Use get_html instead.
Source code in wikibot3rd/wikiclient.py
144 145 146 |
|
getPage(pageTitle)
Deprecated: Use get_page instead.
Source code in wikibot3rd/wikiclient.py
161 162 163 |
|
getSite()
Deprecated: Use get_site instead.
Source code in wikibot3rd/wikiclient.py
50 51 52 |
|
getSiteStatistics()
Deprecated: Use get_site_statistics instead.
Source code in wikibot3rd/wikiclient.py
199 200 201 |
|
getWikiMarkup(pageTitle)
Deprecated: Use get_wiki_markup instead.
Source code in wikibot3rd/wikiclient.py
124 125 126 |
|
get_clients()
staticmethod
Get a dictionary of WikiClient instances for all WikiUsers.
Returns:
Type | Description |
---|---|
Dict[str, WikiClient]
|
Dict[str, WikiClient]: A dictionary with wiki user IDs as keys and WikiClient instances as values. |
Source code in wikibot3rd/wikiclient.py
203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
get_html(page_title)
Get the HTML content for a given page title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_title |
str
|
The title of the page to retrieve the HTML for. |
required |
Returns:
Type | Description |
---|---|
str
|
The HTML content of the specified page. |
Source code in wikibot3rd/wikiclient.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
get_page(page_title)
Get the page object for a given title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_title |
str
|
The title of the page to retrieve. |
required |
Returns:
Type | Description |
---|---|
Any
|
The page object for the specified title. |
Source code in wikibot3rd/wikiclient.py
148 149 150 151 152 153 154 155 156 157 158 159 |
|
get_site()
Get the Site object for the MediaWiki site.
Returns:
Type | Description |
---|---|
Site
|
The Site object representing the MediaWiki site. |
Source code in wikibot3rd/wikiclient.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
get_site_statistics()
Fetch site statistics using the MediaWiki API.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary containing the site statistics. |
Source code in wikibot3rd/wikiclient.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
get_wiki_markup(page_title)
Get the wiki markup for a given page title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_title |
str
|
The title of the page to retrieve the markup for. |
required |
Returns:
Type | Description |
---|---|
str
|
The wiki markup of the specified page. |
Source code in wikibot3rd/wikiclient.py
110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
login()
Attempt to log in to the MediaWiki site.
Returns:
Type | Description |
---|---|
bool
|
True if login is successful, False otherwise. |
Source code in wikibot3rd/wikiclient.py
97 98 99 100 101 102 103 104 105 106 107 108 |
|
needsLogin()
Deprecated: Use needs_login instead.
Source code in wikibot3rd/wikiclient.py
77 78 79 |
|
needs_login()
Check if login is required for the wiki.
Returns:
Type | Description |
---|---|
bool
|
True if login is required, False otherwise. |
Source code in wikibot3rd/wikiclient.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
ofWikiId(wiki_id, lenient=True, debug=False)
staticmethod
Deprecated: Use of_wiki_id instead.
Source code in wikibot3rd/wikiclient.py
242 243 244 245 246 247 |
|
ofWikiUser(wiki_user, debug=False)
staticmethod
Deprecated: Use of_wiki_user instead.
Source code in wikibot3rd/wikiclient.py
264 265 266 267 |
|
of_wiki_id(wiki_id, lenient=True, debug=False)
staticmethod
Create a WikiClient instance for a specific wiki ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wiki_id |
str
|
The ID of the wiki to create a client for. |
required |
lenient |
bool
|
Whether to be lenient in case of errors. |
True
|
debug |
bool
|
Whether to enable debug output. |
False
|
Returns:
Name | Type | Description |
---|---|---|
WikiClient |
WikiClient
|
A WikiClient instance for the given wiki ID. |
Source code in wikibot3rd/wikiclient.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
of_wiki_user(wiki_user, debug=False)
staticmethod
Create a WikiClient instance from a WikiUser object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wiki_user |
WikiUser
|
A WikiUser instance to create a WikiClient for. |
required |
Returns:
Name | Type | Description |
---|---|---|
WikiClient |
WikiClient
|
A WikiClient instance for the given WikiUser. |
Source code in wikibot3rd/wikiclient.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
savePage(pageTitle, pageContent, pageSummary)
Deprecated: Use save_page instead.
Source code in wikibot3rd/wikiclient.py
177 178 179 |
|
save_page(page_title, page_content, page_summary)
Save a page with given title and content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_title |
str
|
The title of the page. |
required |
page_content |
str
|
The new content of the page. |
required |
page_summary |
str
|
A summary of the changes made. |
required |
Source code in wikibot3rd/wikiclient.py
165 166 167 168 169 170 171 172 173 174 175 |
|
try_login()
Attempt to log in to the MediaWiki site.
Returns:
Name | Type | Description |
---|---|---|
Exception |
Exception
|
None if login is successful, Exception otherwise. |
Source code in wikibot3rd/wikiclient.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
wikiedit
Created on 2020-11-12
@author: wf
wikinuke
Created on 2020-11-12
@author: wf
wikipush
Created on 2020-10-29 @author: wf @copyright: Wolfgang Fahl. All rights reserved.
WikiPush
Bases: object
Push pages from one MediaWiki to another
Source code in wikibot3rd/wikipush.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
|
__init__(fromWikiId, toWikiId=None, login=False, verbose=True, debug=False)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fromWikiId(str) |
the id of the wiki to push from (source) |
required | |
toWikiID(str) |
the id of the wiki to push to (target) |
required | |
login(bool) |
if True login to source wiki |
required | |
verbose(bool) |
if True print info messages |
required | |
debug(bool) |
if True show debugging messages |
required |
Source code in wikibot3rd/wikipush.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
backup(pageTitles, backupPath=None, git=False, withImages=False)
backup the given page titles Args: pageTitles(list): a list of page titles to be downloaded from the fromWiki git(bool): True if git should be used as a version control system withImages(bool): True if the image on a page should also be copied
Source code in wikibot3rd/wikipush.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
backupImages(imageList, imageBackupPath)
backup the images in the givne imageList
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imageList(list) |
the list of images |
required | |
imageBackupPath(str) |
the path to the backup directory |
required |
Source code in wikibot3rd/wikipush.py
623 624 625 626 627 628 629 630 631 632 633 634 635 |
|
convertToCSV(pageRecords, separator=';')
Converts the given pageRecords into a str in csv format ToDO: Currently does not support escaping of the separator and escaping of quotes Args: pageRecords: dict of dicts containing the printouts separator(char): Returns: str
Source code in wikibot3rd/wikipush.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
downloadImage(image, downloadPath=None)
download the given image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image(image) |
the image to download |
required | |
downloadPath(str) |
the path to download to if None getDownloadPath will be used |
required |
Source code in wikibot3rd/wikipush.py
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
|
edit(page_titles, modify=None, context=1, force=False)
Edit the pages with the given page titles
Args: page_titles (list): a list of page titles to be transferred from the formWiki to the toWiki modify: String modify function that takes as input the string and returns the modified string context: The number of context lines force (bool): True if pages should be actually edited - dry run only listing pages is default
Source code in wikibot3rd/wikipush.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
|
edit_page_content(page_title, new_text=None, summary='edited by wikiedit', modify=None, force=False, context=1)
Edit the content of a single page.
Args: page_title (str): The title of the page to be edited new_text (str): the new text for the page summary (str): the summary / comment for the editing modify (Callable[[str], str]): Function to modify the page content force (bool): If True, actually edit the page; if False, perform a dry run context (int): The number of context lines for diff
Returns: str: Status of the edit operation
Source code in wikibot3rd/wikipush.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
edit_wikison(page_titles, entity_type_name, property_name, value, force=False)
Edit the WikiSON for on the given pages Args: page_titles: a list of page titles to be edited entity_type_name: name of the WikiSON entity type property_name: name of the property to edit value: value to set. If None property is deleted from the WikiSON force: If False only print the changes. Otherwise, apply the changes
Source code in wikibot3rd/wikipush.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
|
ensureDirectoryExists(directory)
make sure the given directory exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory(str) |
the directory to check for existence |
required |
Source code in wikibot3rd/wikipush.py
729 730 731 732 733 734 735 736 |
|
ensureParentDirectoryExists(filePath)
for pages that have a "/" in the name make sure that the parent Directory exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filePath(str) |
the filePath to check |
required |
Source code in wikibot3rd/wikipush.py
719 720 721 722 723 724 725 726 727 |
|
extract_category_and_mainlabel(askQuery, category_labels=['Category', 'Kategorie', 'Catégorie', 'Categoría'])
Extracts the category pattern and mainlabel from a MediaWiki query, supporting multiple language labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
askQuery |
str
|
The query string to be processed. |
required |
category_labels |
List[str]
|
A list of category labels in different languages (default: ['Category', 'Kategorie', 'Catégorie', 'Categoría']). |
['Category', 'Kategorie', 'Catégorie', 'Categoría']
|
Returns:
Type | Description |
---|---|
Optional[Tuple[str, Optional[str]]]
|
Optional[Tuple[str, Optional[str]]]: A tuple containing the category pattern and |
Optional[Tuple[str, Optional[str]]]
|
the mainlabel if present. Returns None if the query does not match a category pattern. |
Source code in wikibot3rd/wikipush.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
extract_template_records(pageRecords, template)
Extract template records from the given pageRecords using batch page retrieval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageRecords |
dict
|
Dictionary with page titles as keys |
required |
template |
str
|
Name of the template to extract (e.g., "Infobox officeholder") |
required |
Returns:
Type | Description |
---|---|
list
|
list[dict]: List of template records, where each record is a dictionary containing the template parameters. Returns None for pages where the template is not found. |
Example
pageRecords = {"John Adams": {}, "Thomas Jefferson": {}} records = extract_template_records(pageRecords, "Infobox officeholder")
Source code in wikibot3rd/wikipush.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
formatQueryResult(askQuery, wiki=None, limit=None, showProgress=False, queryDivision=1, outputFormat='lod', entityName='data', title=None)
format the query result for the given askQuery. Args: askQuery(string): Semantic Media Wiki in line query https://www.semantic-mediawiki.org/wiki/Help:Inline_queries wiki(wikibot3rd): the wiki to query - use fromWiki if not specified limit(int): the limit for the query (optional) showProgress(bool): true if progress of the query retrieval should be indicated (default: one dot per 50 records ...) queryDivision(int): Defines the number of subintervals the query is divided into (must be greater equal 1) outputFormat(str): output format of the query results - default format is lod entityName(str): the name of the entity title(str): the title of the query (if any) Returns: Query results in the requested outputFormat as string. If the requested outputFormat is not supported None is returned.
Source code in wikibot3rd/wikipush.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
getDiff(text, newText, n=1, forHuman=True)
staticmethod
Compare the two given strings and return the differences Args: text: old text to compare the new text to newText: new text n: The number of context lines forHuman: If True update the diff string to be better human-readable
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
difference string |
Source code in wikibot3rd/wikipush.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
getDownloadPath()
get the download path
Source code in wikibot3rd/wikipush.py
746 747 748 749 750 |
|
getHomePath(localPath)
get the given home path
Source code in wikibot3rd/wikipush.py
738 739 740 741 742 743 744 |
|
getModify(search, replace, debug=False)
staticmethod
get the modification function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search(str) |
the search string |
required | |
replace(str) |
the replace string |
required | |
debug(bool) |
if debug show |
required |
Returns:
Type | Description |
---|---|
Callable[[str], str]
|
String modify function that takes as input the string, applies the search and replace action and returns the modified string |
Source code in wikibot3rd/wikipush.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
handleAPIWarnings(warnings, ignoreExists=False)
handle API Warnings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
warnings(list) |
a list of API warnings |
required | |
ignoreExists(bool) |
ignore messages that warn about existing content |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the exception was handled as ok False if it was logged as an error |
Source code in wikibot3rd/wikipush.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
|
handleException(ex, ignoreExists=False)
handle the given exception and ignore it if it includes "exists" and ignoreExists is True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ex(Exception) |
the exception to handle |
required | |
ignoreExists(bool) |
True if "exists" should be ignored |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the exception was handled as ok False if it was logged as an error |
Source code in wikibot3rd/wikipush.py
788 789 790 791 792 793 794 795 796 797 798 799 800 |
|
handleWarning(msg, marker='⚠️', ignoreExists=False)
handle the given warning and ignore it if it includes "exists" and ignoreExists is True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg(string) |
the warning to handle |
required | |
marker(string) |
the marker to use for the message |
required | |
ignoreExists(bool) |
True if "exists" should be ignored |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the exception was handled as ok False if it was logged as an error |
Source code in wikibot3rd/wikipush.py
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
|
log(msg, end='\n')
show the given message if verbose is on
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg(str) |
the message to display |
required |
Source code in wikibot3rd/wikipush.py
88 89 90 91 92 93 94 95 96 |
|
nuke(pageTitles, force=False)
delete the pages with the given page Titles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitles(list) |
a list of page titles to be transfered from the formWiki to the toWiki |
required | |
force(bool) |
True if pages should be actually deleted - dry run only listing pages is default |
required |
Source code in wikibot3rd/wikipush.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
push(pageTitles, force=False, ignore=False, withImages=False)
push the given page titles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitles(list) |
a list of page titles to be transfered from the formWiki to the toWiki |
required | |
force(bool) |
True if pages should be overwritten if they exist |
required | |
ignore(bool) |
True if warning for images should be ignored (e.g if they exist) |
required | |
withImages(bool) |
True if the image on a page should also be copied |
required |
Returns: list: a list of pageTitles for which the activity failed
Source code in wikibot3rd/wikipush.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
|
pushImages(imageList, delim='', ignore=False)
push the images in the given image List
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imageList(list) |
a list of images to be pushed |
required | |
ignore(bool) |
True to upload despite any warnings. |
required |
Source code in wikibot3rd/wikipush.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
|
query(askQuery, wiki=None, pageField=None, limit=None, showProgress=False, queryDivision=1)
query the given wiki for pages matching the given askQuery
Parameters:
Name | Type | Description | Default |
---|---|---|---|
askQuery(string) |
Semantic Media Wiki in line query https://www.semantic-mediawiki.org/wiki/Help:Inline_queries |
required | |
wiki(wikibot3rd) |
the wiki to query - use fromWiki if not specified |
required | |
pageField(string) |
the field to select the pageTitle from |
required | |
limit(int) |
the limit for the query (optional) |
required | |
showProgress(bool) |
true if progress of the query retrieval should be indicated (default: one dot per 50 records ...) |
required |
Returns: list: a list of pageTitles matching the given askQuery
Source code in wikibot3rd/wikipush.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
queryPages(askQuery, wiki=None, limit=None, showProgress=False, queryDivision=1)
query the given wiki for pagerecords matching the given askQuery
Parameters:
Name | Type | Description | Default |
---|---|---|---|
askQuery |
str
|
Semantic Media Wiki in line query https://www.semantic-mediawiki.org/wiki/Help:Inline_queries |
required |
wiki |
wikibot3rd
|
the wiki to query - use fromWiki if not specified |
None
|
limit |
int
|
the limit for the query (optional) |
None
|
showProgress |
bool
|
true if progress of the query retrieval should be indicated (default: one dot per 50 records ...) |
False
|
queryDivision |
int
|
Defines the number of subintervals the query is divided into (must be greater equal 1) |
1
|
Returns: list: a list of pageRecords matching the given askQuery
Source code in wikibot3rd/wikipush.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
restore(pageTitles=None, backupPath=None, listFile=None, stdIn=False)
restore given page titles from local backup If no page titles are given the whole backup is restored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitles(list) |
a list of pageTitles to be restored to toWiki. If None -> full restore of backup |
required | |
backupPath(str) |
path to backup location |
required | |
listFile |
|
None
|
|
stdIn |
|
False
|
Source code in wikibot3rd/wikipush.py
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
|
show_exception(ex)
Show the given exception and, if debug mode is on, show the traceback.
Source code in wikibot3rd/wikipush.py
777 778 779 780 781 782 783 784 785 786 |
|
upload(files, force=False)
push the given files Args: files(list): a list of filenames to be transfered to the toWiki force(bool): True if images should be overwritten if they exist
Source code in wikibot3rd/wikipush.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
uploadImage(imagePath, filename, description, ignoreExists=False)
upload an image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imagePath(str) |
the path to the image |
required | |
filename(str) |
the filename to use |
required | |
description(str) |
the description to use |
required | |
ignoreExists(bool) |
True if it should be ignored if the image exists |
required |
Source code in wikibot3rd/wikipush.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
|
work(pageTitles, activity='copying', comment='pushed', force=False, ignore=False, withImages=False)
work on the given page titles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pageTitles(list) |
a list of page titles to be transfered from the formWiki to the toWiki |
required | |
activity(str) |
the activity to perform |
required | |
comment(str) |
the comment to display |
required | |
force(bool) |
True if pages should be overwritten if they exist |
required | |
ignore(bool) |
True if warning for images should be ignored (e.g if they exist) |
required | |
withImages(bool) |
True if the image on a page should also be copied |
required |
Returns: list: a list of pageTitles for which the activity failed
Source code in wikibot3rd/wikipush.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
main(argv=None, mode='wikipush')
main program.
Source code in wikibot3rd/wikipush.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 |
|
wikiquery
Created on 2024-04-18
@author: wf
wikirestore
Created on 2021-02-16
@author: wf
wikitext
Created on 2023-02-24 @author: tholzheim
WikiMarkup
Provides methods to modify, query and update Templates in wiki markup see https://en.wikipedia.org/wiki/Help:Wikitext
Source code in wikibot3rd/wikitext.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
parsed_wiki_markup: wtp.WikiText
property
writable
Get WikiText. If not already parsed the markup is parsed
Returns:
Name | Type | Description |
---|---|---|
wtp |
WikiText
|
WikiText |
wiki_markup: str
property
writable
Get wiki markup. If wikimarkup was parsed the parsed markup is converted back to wiki markup
Returns:
Type | Description |
---|---|
str
|
str |
__init__(page_title, wiki_markup=None, debug=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_title |
str
|
page title of the wiki_markup file |
required |
wiki_markup |
str
|
WikiPage content as string. If None tries to init the wiki_markup from source location |
None
|
Source code in wikibot3rd/wikitext.py
19 20 21 22 23 24 25 26 27 28 29 |
|
add_template(template_name, data)
Adds the given data as template with the given name to this wikifile. The data is added as new template object to the wikifile. Args: template_name(str): Name of the template the data should be inserted in data(dict): Data that should be saved in form of a template
Source code in wikibot3rd/wikitext.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
extract_template(template_name, match=None)
Extracts the template data and returns it as dict
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template_name |
str
|
name of the template that should be extracted |
required |
match(dict) |
Additional matching criteria |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
list of dicts: records of the templates that match the given name |
Source code in wikibot3rd/wikitext.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
update_template(template_name, args, overwrite=False, update_all=False, match=None)
Updates the given template the values from the given dict args. If force is set to True existing values will be overwritten. Args: template_name(str): name of the template that should be updated args(dict): Dict containing the arguments that should be set. key=argument name, value=argument value overwrite(bool): If True existing values will be overwritten update_all(bool): If True all matching attributes are updated. Otherwise, only one template is updated if matched multiple an error is raised. match(dict): matching criteria for the template.
Returns:
Type | Description |
---|---|
Nothing |
Source code in wikibot3rd/wikitext.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
WikiSON
WikiSON Api to edit WikiSON entities
Source code in wikibot3rd/wikitext.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
__init__(page_title, wiki_markup)
constructor Args: page_title: name of the wiki page wiki_markup: markup of the wiki page
Source code in wikibot3rd/wikitext.py
230 231 232 233 234 235 236 237 |
|
get(entity_type_name)
Get the WikiSON entity by the given name Args: entity_type_name: name of the WikiSON entity type e.g. Scholar, Event
Raises:
Type | Description |
---|---|
Exception
|
if wiki markup contains more than one WikiSON with the same entity type name |
Returns:
Name | Type | Description |
---|---|---|
dict |
Optional[Dict[str, str]]
|
record of the entity |
Source code in wikibot3rd/wikitext.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
set(entity_type_name, record)
Set WikiSON entity with the given type and data Args: entity_type_name: name of the WikiSON entity type e.g. Scholar, Event record: data to add to the WikiSON entity
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
wiki markup of the page |
Source code in wikibot3rd/wikitext.py
262 263 264 265 266 267 268 269 270 271 272 273 |
|
wikiupload
Created on 2020-11-12
@author: wf
wikiuser
Created on 2020-11-01
@author: wf
WikiCredentials
dataclass
Base class for wiki credentials
Source code in wikibot3rd/wikiuser.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
encrypted: bool
property
Property to check if the credentials are encrypted.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the credentials are encrypted, False otherwise. |
__post_init__()
if a password is available immediately encrypt it
Source code in wikibot3rd/wikiuser.py
34 35 36 37 38 39 40 |
|
decrypt()
Decrypt and return the password
Source code in wikibot3rd/wikiuser.py
67 68 69 70 71 72 73 74 75 |
|
encrypt(password)
Encrypt the given password
Source code in wikibot3rd/wikiuser.py
58 59 60 61 62 63 64 65 |
|
get_password()
get my decrypted password
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the decrypted password for this user |
Source code in wikibot3rd/wikiuser.py
77 78 79 80 81 82 83 84 85 86 87 |
|
WikiUser
dataclass
Bases: WikiUserData
WikiUser handling
Source code in wikibot3rd/wikiuser.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
ask_password()
Ask the user for a password twice to ensure it is entered correctly.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The confirmed password entered by the user. |
Source code in wikibot3rd/wikiuser.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
getIniPath()
staticmethod
get the path for the ini file
Source code in wikibot3rd/wikiuser.py
233 234 235 236 237 238 |
|
getInteractiveFields()
Get the non-credential fields from WikiUserData plus 'password' for interactive input.
Source code in wikibot3rd/wikiuser.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
getWikiUrl()
return the full url of this wiki
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the full url of this wiki |
Source code in wikibot3rd/wikiuser.py
140 141 142 143 144 145 146 147 |
|
getWikiUsers(lenient=False)
classmethod
get all WikiUsers from the ini files in the iniPath
Source code in wikibot3rd/wikiuser.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
get_wiki_url()
return the full url of this wiki
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the full url of this wiki |
Source code in wikibot3rd/wikiuser.py
131 132 133 134 135 136 137 138 |
|
iniFilePath(wikiId)
staticmethod
get the path for the ini file for the given wikiId
Source code in wikibot3rd/wikiuser.py
240 241 242 243 244 245 246 247 |
|
interactiveSave(yes=False, interactive=False, filePath=None)
save me
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yes |
bool
|
if True save without asking |
False
|
interactive |
bool
|
if True get interactive input |
False
|
filePath |
str
|
the path where to save the credentials ini file |
None
|
Source code in wikibot3rd/wikiuser.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
ofDict(userDict, encrypted=True, lenient=False, encrypt=True)
classmethod
create a WikiUser from the given dictionary
Args: userDict (dict): dictionary with WikiUser properties encrypted(bool): if True the password is encrypted in the dict lenient (bool): if True ignore missing fields encrypt (bool): if True encrypt the password (if not encrypted yet)
Returns: WikiUser: the WikiUser created from the dictionary
Source code in wikibot3rd/wikiuser.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
ofWikiId(wikiId, lenient=False)
classmethod
create a wikiUser for the given wikiId
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wikiId |
str
|
the wikiId of the user to be created |
required |
lenient |
bool
|
if True ignore parsing errors in the ini file |
False
|
Returns:
Name | Type | Description |
---|---|---|
WikiUser |
WikiUser
|
the wikiUser for this wikiId |
Source code in wikibot3rd/wikiuser.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
readPropertyFile(filepath, sep='=', comment_char='#')
staticmethod
Read the file passed as parameter as a properties file.
https://stackoverflow.com/a/31852401/1497139
Source code in wikibot3rd/wikiuser.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
save(iniFilePath=None)
save me to a propertyFile
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the path of the property file |
Source code in wikibot3rd/wikiuser.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
WikiUserData
dataclass
Bases: WikiCredentials
User credentials for a specific wiki
Source code in wikibot3rd/wikiuser.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
wikiuser_cmd
Created on 2024-09-26
@author: wf
main(argv=None)
WikiUser credential handling
Source code in wikibot3rd/wikiuser_cmd.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|