-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchThread.py
More file actions
38 lines (34 loc) · 1.21 KB
/
FetchThread.py
File metadata and controls
38 lines (34 loc) · 1.21 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
from PySide6 import QtCore
class FetchApiThread(QtCore.QThread):
result = QtCore.Signal(object)
error = QtCore.Signal(str)
def run(self):
try:
import os, json, urllib.request
from dotenv import load_dotenv
load_dotenv()
base = os.environ.get('HRMIS_API_URL')
if not base:
self.error.emit('HRMIS_API_URL not configured in environment')
return
url = base.rstrip('/') + '/api/applicants/getReadyApplicant'
req = urllib.request.Request(url, headers={'Accept': 'application/json'})
with urllib.request.urlopen(req, timeout=8) as resp:
body = resp.read().decode('utf-8')
data = json.loads(body)
except Exception as e:
try:
import traceback; traceback.print_exc()
except Exception:
pass
try:
self.error.emit(str(e))
except Exception:
pass
return
if isinstance(data, dict) and 'data' in data:
data = data.get('data')
try:
self.result.emit(data)
except Exception:
pass