JaySMTA commited on
Commit
ecb2d21
·
verified ·
1 Parent(s): 9e4317b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -51
app.py CHANGED
@@ -194,60 +194,43 @@ def create_interface(name, scrape_function):
194
  output_file = f"{name.lower()}_scraped_data.csv"
195
 
196
  def clean_text(text):
197
- return ' '.join(str(text).replace('\n', ' ').split())
198
 
199
  with open(output_file, 'w', newline='', encoding='utf-8') as f:
200
- if data:
201
- fieldnames = ['firstName', 'lastName', 'fullName', 'headline', 'location', 'connections', 'about']
202
- for i in range(5):
203
- fieldnames.extend([f'experience_{i+1}_title', f'experience_{i+1}_company', f'experience_{i+1}_duration'])
204
- for i in range(3):
205
- fieldnames.extend([f'education_{i+1}_school', f'education_{i+1}_degree', f'education_{i+1}_date'])
206
- fieldnames.extend(['languages', 'skills'])
207
-
208
- writer = csv.DictWriter(f, fieldnames=fieldnames)
209
- writer.writeheader()
210
 
211
- for row in data:
212
- clean_row = {
213
- 'firstName': clean_text(row.get('firstName', '')),
214
- 'lastName': clean_text(row.get('lastName', '')),
215
- 'fullName': clean_text(row.get('fullName', '')),
216
- 'headline': clean_text(row.get('headline', '')),
217
- 'location': clean_text(row.get('addressWithCountry', '')),
218
- 'connections': row.get('connections', ''),
219
- 'about': clean_text(row.get('about', ''))
220
- }
221
-
222
- experiences = row.get('experiences', [])
223
- for i in range(5):
224
- if i < len(experiences):
225
- exp = experiences[i]
226
- clean_row[f'experience_{i+1}_title'] = clean_text(exp.get('title', ''))
227
- clean_row[f'experience_{i+1}_company'] = clean_text(exp.get('subtitle', ''))
228
- clean_row[f'experience_{i+1}_duration'] = clean_text(exp.get('caption', ''))
229
- else:
230
- clean_row[f'experience_{i+1}_title'] = ''
231
- clean_row[f'experience_{i+1}_company'] = ''
232
- clean_row[f'experience_{i+1}_duration'] = ''
233
-
234
- educations = row.get('educations', [])
235
- for i in range(3):
236
- if i < len(educations):
237
- edu = educations[i]
238
- clean_row[f'education_{i+1}_school'] = clean_text(edu.get('title', ''))
239
- clean_row[f'education_{i+1}_degree'] = clean_text(edu.get('subtitle', ''))
240
- clean_row[f'education_{i+1}_date'] = clean_text(edu.get('caption', ''))
241
- else:
242
- clean_row[f'education_{i+1}_school'] = ''
243
- clean_row[f'education_{i+1}_degree'] = ''
244
- clean_row[f'education_{i+1}_date'] = ''
245
-
246
- clean_row['languages'] = ', '.join([lang.get('title', '') for lang in row.get('languages', [])])
247
- clean_row['skills'] = ', '.join([skill.get('title', '') for skill in row.get('skills', [])[:10]])
248
-
249
- writer.writerow(clean_row)
250
-
251
  return output_file
252
 
253
  preview_button.click(lambda x: preview_csv(x, scrape_function), inputs=input_file, outputs=preview)
 
194
  output_file = f"{name.lower()}_scraped_data.csv"
195
 
196
  def clean_text(text):
197
+ return str(text).replace('\n', ' ').strip()
198
 
199
  with open(output_file, 'w', newline='', encoding='utf-8') as f:
200
+ writer = csv.writer(f)
201
+ for profile in data:
202
+ writer.writerow(["Profile Information"])
203
+ writer.writerow([f"Name: {clean_text(profile.get('fullName', ''))}"])
204
+ writer.writerow([f"Headline: {clean_text(profile.get('headline', ''))}"])
205
+ writer.writerow([f"Location: {clean_text(profile.get('addressWithCountry', ''))}"])
206
+ writer.writerow([f"Connections: {profile.get('connections', '')}"])
207
+ writer.writerow([f"About: {clean_text(profile.get('about', ''))}"])
 
 
208
 
209
+ writer.writerow(["Experiences"])
210
+ for exp in profile.get('experiences', [])[:5]: # Limit to top 5 experiences
211
+ writer.writerow([f"Title: {clean_text(exp.get('title', ''))}"])
212
+ writer.writerow([f"Company: {clean_text(exp.get('subtitle', ''))}"])
213
+ writer.writerow([f"Duration: {clean_text(exp.get('caption', ''))}"])
214
+ writer.writerow([]) # Empty row for readability
215
+
216
+ writer.writerow(["Education"])
217
+ for edu in profile.get('educations', [])[:3]: # Limit to top 3 educations
218
+ writer.writerow([f"School: {clean_text(edu.get('title', ''))}"])
219
+ writer.writerow([f"Degree: {clean_text(edu.get('subtitle', ''))}"])
220
+ writer.writerow([f"Years: {clean_text(edu.get('caption', ''))}"])
221
+ writer.writerow([]) # Empty row for readability
222
+
223
+ writer.writerow(["Skills"])
224
+ skills = [clean_text(skill.get('title', '')) for skill in profile.get('skills', [])[:10]]
225
+ writer.writerow([", ".join(skills)])
226
+
227
+ writer.writerow(["Languages"])
228
+ languages = [clean_text(lang.get('title', '')) for lang in profile.get('languages', [])]
229
+ writer.writerow([", ".join(languages)])
230
+
231
+ writer.writerow([]) # Empty row between profiles
232
+ writer.writerow([]) # Empty row between profiles
233
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  return output_file
235
 
236
  preview_button.click(lambda x: preview_csv(x, scrape_function), inputs=input_file, outputs=preview)