Skip to main content

Synchronous / Asynchronous HTTPX extension for NationStates

Project description

pypi version Code style: black pre-commit.ci status Documentation Status

Synchronous / Asynchronous NationStates

An extension for HTTPX for the NationStates API

Installing

python3 -m pip install -U sans

Development version:

python3 -m pip install -U https://github.com/zephyrkul/sans/archive/master.zip#egg=sans

Examples

Synchronous

import sans
from xml.etree import ElementTree as ET

def main():
   sans.set_agent("Darcania")
   request = sans.Nation(
      "darcania",
      "fullname population flag census",
      mode="score",
      scale="65 66",
   )
   root = sans.get(request)
   sans.indent(root)
   print(ET.tostring(root, encoding="unicode"))

   with sans.stream("GET", sans.RegionsDump()) as response:
      for region in response.iter_xml():
         sans.indent(region)
         print(ET.tostring(region, encoding="unicode"))

if __name__ == "__main__":
   main()

Asynchronous

import asyncio
import sans
from xml.etree import ElementTree as ET

async def main():
   sans.set_agent("Darcania")
   async with sans.AsyncClient() as client:
      request = sans.Nation(
         "darcania",
         "fullname population flag census",
         mode="score",
         scale="65 66",
      )
      root = (await client.send(request)).xml
      sans.indent(root)
      print(ET.tostring(root, encoding="unicode"))

      async with client.stream("GET", sans.RegionsDump()) as response:
         async for region in response.aiter_xml():
            sans.indent(region)
            print(ET.tostring(region, encoding="unicode"))

if __name__ == "__main__":
   asyncio.run(main())

Command Line

$ sans --nation darcania census --scale "65 66" --mode score --agent Darcania

<CENSUS>
   <SCALE id="65">
      <SCORE>4949.00</SCORE>
   </SCALE>
   <SCALE id="66">
      <SCORE>130.00</SCORE>
   </SCALE>
</CENSUS>

$ sans --nation testlandia fullname

<FULLNAME>The Hive Mind of Testlandia</FULLNAME>

sans --region "the north pacific" numnations lastupdate

<LASTUPDATE>1683650325</LASTUPDATE>
<NUMNATIONS>10503</NUMNATIONS>

$ sans --quit
No query provided. Exiting...

Requirements

  • Python 3.7+

  • httpx

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sans-1.0.0.tar.gz (24.7 kB view hashes)

Uploaded Source

Built Distribution

sans-1.0.0-py3-none-any.whl (18.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page