forked from freelancer/freelancer-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_threads.py
38 lines (31 loc) · 1.09 KB
/
get_threads.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
34
35
36
37
38
from freelancersdk.session import Session
from freelancersdk.resources.messages.messages import get_threads
from freelancersdk.resources.messages.exceptions import \
ThreadsNotFoundException
from freelancersdk.resources.messages.helpers import (
create_get_threads_object, create_get_threads_details_object
)
import os
def sample_get_threads():
url = os.environ.get('FLN_URL')
oauth_token = os.environ.get('FLN_OAUTH_TOKEN')
session = Session(oauth_token=oauth_token, url=url)
get_threads_data = create_get_threads_object(
threads=80034553,
is_read=True,
threads_details = create_get_threads_details_object(
last_message=True,
user_details=True
)
)
try:
threads = get_threads(session, get_threads_data)
except ThreadsNotFoundException as e:
print('Error message: {}'.format(e.message))
print('Server response: {}'.format(e.error_code))
return None
else:
return threads
result = sample_get_threads()
if result:
print('Found threads: {}'.format(len(result['threads'])))