Spaces:
Build error
Build error
| import requests | |
| import csv | |
| def process_csv(input_file, txt_projectName): | |
| # STEP 1 in processing outputs | |
| # takes the url as supplied by MechanicalClerk via GoogleNews and turns it into the proper article links | |
| def get_redirected_url(url): | |
| response = requests.get("https://" + url) | |
| return response.url | |
| # Read the input .csv file | |
| with open(input_file.name, 'r', encoding="utf-8") as file: | |
| csv_data = list(csv.reader(file, delimiter='\t')) | |
| # Process each row in the .csv file except the header | |
| for row in csv_data[1:]: | |
| row[3] = get_redirected_url(row[3]) | |
| # Write the modified .csv data to a new file | |
| with open(txt_projectName+'_processedSearchResults.tsv', 'w', newline='') as file: | |
| writer = csv.writer(file, delimiter='\t') | |
| writer.writerows(csv_data) | |
| return txt_projectName+'_processedSearchResults.tsv' |