Synchronous / Asynchronous HTTPX extension for NationStates
Project description
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
Release history Release notifications | RSS feed
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.1.0.tar.gz
(24.9 kB
view hashes)
Built Distribution
sans-1.1.0-py3-none-any.whl
(18.8 kB
view hashes)