-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe_to_updates.py
33 lines (25 loc) · 1.19 KB
/
subscribe_to_updates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
""" Subscribe to updates example
Prerequiste:
- Create a Plurk app at https://www.plurk.com/PlurkApp/create)
What this example script does:
1. Perform OAuth with pre-fetched tokens.
2. Use the helper function to run indefintely and print all received updates.
Note that using hardcoded credentials is a bad practice.
The script here is only for demonstration purpose, do not use it without modification in production.
"""
from plurk import Client
from plurk.models import NewPlurk, NewResponse
APP_KEY = '<your-plurk-app-key>'
APP_SECRET = '<your-plurk-app-secret>'
TOKEN = '<your-bot-user-token>'
TOKEN_SECRET = '<your-bot-user-token-secret>'
with Client(APP_KEY, APP_SECRET) as client:
# Set app user's access token directly
client.set_access_token(TOKEN, TOKEN_SECRET)
print('Subscribed to timeline updates...')
for channel_data in client.helpers.subscribe_to_user_channel():
for entry in channel_data.data:
if isinstance(entry, NewPlurk):
print(f'New plurk detected. plurk_id: {entry.plurk_id}, content_raw: {entry.content_raw}')
elif isinstance(entry, NewResponse):
print(f'New response detected. plurk_id: {entry.plurk_id}')