Skip to content
Merged

Next #16

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
30 changes: 21 additions & 9 deletions content/docs/libraries/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A simple API wrapper for [Topstats.gg](https://topstats.gg) written in Python.

## Getting started

Make sure you already have an API token handy. See [this page](https://docs.topstats.gg/authentication/tokens) on how to retrieve it.
Make sure you already have an API token handy. See [this page](https://docs.topstats.gg/docs/authentication/tokens) on how to retrieve it.

After that, run the following command in your terminal:

Expand All @@ -38,33 +38,45 @@ import os


async def main() -> None:

# Declare the client.
async with topstats.Client(os.getenv('TOPSTATS_TOKEN')) as ts:

# Fetch a bot from its ID.
bot = await ts.get_bot(432610292342587392)

print(bot)

# Fetch topstats.gg's top bots.
bots = await ts.get_top_bots(sort_by=topstats.SortBy.server_count())

for b in bots:
print(b)

# Search for bots that has the name 'MEE6.'
mee6_bots = await ts.search_bots(name='MEE6')

for b in mee6_bots:
print(b)

# Search for anime-tagged bots.
anime_bots = await ts.search_bots(tag='anime')

for b in anime_bots:
print(b)

# Fetch a bot's historical server count.
sc = await ts.get_historical_bot_server_count(432610292342587392)

for server_count in sc:
print(server_count)

# Compare two bots' historical server count.
vs = await ts.compare_bot_server_count(432610292342587392, 437808476106784770)

for first, second in vs:
print(first, second)

# Compare up to four bots' historical total vote count.
vs2 = await ts.compare_bot_total_votes(
topstats.Period.LAST_YEAR,
Expand All @@ -78,11 +90,11 @@ async def main() -> None:
print(first, second, third, fourth)

if __name__ == '__main__':

# See https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
# for more details.
if os.name == 'nt':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

asyncio.run(main())
```