Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import logging
|
| 3 |
from linkedin_jobs_scraper import LinkedinScraper
|
| 4 |
-
from linkedin_jobs_scraper.events import Events, EventData
|
| 5 |
from linkedin_jobs_scraper.query import Query, QueryOptions, QueryFilters
|
| 6 |
-
from linkedin_jobs_scraper.filters import RelevanceFilters, TimeFilters
|
| 7 |
import pandas as pd
|
| 8 |
|
| 9 |
# Configure logging
|
| 10 |
-
logging.basicConfig(level=logging.INFO)
|
| 11 |
|
| 12 |
# Initialize job data storage
|
| 13 |
job_data = []
|
|
@@ -25,7 +25,7 @@ def on_data(data: EventData):
|
|
| 25 |
})
|
| 26 |
|
| 27 |
def on_end():
|
| 28 |
-
|
| 29 |
|
| 30 |
# Scraper function
|
| 31 |
def scrape_jobs(query, locations, time_filter):
|
|
@@ -75,20 +75,23 @@ def scrape_jobs(query, locations, time_filter):
|
|
| 75 |
if job_data:
|
| 76 |
df = pd.DataFrame(job_data)
|
| 77 |
message = f"Jobs ({len(job_data)}) data successfully scraped."
|
|
|
|
| 78 |
return df, message
|
| 79 |
else:
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
-
# Handle
|
| 84 |
-
|
|
|
|
| 85 |
return None, message
|
| 86 |
|
| 87 |
def gradio_interface(query, locations, time_filter):
|
| 88 |
df, message = scrape_jobs(query, locations, time_filter)
|
| 89 |
return df, message
|
| 90 |
|
| 91 |
-
#App Layout
|
| 92 |
iface = gr.Interface(
|
| 93 |
fn=gradio_interface,
|
| 94 |
inputs=[
|
|
@@ -110,4 +113,4 @@ iface = gr.Interface(
|
|
| 110 |
)
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import logging
|
| 3 |
from linkedin_jobs_scraper import LinkedinScraper
|
| 4 |
+
from linkedin_jobs_scraper.events import Events, EventData, EventMetrics
|
| 5 |
from linkedin_jobs_scraper.query import Query, QueryOptions, QueryFilters
|
| 6 |
+
from linkedin_jobs_scraper.filters import RelevanceFilters, TimeFilters, OnSiteOrRemoteFilters
|
| 7 |
import pandas as pd
|
| 8 |
|
| 9 |
# Configure logging
|
| 10 |
+
logging.basicConfig(filename="job_scraper.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 11 |
|
| 12 |
# Initialize job data storage
|
| 13 |
job_data = []
|
|
|
|
| 25 |
})
|
| 26 |
|
| 27 |
def on_end():
|
| 28 |
+
logging.info("[ON_END] Scraping completed.")
|
| 29 |
|
| 30 |
# Scraper function
|
| 31 |
def scrape_jobs(query, locations, time_filter):
|
|
|
|
| 75 |
if job_data:
|
| 76 |
df = pd.DataFrame(job_data)
|
| 77 |
message = f"Jobs ({len(job_data)}) data successfully scraped."
|
| 78 |
+
logging.info(message)
|
| 79 |
return df, message
|
| 80 |
else:
|
| 81 |
+
logging.warning("No job data found.")
|
| 82 |
+
return pd.DataFrame(), 'No jobs found.'
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
+
# Handle specific exceptions and log detailed information
|
| 86 |
+
logging.error(f"An error occurred during scraping: {e}", exc_info=True)
|
| 87 |
+
message = f"An error occurred during scraping: {e}. Please check the logs for more details."
|
| 88 |
return None, message
|
| 89 |
|
| 90 |
def gradio_interface(query, locations, time_filter):
|
| 91 |
df, message = scrape_jobs(query, locations, time_filter)
|
| 92 |
return df, message
|
| 93 |
|
| 94 |
+
# App Layout
|
| 95 |
iface = gr.Interface(
|
| 96 |
fn=gradio_interface,
|
| 97 |
inputs=[
|
|
|
|
| 113 |
)
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
| 116 |
+
iface.launch()
|