MediaWiki API result

This is the HTML representation of the JSON format. HTML is good for debugging, but is unsuitable for application use.

Specify the format parameter to change the output format. To see the non-HTML representation of the JSON format, set format=json.

See the complete documentation, or the API help for more information.

{
    "batchcomplete": "",
    "continue": {
        "gapcontinue": "SEAICE_tutorial",
        "continue": "gapcontinue||"
    },
    "warnings": {
        "main": {
            "*": "Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."
        },
        "revisions": {
            "*": "Because \"rvslots\" was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used."
        }
    },
    "query": {
        "pages": {
            "204": {
                "pageid": 204,
                "ns": 0,
                "title": "ReadTheDocs",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "[https://readthedocs.org/ Read the docs] is a simple yet powerful tool for creating effective online technical documentation. It's used by many large projects, for example the [http://mitgcm.rtfd.io MITgcm documentation] is moving to RTD. Getting started with documentation on RTD is straightforward, and it integrates seamlessly with git. This means your documentation can be version controlled alongside your code base. No more excuses for out of date documentation!\n\nThis page will not go through setting up Markdown or Sphinx documentation with ReadTheDocs. The [https://docs.readthedocs.io/en/latest/getting_started.html Getting started guide] is a great resource. For an example of Markdown documentation, see the [http://gcmpy.rtfd.io gcmpy docs] and [https://git.uwaterloo.ca/tghill/gcmpy code repo]. This page will provide some tips about integrating RTD with the UW fluids gitlab group (see [[Git]] page for more detail on this group).\n\n'''Caution: the instructions here rely on making your repository public. Only proceed if this is okay for your project!'''\n\n== Integrating with gitlab ==\n\nIt is relatively easy to integrate RTD with your code base on the gitlab group. Navigate to your repository home, click into the settings menu (gear icon in top left), and go to '''Edit Project'''. Change the '''Visibility Level''' to Public and change '''Feature Visibility --> Repository''' to \"Everyone with access\".\n\nIf you are creating a new project on RTD, specify the gitlab project URL when it asks for a URL to import from. If you are modifying an existing RTD project (for instance, moving from a GitHub repo to the group GitLab), navigate to '''Admin --> Settings --> Repository URL''' and put in your gitlab project URL.\n\n=== Adding a webhook ===\n\nYou might have to add your own webhook. This triggers your online docs to update when you push to the git repository.\n\nOn RTD, navigate to '''Admin --> Integrations''' and select \"Add integration\". Choose \"GitLab incoming webhook\" from the drop-down menu. Follow the link it gives you, and copy the URL when the page loads.\n\nGo to your GitLab repo, and from the drop-down settings menu choose '''Webhooks'''. Paste the URL into the URL box, and leave the other settings as they are. Select \"Add webhook\". That should be it!\n\nNow commit some changes to your docs, and go to your RTD project page. You should see it rebuilding your documentation like magic. If everything builds, you're done! Now any time you update your repo, your online docs will update.\n\nIf this doesn't work, RTD has some helpful troubleshooting tips. Navigate to the webhook you added on RTD, and you should see a link to help documentation. Good luck!"
                    }
                ]
            },
            "44": {
                "pageid": 44,
                "ns": 0,
                "title": "Replaceutil.py",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "== Find & Replace in text files using Python ==\n\nFor a number of reasons it may be useful to have a script automatically find and replace certain strings in text files (namelists, source code files, etc.). Below we look at how to use python to do just that.\n\nThe first thing we'll need is the Python file '''replaceutil.py''' (source: http://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python), the code is as follows:\n\n<syntaxhighlight lang=\"python\">\nfrom tempfile import mkstemp\nfrom shutil import move\nfrom os import remove, close\n\ndef replace(file, pattern, subst):\n    #Create temp file\n    fh, abs_path = mkstemp()\n    new_file = open(abs_path,'w')\n    old_file = open(file)\n    for line in old_file:\n        new_file.write(line.replace(pattern, subst))\n    #close temp file\n    new_file.close()\n    close(fh)\n    old_file.close()\n    #Remove original file\n    remove(file)\n    #Move new file\n    move(abs_path, file)\n</syntaxhighlight>\n\nWe have now created a custom python module called 'replaceutil' that we can import into our own scripts. '''replaceutil.py''' makes use of three other pre-existing python modules 'tempfile', 'shutil' (shell utilities), and 'os' (for command-line tasks).\n\n== A toy example usage ==\n\nTo test out replaceutil, let's use the UNIX command-line to quickly create a short text file ('''temp.txt''') we would like to have replaceutil edit:\n<syntaxhighlight lang=\"bash\">\n$ echo \"I like amath.\" > temp.txt\n</syntaxhighlight>\n\nWe can check that this was done correctly by:\n<syntaxhighlight lang=\"bash\">\n$ cat temp.txt\nI like amath.\n</syntaxhighlight>\n\nNow (in the same directory) let's create our own python script that will import '''replaceutil.py''' and modify the file '''temp.txt'''. Let's call it '''testreplace.py''', and it's code will be as follows:\n\n<syntaxhighlight lang=\"python\">\nimport replaceutil as ru\n\nmyfile = \"temp.txt\"\npattern = \"amath\"\nsubst = \"cabbage\"\n    \nprint \"Replacing instances of\", pattern, \"with\", subst, \"in\", myfile, \"...\"\nru.replace(myfile,pattern,subst)\nprint \"Done.\"\n</syntaxhighlight>\n\nWe can run '''testreplace.py''' from the command-line via\n\n<syntaxhighlight lang=\"bash\">\n$ python testreplace.py \n</syntaxhighlight>\n<code>\nReplacing instances of amath with cabbage in temp.txt ...<br>\nDone. <br>\n</code>\n\nAlternatively, we could have run it as an executable '''./testreplace.py''' by inserting the bang '''#!/usr/bin/python''' at the top of '''testreplace.py''' and switching on the executable bit using '''chmod a+x testreplace.py'''.\n\nTo check that '''testreplace.py''' did what we wanted it do, let's check the contents of '''temp.txt''':\n\n<syntaxhighlight lang=\"bash\">$ cat temp.txt</syntaxhighlight>\n<code>I like cabbage.</code>\n\nAnd we see that the word \"amath\" has been replaced with \"cabbage\", as desired.\n\n(TODO: Show a more practical application of this for e.g., automated parameter-sweeps in model runs)"
                    }
                ]
            }
        }
    }
}