-
Notifications
You must be signed in to change notification settings - Fork 44
/
get_projects.py
80 lines (68 loc) · 2.21 KB
/
get_projects.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from freelancersdk.session import Session
from freelancersdk.resources.projects.projects import (
get_projects, get_project_by_id
)
from freelancersdk.resources.projects.helpers import (
create_get_projects_object, create_get_projects_project_details_object,
create_get_projects_user_details_object
)
from freelancersdk.resources.projects.exceptions import \
ProjectsNotFoundException
import os
import json
def sample_get_projects():
url = os.environ.get('FLN_URL')
oauth_token = os.environ.get('FLN_OAUTH_TOKEN')
session = Session(oauth_token=oauth_token, url=url)
query = create_get_projects_object(
project_ids=[
201,
202,
203,
],
project_details=create_get_projects_project_details_object(
full_description=True,
jobs=True,
qualifications=True,
),
user_details=create_get_projects_user_details_object(
basic=True,
profile_description=True,
reputation=True,
),
)
try:
p = get_projects(session, query)
except ProjectsNotFoundException as e:
print('Error message: {}'.format(e.message))
print('Server response: {}'.format(e.error_code))
return None
else:
return p
def sample_get_project_by_id():
url = os.environ.get('FLN_URL')
oauth_token = os.environ.get('FLN_OAUTH_TOKEN')
session = Session(oauth_token=oauth_token, url=url)
project_id = 15389177
project_details = create_get_projects_project_details_object(
full_description=True
)
user_details = create_get_projects_user_details_object(
basic=True
)
try:
p = get_project_by_id(session, project_id, project_details, user_details)
except ProjectsNotFoundException as e:
print('Error message: {}'.format(e.message))
print('Server response: {}'.format(e.error_code))
return None
else:
return p
print('Getting multiple projects...')
p = sample_get_projects()
if p:
print('Found projects: {}'.format(json.dumps(p)))
print('Getting a single project by ID...')
p = sample_get_project_by_id()
if p:
print('Found a single project: {}'.format(json.dumps(p)))