-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_sync.py
More file actions
98 lines (79 loc) · 3.1 KB
/
Copy pathexample_sync.py
File metadata and controls
98 lines (79 loc) · 3.1 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Example usage of Kwork API Library (Sync)
"""
import os
import sys
from dotenv import load_dotenv
# Add library to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "pykwork"))
from pykwork import KworkAuthError, KworkRequestError, KworkSyncClient
# Load environment variables from .env file
load_dotenv()
def main():
# Initialize client
client = KworkSyncClient(
username=os.getenv("KWORK_USERNAME"),
password=os.getenv("KWORK_PASSWORD"),
uad=os.getenv("KWORK_UAD", "test"),
device=os.getenv("KWORK_DEVICE", "test"),
)
try:
with client:
# Login
auth_response = client.login()
print("Logged in successfully")
print(f"Token: {client.token[:20]}...")
print(f"Expires in: {auth_response['response']['expired']} seconds")
print()
# Get current user info
actor = client.get_actor()
print(f"User: {actor['response']['username']}")
print(f"ID: {actor['response']['id']}")
print(f"Email: {actor['response']['email']}")
print(f"Type: {actor['response']['type']}")
print()
# Get connects info (коннекты)
connects = client.get_connects()
print(f"Коннекты: {connects['active_connects']} из {connects['all_connects']}")
print()
# Get categories
categories = client.get_categories()
print(f"Got {len(categories)} categories:")
for cat in categories:
print(f" - {cat['name']} (ID: {cat['id']})")
print()
# Get projects (first 2 pages)
projects = client.get_all_projects(max_pages=2)
print(f"Got {len(projects)} projects")
if projects:
print(f"First project: {projects[0]['title']}")
print(f"Price: {projects[0]['price']} RUB")
print()
# Get projects filtered by category (IT & Development)
it_projects = client.get_all_projects(max_pages=1, categories="11")
print(f"Got {len(it_projects)} IT projects")
print()
# Get user's offers
offers = client.get_all_offers()
print(f"Got {len(offers)} offers")
if offers:
print(f"First offer: {offers[0]['title']}")
print(f"Price: {offers[0]['price']} RUB")
print(f"Status: {offers[0]['status']}")
print()
# Get user by ID
user = client.get_user(user_id=1)
print(f"User: {user['response']['username']}")
print(f"Full name: {user['response']['fullname']}")
print()
print("All operations completed successfully!")
except KworkAuthError as e:
print(f"Authentication error: {e}")
except KworkRequestError as e:
print(f"Request error: {e}")
if e.status_code:
print(f"Status code: {e.status_code}")
except Exception as e:
print(f"Unexpected error: {e}")
if __name__ == "__main__":
main()