File size: 3,705 Bytes
99273f7
ea93bfe
99273f7
bea2c44
 
 
 
 
 
 
 
 
ea93bfe
bea2c44
 
ea93bfe
bea2c44
 
 
 
 
ea93bfe
 
bea2c44
 
91a0869
bea2c44
 
 
 
 
99273f7
 
 
 
 
 
 
bea2c44
 
 
 
 
 
 
 
ea93bfe
 
 
 
 
bea2c44
 
 
 
 
 
ea93bfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datetime import datetime
import json

class JobDescription:
    def __init__(self, title, company, url, company_url, job_description):
        self.title = title
        self.company = company
        self.url = url
        self.company_url = company_url
        self.published_at = None  # Initialize to None or a default value
        self.job_description = job_description
        self.organization_logo_url = ""
        self.ai_result : AIInformation = None
        self.salary_range = ""
    
    def format_should_apply(self, should_apply : bool):
        if should_apply:
            return "⭐ "
        return ""
    
    def get_salary(self):
        if self.ai_result.salary_range.lower() not in ["", "unknown"]:
            return self.ai_result.salary_range
        return self.salary_range
    
    def format_str_or_list(self, input):
        if isinstance(input, str):
            return input.replace("\n", "<br />")
        if isinstance(input, list):
            return "<ul>" + "".join(f"<li>{item}</li>" for item in input) + "</ul>"
        return input
    
    def format_posted_date(self, date):
        if "{}".format(date) == "nan":
            return "?"
        if isinstance(date, str):
            return datetime.datetime.fromtimestamp(int(date)).strftime("%d/%m/%Y")
        return date.strftime("%d/%m/%Y")

    def to_html(self):
        #open box
        result = ["<div class='job'>"]
        #logo
        result.append("<div class='logobox'><img src='{}' alt='No logo' class='logo'></div>".format(self.organization_logo_url))
        #text part
        result.append("<div style='flex: 5; padding: 10px;'>")
        result.append("<h3><a href='{}' target='_blank'>{}{}</a></h3>".format(self.url, self.format_should_apply(self.ai_result.should_apply), self.title))
        result.append("<p><a href='{}' target='_blank'>{}</a> ({}) - published at {}</p>".format(self.company_url, self.company, self.ai_result.company_description, self.format_posted_date(self.published_at)))
        result.append("<p><h4>Position: {}</h4>{}</p>".format(self.get_salary(), self.format_str_or_list(self.ai_result.position_summary)))
        result.append("<p><h4>Language:</h4>{}</p>".format(self.format_str_or_list(self.ai_result.language_requirements)))
        result.append("<p><h4>Experience:</h4>{}</p>".format(self.format_str_or_list(self.ai_result.experience_requirements)))
        #close text part
        result.append("</div>")
        #close box
        result.append("</div>")
        return " ".join(result)
    
class AIInformation:
    def __init__(self, json_dump):
        obj = json.loads(json_dump)
        print(obj)
        #Check result
        if not "company_description" in obj:
            obj["company_description"] = ""
        if not "position_summary" in obj:
            obj["position_summary"] = ""
        if not "language_requirements" in obj:
            obj["language_requirements"] = ""
        if not "experience_requirements" in obj:
            obj["experience_requirements"] = ""
        if not "is_an_internship" in obj:
            obj["is_an_internship"] = False
        if not "salary_range" in obj:
            obj["salary_range"] = ""
        if not "should_apply" in obj:
            obj["should_apply"] = True

        self.company_description = obj["company_description"]
        self.position_summary = obj["position_summary"]
        self.language_requirements = obj["language_requirements"]
        self.experience_requirements = obj["experience_requirements"]
        self.is_an_internship = obj["is_an_internship"]
        self.salary_range = obj["salary_range"]
        self.should_apply : bool = obj["should_apply"]