Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator api update #224

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions sites/setup_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time


# Inspired from the Andrei Cojocaru update_peviitor_api Decorator
class UpdatePeviitorAPI:
"""
Class for updating data on pe viitor API
Expand All @@ -16,43 +15,35 @@ def __init__(self, company_name, data_list):
"""
self.company_name = company_name
self.data_list = data_list
self.api_key = os.environ.get('API_KEY')
self.email = os.environ.get('EMAIL')

def __call__(self):
"""
Perform the data update process.
"""
self._send_clean_request()
self.get_token()
time.sleep(0.2)
self._send_post_request()
self.add_jobs()

def get_token(self):

def _send_clean_request(self):
"""
Send the clean request to the Peviitor API.
"""
payload = json.dumps({
"email": self.email
})

clean_url = 'https://api.peviitor.ro/v4/clean/'
clean_header = {
'Content-Type': 'application/x-www-form-urlencoded',
'apikey': self.api_key
post_header = {
'Content-Type': 'application/json'
}
requests.post(clean_url, headers=clean_header, data={'company': self.company_name})

def _send_post_request(self):
"""
Send the post request to update the data
"""
self.access_token = requests.request("POST", "https://api.peviitor.ro/v5/get_token/", headers=post_header, data=payload).json()['access']


def add_jobs(self):

post_header = {
'Content-Type': 'application/json',
'apikey': self.api_key
'Authorization': f'Bearer {self.access_token}',
'Content-Type': 'application/json'
}
# print(json.dumps(self.data_list))
requests.post('https://api.peviitor.ro/v4/update/', headers=post_header, data=json.dumps(self.data_list))

# don't delete this lines if you want to see the graph on scraper's page
file = self.company_name.lower() + '.py'
data = {'data': len(self.data_list)}
dataset_url = f'https://dev.laurentiumarian.ro/dataset/JobsScrapers/{file}/'
requests.post(dataset_url, json=data)
########################################################

requests.request("POST", "https://api.peviitor.ro/v5/add/", headers=post_header, data=json.dumps(self.data_list))

Loading