interpals-api 2.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,161 @@
1
+ """
2
+ This Python library provides a simple HTTP API for working with the website https://interpals.net/. It includes:
3
+
4
+ * retrieving data by user identifier
5
+ * listing visitors
6
+ * searching for users by criterions
7
+ * viewing and sending messages, deleting chats
8
+ * listing, adding and removing friends
9
+ * listing albums and pictures
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ pip install interpals-api
15
+ ```
16
+
17
+ ## Basic example
18
+
19
+ ```python
20
+ from interpals_api import Session, Api
21
+
22
+ session = Session.login('yourusername', 'yourpassword')
23
+ api = Api(session)
24
+
25
+ user_info = api.profile('someuser')
26
+ print(user_info)
27
+ ```
28
+
29
+ Since version `2.1` it supports asynchronous calls for each api method. Below there is a brief asynchonous example:
30
+
31
+ ```python
32
+ from interpals_api import SessionAsync, ApiAsync
33
+
34
+ session = await SessionAsync.login('yourusername', 'yourpassword')
35
+ api = ApiAsync(session)
36
+
37
+ user_info = await api.profile('someuser')
38
+ print(user_info)
39
+ ```
40
+
41
+ ## Other examples
42
+
43
+ Basic example to retrieve user info:
44
+
45
+ ```python
46
+ from interpals_api import Session, Api
47
+
48
+ session = Session.login('yourusername', 'yourpassword')
49
+ api = Api(session)
50
+
51
+ # This gives info of the user with the link: https://www.interpals.net/someuser
52
+ user_info = api.profile('someuser')
53
+ ```
54
+
55
+ Dump and load session object:
56
+
57
+ ```python
58
+ from interpals_api import Session, Api
59
+
60
+ session = Session.login('yourusername', 'yourpassword')
61
+
62
+ # Save session into a file
63
+ with open('session.json', 'w') as f:
64
+ session.dump(f)
65
+
66
+ # Load session from the saved file
67
+ with open('session.json') as f:
68
+ session = Session.load(f)
69
+ ```
70
+
71
+ Viewing and searching for users:
72
+
73
+ ```python
74
+ from interpals_api import Session, Api
75
+
76
+ session = Session.login('yourusername', 'yourpassword')
77
+ api = Api(session)
78
+
79
+ # Viewing a certain user
80
+ api.view('someuser')
81
+
82
+ # Showing the visitors of your profile
83
+ users = api.visitors()
84
+ print(users)
85
+
86
+ # Searching for users
87
+ options = {
88
+ 'age1': '20',
89
+ 'age2': '40',
90
+ 'sex': ['male', 'female'],
91
+ 'continents': ['AF', 'AS', 'EU', 'NA', 'OC', 'SA'],
92
+ 'countries': ['US', 'CA', 'UK', 'RU'],
93
+ 'keywords': 'travelling',
94
+ 'online': True,
95
+ 'cityName': 'London' # Or you can use 'city' with its direct code on the website (it's faster)
96
+ }
97
+ for user in api.search(options, limit=100, timeout=1.0):
98
+ print(user)
99
+ ```
100
+
101
+ To work with friends and pictures, it is necessary to use `uid` in methods:
102
+
103
+ ```python
104
+ from interpals_api import Session, Api
105
+
106
+ session = Session.login('yourusername', 'yourpassword')
107
+ api = Api(session)
108
+
109
+ uid = api.get_uid('someuser')
110
+
111
+ # Listing friends of the user 'someuser'
112
+ friends = api.friends(uid)
113
+ print(friends)
114
+
115
+ # Adding 'someuser' to friends
116
+ api.friend_add(uid)
117
+
118
+ # Removing 'someuser' from friends
119
+ api.friend_remove(uid)
120
+
121
+ # Listing pictures
122
+ albums = api.albums(uid)
123
+ for album in albums:
124
+ aid = album['aid']
125
+ pictures = api.pictures(uid, aid)
126
+ for picture in pictures:
127
+ print(picture['src'])
128
+ ```
129
+
130
+ Working with the chat is done through `thread_id`:
131
+
132
+ ```python
133
+ from interpals_api import Session, Api
134
+
135
+ session = Session.login('yourusername', 'yourpassword')
136
+ api = Api(session)
137
+
138
+ uid = api.get_uid('someuser')
139
+
140
+ # Listing your chats
141
+ result = api.chat(count=9, offset=0)
142
+ print(result['chats'])
143
+
144
+ # Staring new chat (getting thread_id)
145
+ thread_id = api.get_thread_id(uid)
146
+
147
+ # Show chat messages
148
+ messages = api.chat_messages(thread_id)
149
+ print(messages)
150
+
151
+ # Send new message to the thread
152
+ api.chat_send(thread_id, "Hey! How are you?")
153
+
154
+ # Removing chat
155
+ api.chat_delete(thread_id)
156
+ ```
157
+
158
+ """
159
+
160
+ from .session import Session, SessionAsync
161
+ from .api import Api, ApiAsync