linkedin-api 2.2.1__tar.gz → 2.3.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: linkedin-api
3
- Version: 2.2.1
3
+ Version: 2.3.1
4
4
  Summary: LinkedIn API for Python
5
5
  Home-page: https://github.com/tomquirk/linkedin-api
6
6
  License: MIT
@@ -22,12 +22,11 @@ Project-URL: Documentation, https://linkedin-api.readthedocs.io
22
22
  Project-URL: Repository, https://github.com/tomquirk/linkedin-api
23
23
  Description-Content-Type: text/markdown
24
24
 
25
-
26
25
  <div align="center">
27
26
 
28
27
  # LinkedIn API for Python
29
- ![Build](https://img.shields.io/github/actions/workflow/status/tomquirk/linkedin-api/ci.yml?label=Build&logo=github) [![GitHub Release](https://img.shields.io/github/v/release/tomquirk/linkedin-api?label=Release&logo=python)](https://pypi.org/project/linkedin-api/) [![License](https://img.shields.io/badge/License-MIT-blue)](#license) [![Documentation](https://img.shields.io/github/v/release/tomquirk/linkedin-api?label=Docs&color=23cc71&logo=readthedocs)](https://linkedin-api.readthedocs.io) [![PyPI Downloads](https://img.shields.io/pypi/dm/linkedin-api?label=Downloads)](https://pypi.org/project/linkedin-api/)
30
28
 
29
+ ![Build](https://img.shields.io/github/actions/workflow/status/tomquirk/linkedin-api/ci.yml?label=Build&logo=github) [![Documentation](https://img.shields.io/readthedocs/linkedin-api?label=Docs)](https://linkedin-api.readthedocs.io) [![GitHub Release](https://img.shields.io/github/v/release/tomquirk/linkedin-api?label=PyPI&logo=python)](https://pypi.org/project/linkedin-api/) [![Discord](https://img.shields.io/badge/Discord-5865F2?logo=discord&logoColor=ffffff)](https://discord.gg/hdd48NEB37)
31
30
 
32
31
  Search profiles, send messages, find jobs and more in Python. No official API access required.
33
32
 
@@ -47,22 +46,22 @@ Search profiles, send messages, find jobs and more in Python. No official API ac
47
46
 
48
47
  <p align="center" dir="auto" >
49
48
  <a href="https://bit.ly/3AFPGZd" target="_blank">
50
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/proapis.png" alt="iScraper by ProAPIs">
49
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/proapis.png" alt="iScraper by ProAPIs">
51
50
  </a>
52
51
  <a href="https://bit.ly/3SWnB63" target="_blank">
53
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/prospeo.png" alt="Prospeo">
52
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/prospeo.png" alt="Prospeo">
54
53
  </a>
55
54
  <a href="https://bit.ly/3SRximo" target="_blank">
56
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/proxycurl.png" alt="proxycurl">
55
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/proxycurl.png" alt="proxycurl">
57
56
  </a>
58
57
  <a href="https://bit.ly/3Mbksvd" target="_blank">
59
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/lix.png" alt="Lix">
58
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/lix.png" alt="Lix">
60
59
  </a>
61
60
  <a href="https://bit.ly/3WOIMrX" target="_blank">
62
- <img height="70px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/unipile.png" alt="Unipile">
61
+ <img height="70px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/unipile.png" alt="Unipile">
63
62
  </a>
64
63
  <a href="https://bit.ly/4fUyE9J" target="_blank">
65
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/scrapin.png" alt="Scrapin">
64
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/scrapin.png" alt="Scrapin">
66
65
  </a>
67
66
  </p>
68
67
 
@@ -81,21 +80,21 @@ Search profiles, send messages, find jobs and more in Python. No official API ac
81
80
 
82
81
  And more! [Read the docs](https://linkedin-api.readthedocs.io/en/latest/api.html) for all API methods.
83
82
 
84
- ## Installation
85
-
86
83
  > [!IMPORTANT]
87
- > This library is not officially supported by LinkedIn. Using this might violate LinkedIn's Terms of Service. Use it at your own risk.
84
+ > This library is not officially supported by LinkedIn. Using this library might violate LinkedIn's Terms of Service. Use it at your own risk.
85
+
86
+ ## Installation
88
87
 
89
88
  > [!NOTE]
90
- > Python >= 3.8 required
89
+ > Python >= 3.10 required
91
90
 
92
- To install the linkedin_api package, use the following command:
91
+ ###
93
92
 
94
93
  ```bash
95
94
  pip install linkedin-api
96
95
  ```
97
96
 
98
- Or, for bleading edge:
97
+ Or, for bleeding edge:
99
98
 
100
99
  ```bash
101
100
  pip install git+https://github.com/tomquirk/linkedin-api.git
@@ -104,14 +103,14 @@ pip install git+https://github.com/tomquirk/linkedin-api.git
104
103
  ### Quick Start
105
104
 
106
105
  > [!TIP]
107
- > See all methods on the [documentation website](https://linkedin-api.readthedocs.io/).
106
+ > See all API methods on the [docs](https://linkedin-api.readthedocs.io/en/latest/api.html).
108
107
 
109
108
  The following snippet demonstrates a few basic linkedin_api use cases:
110
109
 
111
110
  ```python
112
111
  from linkedin_api import Linkedin
113
112
 
114
- # Authenticate using any Linkedin account credentials
113
+ # Authenticate using any Linkedin user account credentials
115
114
  api = Linkedin('reedhoffman@linkedin.com', '*******')
116
115
 
117
116
  # GET a profile
@@ -124,12 +123,6 @@ contact_info = api.get_profile_contact_info('billy-g')
124
123
  connections = api.get_profile_connections('1234asc12304')
125
124
  ```
126
125
 
127
- ## Documentation
128
-
129
- For comprehensive documentation, including available methods and parameters, visit the [documentation](https://linkedin-api.readthedocs.io/).
130
-
131
- [Learn more](#how-it-works) about how it works.
132
-
133
126
  ## Commercial alternatives
134
127
 
135
128
  > This is a sponsored section
@@ -248,36 +241,53 @@ Get started [here](https://bit.ly/3AFPGZd).
248
241
 
249
242
  > End sponsored section
250
243
 
251
- ## Disclaimer
252
-
253
- This library is not endorsed or supported by LinkedIn. It is an unofficial library intended for educational purposes and personal use only. By using this library, you agree to not hold the author or contributors responsible for any consequences resulting from its usage.
254
-
255
- ## Contributing
256
-
257
- We welcome contributions! [Learn how to find endpoints](#find-new-endpoints).
258
-
259
244
  ## Development
260
245
 
261
246
  ### Dependencies
262
247
 
263
- - Python 3.7
248
+ - [`poetry`](https://python-poetry.org/docs/)
264
249
  - A valid Linkedin user account (don't use your personal account, if possible)
265
- - [`pipenv`](https://pipenv.pypa.io/en/latest/) (optional)
266
250
 
267
251
  ### Development installation
268
252
 
269
- 1. Create a `.env` config file. An example is provided in `.env.example` - you include at least all of the settings set there.
270
- 2. Install dependencies with `pipenv`:
253
+ 1. Create a `.env` config file (use `.env.example` as a reference)
254
+ 2. Install dependencies using `poetry`:
271
255
 
272
256
  ```bash
273
- pipenv install --dev
274
- pipenv shell
257
+ poetry install
258
+ poetry self add poetry-plugin-dotenv
275
259
  ```
276
260
 
277
261
  ### Run tests
278
262
 
263
+ Run all tests:
264
+
279
265
  ```bash
280
- pipenv run test
266
+ poetry run pytest
267
+ ```
268
+
269
+ Run unit tests:
270
+
271
+ ```bash
272
+ poetry run pytest tests/unit
273
+ ```
274
+
275
+ Run E2E tests:
276
+
277
+ ```bash
278
+ poetry run pytest tests/e2e
279
+ ```
280
+
281
+ ### Lint
282
+
283
+ ```bash
284
+ poetry run black --check .
285
+ ```
286
+
287
+ Or to fix:
288
+
289
+ ```bash
290
+ poetry run black .
281
291
  ```
282
292
 
283
293
  ### Troubleshooting
@@ -382,7 +392,12 @@ It could be possible to document (and implement a nice interface for) this query
382
392
 
383
393
  ### Release a new version
384
394
 
385
- 1. Bump `__version__` in `__init__.py`
386
- 1. `pipenv run build`
387
- 1. `pipenv run publish`
395
+ 1. Bump `version` in `pyproject.toml`
396
+ 1. `poetry build`
397
+ 1. `poetry publish`
398
+ 1. Draft release notes in GitHub.
399
+
400
+ ## Disclaimer
401
+
402
+ This library is not endorsed or supported by LinkedIn. It is an unofficial library intended for educational purposes and personal use only. By using this library, you agree to not hold the author or contributors responsible for any consequences resulting from its usage.
388
403
 
@@ -1,9 +1,8 @@
1
-
2
1
  <div align="center">
3
2
 
4
3
  # LinkedIn API for Python
5
- ![Build](https://img.shields.io/github/actions/workflow/status/tomquirk/linkedin-api/ci.yml?label=Build&logo=github) [![GitHub Release](https://img.shields.io/github/v/release/tomquirk/linkedin-api?label=Release&logo=python)](https://pypi.org/project/linkedin-api/) [![License](https://img.shields.io/badge/License-MIT-blue)](#license) [![Documentation](https://img.shields.io/github/v/release/tomquirk/linkedin-api?label=Docs&color=23cc71&logo=readthedocs)](https://linkedin-api.readthedocs.io) [![PyPI Downloads](https://img.shields.io/pypi/dm/linkedin-api?label=Downloads)](https://pypi.org/project/linkedin-api/)
6
4
 
5
+ ![Build](https://img.shields.io/github/actions/workflow/status/tomquirk/linkedin-api/ci.yml?label=Build&logo=github) [![Documentation](https://img.shields.io/readthedocs/linkedin-api?label=Docs)](https://linkedin-api.readthedocs.io) [![GitHub Release](https://img.shields.io/github/v/release/tomquirk/linkedin-api?label=PyPI&logo=python)](https://pypi.org/project/linkedin-api/) [![Discord](https://img.shields.io/badge/Discord-5865F2?logo=discord&logoColor=ffffff)](https://discord.gg/hdd48NEB37)
7
6
 
8
7
  Search profiles, send messages, find jobs and more in Python. No official API access required.
9
8
 
@@ -23,22 +22,22 @@ Search profiles, send messages, find jobs and more in Python. No official API ac
23
22
 
24
23
  <p align="center" dir="auto" >
25
24
  <a href="https://bit.ly/3AFPGZd" target="_blank">
26
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/proapis.png" alt="iScraper by ProAPIs">
25
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/proapis.png" alt="iScraper by ProAPIs">
27
26
  </a>
28
27
  <a href="https://bit.ly/3SWnB63" target="_blank">
29
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/prospeo.png" alt="Prospeo">
28
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/prospeo.png" alt="Prospeo">
30
29
  </a>
31
30
  <a href="https://bit.ly/3SRximo" target="_blank">
32
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/proxycurl.png" alt="proxycurl">
31
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/proxycurl.png" alt="proxycurl">
33
32
  </a>
34
33
  <a href="https://bit.ly/3Mbksvd" target="_blank">
35
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/lix.png" alt="Lix">
34
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/lix.png" alt="Lix">
36
35
  </a>
37
36
  <a href="https://bit.ly/3WOIMrX" target="_blank">
38
- <img height="70px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/unipile.png" alt="Unipile">
37
+ <img height="70px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/unipile.png" alt="Unipile">
39
38
  </a>
40
39
  <a href="https://bit.ly/4fUyE9J" target="_blank">
41
- <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/master/assets/logos/scrapin.png" alt="Scrapin">
40
+ <img height="45px" src="https://raw.githubusercontent.com/tomquirk/linkedin-api/main/docs/assets/logos/scrapin.png" alt="Scrapin">
42
41
  </a>
43
42
  </p>
44
43
 
@@ -57,21 +56,21 @@ Search profiles, send messages, find jobs and more in Python. No official API ac
57
56
 
58
57
  And more! [Read the docs](https://linkedin-api.readthedocs.io/en/latest/api.html) for all API methods.
59
58
 
60
- ## Installation
61
-
62
59
  > [!IMPORTANT]
63
- > This library is not officially supported by LinkedIn. Using this might violate LinkedIn's Terms of Service. Use it at your own risk.
60
+ > This library is not officially supported by LinkedIn. Using this library might violate LinkedIn's Terms of Service. Use it at your own risk.
61
+
62
+ ## Installation
64
63
 
65
64
  > [!NOTE]
66
- > Python >= 3.8 required
65
+ > Python >= 3.10 required
67
66
 
68
- To install the linkedin_api package, use the following command:
67
+ ###
69
68
 
70
69
  ```bash
71
70
  pip install linkedin-api
72
71
  ```
73
72
 
74
- Or, for bleading edge:
73
+ Or, for bleeding edge:
75
74
 
76
75
  ```bash
77
76
  pip install git+https://github.com/tomquirk/linkedin-api.git
@@ -80,14 +79,14 @@ pip install git+https://github.com/tomquirk/linkedin-api.git
80
79
  ### Quick Start
81
80
 
82
81
  > [!TIP]
83
- > See all methods on the [documentation website](https://linkedin-api.readthedocs.io/).
82
+ > See all API methods on the [docs](https://linkedin-api.readthedocs.io/en/latest/api.html).
84
83
 
85
84
  The following snippet demonstrates a few basic linkedin_api use cases:
86
85
 
87
86
  ```python
88
87
  from linkedin_api import Linkedin
89
88
 
90
- # Authenticate using any Linkedin account credentials
89
+ # Authenticate using any Linkedin user account credentials
91
90
  api = Linkedin('reedhoffman@linkedin.com', '*******')
92
91
 
93
92
  # GET a profile
@@ -100,12 +99,6 @@ contact_info = api.get_profile_contact_info('billy-g')
100
99
  connections = api.get_profile_connections('1234asc12304')
101
100
  ```
102
101
 
103
- ## Documentation
104
-
105
- For comprehensive documentation, including available methods and parameters, visit the [documentation](https://linkedin-api.readthedocs.io/).
106
-
107
- [Learn more](#how-it-works) about how it works.
108
-
109
102
  ## Commercial alternatives
110
103
 
111
104
  > This is a sponsored section
@@ -224,36 +217,53 @@ Get started [here](https://bit.ly/3AFPGZd).
224
217
 
225
218
  > End sponsored section
226
219
 
227
- ## Disclaimer
228
-
229
- This library is not endorsed or supported by LinkedIn. It is an unofficial library intended for educational purposes and personal use only. By using this library, you agree to not hold the author or contributors responsible for any consequences resulting from its usage.
230
-
231
- ## Contributing
232
-
233
- We welcome contributions! [Learn how to find endpoints](#find-new-endpoints).
234
-
235
220
  ## Development
236
221
 
237
222
  ### Dependencies
238
223
 
239
- - Python 3.7
224
+ - [`poetry`](https://python-poetry.org/docs/)
240
225
  - A valid Linkedin user account (don't use your personal account, if possible)
241
- - [`pipenv`](https://pipenv.pypa.io/en/latest/) (optional)
242
226
 
243
227
  ### Development installation
244
228
 
245
- 1. Create a `.env` config file. An example is provided in `.env.example` - you include at least all of the settings set there.
246
- 2. Install dependencies with `pipenv`:
229
+ 1. Create a `.env` config file (use `.env.example` as a reference)
230
+ 2. Install dependencies using `poetry`:
247
231
 
248
232
  ```bash
249
- pipenv install --dev
250
- pipenv shell
233
+ poetry install
234
+ poetry self add poetry-plugin-dotenv
251
235
  ```
252
236
 
253
237
  ### Run tests
254
238
 
239
+ Run all tests:
240
+
255
241
  ```bash
256
- pipenv run test
242
+ poetry run pytest
243
+ ```
244
+
245
+ Run unit tests:
246
+
247
+ ```bash
248
+ poetry run pytest tests/unit
249
+ ```
250
+
251
+ Run E2E tests:
252
+
253
+ ```bash
254
+ poetry run pytest tests/e2e
255
+ ```
256
+
257
+ ### Lint
258
+
259
+ ```bash
260
+ poetry run black --check .
261
+ ```
262
+
263
+ Or to fix:
264
+
265
+ ```bash
266
+ poetry run black .
257
267
  ```
258
268
 
259
269
  ### Troubleshooting
@@ -358,6 +368,11 @@ It could be possible to document (and implement a nice interface for) this query
358
368
 
359
369
  ### Release a new version
360
370
 
361
- 1. Bump `__version__` in `__init__.py`
362
- 1. `pipenv run build`
363
- 1. `pipenv run publish`
371
+ 1. Bump `version` in `pyproject.toml`
372
+ 1. `poetry build`
373
+ 1. `poetry publish`
374
+ 1. Draft release notes in GitHub.
375
+
376
+ ## Disclaimer
377
+
378
+ This library is not endorsed or supported by LinkedIn. It is an unofficial library intended for educational purposes and personal use only. By using this library, you agree to not hold the author or contributors responsible for any consequences resulting from its usage.
@@ -0,0 +1,7 @@
1
+ """
2
+ linkedin-api
3
+ """
4
+
5
+ from .linkedin import Linkedin
6
+
7
+ __all__ = ["Linkedin"]
@@ -6,9 +6,10 @@ import json
6
6
  import logging
7
7
  import random
8
8
  import uuid
9
+ import re
9
10
  from operator import itemgetter
10
11
  from time import sleep
11
- from urllib.parse import urlencode
12
+ from urllib.parse import urlencode, quote
12
13
  from typing import Dict, Union, Optional, List, Literal
13
14
 
14
15
  from linkedin_api.client import Client
@@ -848,21 +849,165 @@ class Linkedin(object):
848
849
 
849
850
  return profile
850
851
 
851
- def get_profile_connections(
852
- self, urn_id: str, network_depth: Optional[str] = "F"
853
- ) -> List:
854
- """Fetch connections for a given LinkedIn profile. Defaults to first-degree connections.
852
+ def get_profile_connections(self, urn_id: str, **kwargs) -> List:
853
+ """Fetch connections for a given LinkedIn profile.
854
+
855
+ See Linkedin.search_people() for additional searching parameters.
855
856
 
856
857
  :param urn_id: LinkedIn URN ID for a profile
857
858
  :type urn_id: str
858
859
 
859
- :param network_depth: degree of connection for a given Linkedin profile. "F" for first, "S" for second, "O" for other.
860
+ :return: List of search results
861
+ :rtype: list
862
+ """
863
+ return self.search_people(connection_of=urn_id, **kwargs)
864
+
865
+ def get_profile_experiences(self, urn_id: str) -> List:
866
+ """Fetch experiences for a given LinkedIn profile.
867
+
868
+ NOTE: data structure differs slightly from Linkedin.get_profile() experiences.
869
+
870
+ :param urn_id: LinkedIn URN ID for a profile
860
871
  :type urn_id: str
861
872
 
862
- :return: List of search results
873
+ :return: List of experiences
863
874
  :rtype: list
864
875
  """
865
- return self.search_people(connection_of=urn_id, network_depth=network_depth)
876
+ profile_urn = f"urn:li:fsd_profile:{urn_id}"
877
+ variables = ",".join(
878
+ [f"profileUrn:{quote(profile_urn)}", "sectionType:experience"]
879
+ )
880
+ query_id = (
881
+ "voyagerIdentityDashProfileComponents.7af5d6f176f11583b382e37e5639e69e"
882
+ )
883
+
884
+ res = self._fetch(
885
+ f"/graphql?variables=({variables})&queryId={query_id}&includeWebMetadata=true",
886
+ headers={"accept": "application/vnd.linkedin.normalized+json+2.1"},
887
+ )
888
+
889
+ def parse_item(item, is_group_item=False):
890
+ """
891
+ Parse a single experience item.
892
+
893
+ Items as part of an 'experience group' (e.g. a company with multiple positions) have different data structures.
894
+ Therefore, some exceptions need to be made when parsing these items.
895
+ """
896
+ component = item["components"]["entityComponent"]
897
+ title = component["titleV2"]["text"]["text"]
898
+ subtitle = component["subtitle"]
899
+ company = subtitle["text"].split(" · ")[0] if subtitle else None
900
+ employment_type_parts = subtitle["text"].split(" · ") if subtitle else None
901
+ employment_type = (
902
+ employment_type_parts[1]
903
+ if employment_type_parts and len(employment_type_parts) > 1
904
+ else None
905
+ )
906
+ metadata = component.get("metadata", {}) or {}
907
+ location = metadata.get("text")
908
+
909
+ duration_text = component["caption"]["text"]
910
+ duration_parts = duration_text.split(" · ")
911
+ date_parts = duration_parts[0].split(" - ")
912
+
913
+ duration = (
914
+ duration_parts[1]
915
+ if duration_parts and len(duration_parts) > 1
916
+ else None
917
+ )
918
+ start_date = date_parts[0] if date_parts else None
919
+ end_date = date_parts[1] if date_parts and len(date_parts) > 1 else None
920
+
921
+ sub_components = component["subComponents"]
922
+ fixed_list_component = (
923
+ sub_components["components"][0]["components"]["fixedListComponent"]
924
+ if sub_components
925
+ else None
926
+ )
927
+
928
+ fixed_list_text_component = (
929
+ fixed_list_component["components"][0]["components"]["textComponent"]
930
+ if fixed_list_component
931
+ else None
932
+ )
933
+
934
+ # Extract additional description
935
+ description = (
936
+ fixed_list_text_component["text"]["text"]
937
+ if fixed_list_text_component
938
+ else None
939
+ )
940
+
941
+ # Create a dictionary with the extracted information
942
+ parsed_data = {
943
+ "title": title,
944
+ "companyName": company if not is_group_item else None,
945
+ "employmentType": company if is_group_item else employment_type,
946
+ "locationName": location,
947
+ "duration": duration,
948
+ "startDate": start_date,
949
+ "endDate": end_date,
950
+ "description": description,
951
+ }
952
+
953
+ return parsed_data
954
+
955
+ def get_grouped_item_id(item):
956
+ sub_components = item["components"]["entityComponent"]["subComponents"]
957
+ sub_components_components = (
958
+ sub_components["components"][0]["components"]
959
+ if sub_components
960
+ else None
961
+ )
962
+ paged_list_component_id = (
963
+ sub_components_components.get("*pagedListComponent", "")
964
+ if sub_components_components
965
+ else None
966
+ )
967
+ if (
968
+ paged_list_component_id
969
+ and "fsd_profilePositionGroup" in paged_list_component_id
970
+ ):
971
+ pattern = r"urn:li:fsd_profilePositionGroup:\([A-z0-9]+,[A-z0-9]+\)"
972
+ match = re.search(pattern, paged_list_component_id)
973
+ return match.group(0) if match else None
974
+
975
+ data = res.json()
976
+
977
+ items = []
978
+ for item in data["included"][0]["components"]["elements"]:
979
+ grouped_item_id = get_grouped_item_id(item)
980
+ # if the item is part of a group (e.g. a company with multiple positions),
981
+ # find the group items and parse them.
982
+ if grouped_item_id:
983
+ component = item["components"]["entityComponent"]
984
+ # use the company and location from the main item
985
+ company = component["titleV2"]["text"]["text"]
986
+
987
+ location = (
988
+ component["caption"]["text"] if component["caption"] else None
989
+ )
990
+
991
+ # find the group
992
+ group = [
993
+ i
994
+ for i in data["included"]
995
+ if grouped_item_id in i.get("entityUrn", "")
996
+ ]
997
+ if not group:
998
+ continue
999
+ for group_item in group[0]["components"]["elements"]:
1000
+ parsed_data = parse_item(group_item, is_group_item=True)
1001
+ parsed_data["companyName"] = company
1002
+ parsed_data["locationName"] = location
1003
+ items.append(parsed_data)
1004
+ continue
1005
+
1006
+ # else, parse the regular item
1007
+ parsed_data = parse_item(item)
1008
+ items.append(parsed_data)
1009
+
1010
+ return items
866
1011
 
867
1012
  def get_company_updates(
868
1013
  self,
@@ -1291,25 +1436,29 @@ class Linkedin(object):
1291
1436
  # We extract the last part of the string
1292
1437
  profile_urn = profile_urn_string.split(":")[-1]
1293
1438
 
1294
- trackingId = generate_trackingId()
1295
1439
  payload = {
1296
- "trackingId": trackingId,
1297
- "message": message,
1298
- "invitations": [],
1299
- "excludeInvitations": [],
1300
1440
  "invitee": {
1301
- "com.linkedin.voyager.growth.invitation.InviteeProfile": {
1302
- "profileId": profile_urn
1303
- }
1441
+ "inviteeUnion": {"memberProfile": f"urn:li:fsd_profile:{profile_urn}"}
1304
1442
  },
1443
+ "customMessage": message,
1305
1444
  }
1445
+ params = {
1446
+ "action": "verifyQuotaAndCreateV2",
1447
+ "decorationId": "com.linkedin.voyager.dash.deco.relationships.InvitationCreationResultWithInvitee-2",
1448
+ }
1449
+
1306
1450
  res = self._post(
1307
- "/growth/normInvitations",
1451
+ "/voyagerRelationshipsDashMemberRelationships",
1308
1452
  data=json.dumps(payload),
1309
1453
  headers={"accept": "application/vnd.linkedin.normalized+json+2.1"},
1454
+ params=params,
1310
1455
  )
1311
-
1312
- return res.status_code != 201
1456
+ # Check for connection_response.status_code == 400 and connection_response.json().get('data', {}).get('code') == 'CANT_RESEND_YET'
1457
+ # If above condition is True then request has been already sent, (might be pending or already connected)
1458
+ if res.ok:
1459
+ return False
1460
+ else:
1461
+ return True
1313
1462
 
1314
1463
  def remove_connection(self, public_profile_id: str):
1315
1464
  """Remove a given profile as a connection.
@@ -1382,6 +1531,13 @@ class Linkedin(object):
1382
1531
  def get_profile_network_info(self, public_profile_id: str):
1383
1532
  """Fetch network information for a given LinkedIn profile.
1384
1533
 
1534
+ Network information includes the following:
1535
+ - number of connections
1536
+ - number of followers
1537
+ - if the account is followable
1538
+ - the network distance between the API session user and the profile
1539
+ - if the API session user is following the profile
1540
+
1385
1541
  :param public_profile_id: public ID of a LinkedIn profile
1386
1542
  :type public_profile_id: str
1387
1543
 
@@ -1579,7 +1735,7 @@ class Linkedin(object):
1579
1735
  results.extend(data["elements"])
1580
1736
  self.logger.debug(f"results grew: {len(results)}")
1581
1737
 
1582
- return self.get_social_reactions(
1738
+ return self.get_post_reactions(
1583
1739
  urn_id=urn_id,
1584
1740
  results=results,
1585
1741
  max_results=max_results,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "linkedin-api"
3
- version = "2.2.1"
3
+ version = "2.3.1"
4
4
  description = "LinkedIn API for Python"
5
5
  authors = ["Tom Quirk <tom@codalabs.au>"]
6
6
  maintainers = ["Tom Quirk <tom@codalabs.au>"]
@@ -28,12 +28,6 @@ sphinx-book-theme = "^1.1.3"
28
28
  [tool.poetry.group.test.dependencies]
29
29
  pytest = "^8.3.2"
30
30
 
31
- [tool.poetry.scripts]
32
- lint = "black --check ."
33
- test = "python -m pytest tests"
34
- test_unit = "python -m pytest tests/unit"
35
- test_e2e = "python -m pytest tests/e2e"
36
-
37
31
  [build-system]
38
32
  requires = ["poetry-core"]
39
33
  build-backend = "poetry.core.masonry.api"
@@ -1,17 +0,0 @@
1
- """
2
- linkedin-api
3
- """
4
-
5
- from .linkedin import Linkedin
6
-
7
- __title__ = "linkedin_api"
8
- __version__ = "2.2.0"
9
- __summary__ = "Linkedin API for Python"
10
- __description__ = "Search profiles, send messages, find jobs, get company posts and more. All with a regular Linkedin user account. Build bots, SDKs, integrations and AI tools."
11
- __keywords__ = "linkedin,api,automation,scraper,bot,data,sdk,ai,integration,profiles,network,company"
12
- __license__ = "MIT"
13
-
14
- __author__ = "Tom Quirk"
15
- __email__ = "tomquirkacc@gmail.com"
16
-
17
- __all__ = ["Linkedin"]
File without changes