Campfire API basic functions
Project description
This module includes several basic functions for asynchronously sending and receiving data from Campfire server. It can also receive push notifications.
Installation
Using pip
command:
pip install campfire-basic
Clone this repository using git
command:
git clone https://github.com/Camper-CoolDie/campfire-basic
Examples
Requesting
import campfire
import asyncio
async def main():
print(await campfire.send("RProjectVersionGet"))
# {'ABParams': {}, 'version': '1.290'}
asyncio.run(main())
Code above gets current version of Campfire.
Log in
A lot of requests will raise exception if user is not logged in.
import campfire
import asyncio
req = {
"fandomId": 10,
"languageId": 1
}
async def main():
print(await campfire.send("RFandomsGet", req))
# ApiRequestException: Error occurred while processing request ("ERROR_UNAUTHORIZED")
log = campfire.login("email", "password")
print(await log.send("RFandomsGet", req))
# {'fandom': {'subscribesCount': 1105, 'imageId'...
asyncio.run(main())
Receiving notifications
You can receive all notifications Campfire server sending to you.
import campfire
log = campfire.login("email", "password")
# Generate FCM token
token = campfire.token()
async def main():
# Send token to Campfire server if it is not added
if not token.exists():
await log.send("RAccountsAddNotificationsToken", {"token": ntoken.fcm})
# Listen to notifications
def notifi(n):
print(notifi)
await campfire.listen(token, notifi)
print("It works asynchronously!")
asyncio.run(main())
Or, wait for notification:
import campfire
import asyncio
log = campfire.login("email", "password")
token = campfire.token()
async def main():
if not token.exists():
await log.send("RAccountsAddNotificationsToken", {"token": token})
# Wait for notification
async with campfire.wait(token) as n:
print(n)
# With filter (wait for subscriber)
async with campfire.wait(token, {"J_N_TYPE": 4}) as n:
print(n["account"]["J_NAME"])
# Timeout!
try:
async with campfire.wait(token, {}, 15.0) as n:
print(n)
except asyncio.TimeoutError:
print("Time is out")
asyncio.run(main())
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
campfire-basic-1.1.0.tar.gz
(22.4 kB
view hashes)
Built Distribution
Close
Hashes for campfire_basic-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6782f474e0daacb5b91d1fc475705ccb203b94b1f5b9fa198202f57392b24f24 |
|
MD5 | 68244b0b557f1040e645b2eb2961ce77 |
|
BLAKE2b-256 | d0936e75d0143dc9270cd342ad119e8a27a2ba0f91f9c79d92c1b0cc9485c407 |