Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/lua
- -- The purpose of this script is to tell me if the local Sherms locations are hiring at all and for what positions. Made bit by bit with the help of chatGPT, i.e. haphazardly slapped together.
- --Output looks like this (potentially):
- --Job Title: Checker - Part Time
- --Location:
- -- Klamath Falls Thunderbird
- -- <br>
- --
- --
- --Job Title: Courtesy Clerk - Part Time
- --Location:
- -- Klamath Falls Thunderbird
- -- <br>
- --
- --
- local http = require("socket.http") -- also luasocket(?)
- local ltn12 = require("ltn12") -- luasocket
- local lpeg = require("lpeg") -- lpeg
- -- Function to fetch HTML from a URL
- function fetch_html(url)
- local response_body = {}
- local res, code, response_headers, status = http.request{
- url = url,
- sink = ltn12.sink.table(response_body),
- headers = {
- ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0"
- }
- }
- if not res then
- print("Failed to fetch the webpage. HTTP code:", code)
- return nil
- end
- return table.concat(response_body)
- end
- -- Function to remove HTML tags
- function removeHtmlTags(str)
- return str:gsub("<[^>]+>", "") -- Remove everything between < and >
- end
- -- Function to extract job listings
- function extractJobListings(html, locationToCheck)
- -- Pattern to capture job title and location
- local jobPattern = "<a href[^\>]+>(.-)</a>.-<td>(.-)</td>"
- local foundJobs = {}
- -- Find all job entries
- for title, location in string.gmatch(html, jobPattern) do
- -- Remove HTML tags from title
- title = removeHtmlTags(title)
- -- If the location matches the specified location
- if location:match(locationToCheck) then
- table.insert(foundJobs, {title = title, location = location})
- end
- end
- -- Display the results
- if #foundJobs == 0 then
- print("No current openings for " .. locationToCheck)
- else
- for _, job in ipairs(foundJobs) do
- print("Job Title: " .. job.title)
- print("Location: " .. job.location)
- print("---")
- end
- end
- end
- -- Main function to fetch and check for openings
- function check_openings(url, location)
- local html_content = fetch_html(url)
- if html_content then
- extractJobListings(html_content, location)
- else
- print("Failed to fetch or process the HTML content.")
- end
- end
- -- Test the function for "Klamath Falls Thunderbird"
- local url = "https://www.shermsmarkets.com/Pages/13803/"
- local location = "Klamath"
- check_openings(url, location)
Advertisement
Add Comment
Please, Sign In to add comment